From af5e294bd561b74eec67369690ce20da6e8a6378 Mon Sep 17 00:00:00 2001 From: Alisue Date: Sun, 4 Aug 2024 18:19:59 +0900 Subject: [PATCH 1/7] chore: update gitmessage to use conventional commits --- .gitmessage | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/.gitmessage b/.gitmessage index ba2ec72..71ddb20 100644 --- a/.gitmessage +++ b/.gitmessage @@ -1,25 +1,21 @@ - -# Guide (v1.0) -# -# 👍 :+1: Apply changes. +# **Conventional Commits** # -# 🌿 :herb: Add or update things for tests. -# ☕ :coffee: Add or update things for developments. -# 📦 :package: Add or update dependencies. -# 📝 :memo: Add or update documentations. +# [optional scope]: # -# 🐛 :bug: Bugfixes. -# 💋 :kiss: Critical hotfixes. -# 🚿 :shower: Remove features, codes, or files. +# feat: feature (minor) +# deps: dependencies (minor/patch) +# fix: bug fix (patch) +# refactor: refactoring code +# test: test fix; no code change +# docs: documentation fix; no code change +# style: formatting, missing semi colons, etc; no code change +# chore: updating build tasks, package manager configs, etc; no code change # -# 🚀 :rocket: Improve performance. -# 💪 :muscle: Refactor codes. -# 💥 :boom: Breaking changes. -# 💩 :poop: Bad codes needs to be improved. +# **Install** # -# How to use: # git config commit.template .gitmessage # -# Reference: -# https://github.com/lambdalisue/emojiprefix +# **Reference** +# +# - https://www.conventionalcommits.org/en/v1.0.0/ From 0e57ef5821f7aaff40b6b723ed6cb863c159241f Mon Sep 17 00:00:00 2001 From: Alisue Date: Sun, 4 Aug 2024 18:20:45 +0900 Subject: [PATCH 2/7] chore: remove unused scripts --- .gitignore | 1 - .scripts/build_npm.ts | 49 ------------------------------------------- 2 files changed, 50 deletions(-) delete mode 100644 .scripts/build_npm.ts diff --git a/.gitignore b/.gitignore index 78a6d6d..4e4b189 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -/npm /docs deno.lock .coverage diff --git a/.scripts/build_npm.ts b/.scripts/build_npm.ts deleted file mode 100644 index 25d7285..0000000 --- a/.scripts/build_npm.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { build, emptyDir } from "@deno/dnt"; - -const name = "unknownutil"; -const version = Deno.args[0]; -if (!version) { - throw new Error("No version argument is specified"); -} -console.log("*".repeat(80)); -console.log(`${name} ${version}`); -console.log("*".repeat(80)); - -await emptyDir("./npm"); - -await build({ - typeCheck: false, - // XXX: - // snapshot tests doesn't work with dnt so we disable tests for now - // https://github.com/denoland/dnt/issues/254 - test: false, - entryPoints: ["./mod.ts"], - outDir: "./npm", - shims: { - // see JS docs for overview and more options - deno: "dev", - }, - package: { - // package.json properties - name, - version, - author: "Alisue ", - license: "MIT", - repository: "https://github.com/jsr-core/unknownutil", - }, -}); - -// post build steps -Deno.copyFileSync("LICENSE", "npm/LICENSE"); - -// build README for npm -let readme = Deno.readTextFileSync("README.md"); -readme = readme.replaceAll( - `"@core/unknownutil"`, - `"${name}"`, -); -readme = readme.replaceAll( - "## Usage", - `## Install\n\nInstall via npm:\n\n\`\`\`sh\nnpm install --save ${name}\n\`\`\`\n\n## Usage`, -); -Deno.writeTextFileSync("npm/README.md", readme); From f086152759af9099e8854eef7c21c9726605c8b1 Mon Sep 17 00:00:00 2001 From: Alisue Date: Sun, 4 Aug 2024 18:21:13 +0900 Subject: [PATCH 3/7] chore: remove `schedule` from `test` workflow --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59080f6..9e0223d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,8 +5,6 @@ env: NODE_VERSION: 16.x on: - schedule: - - cron: "0 7 * * 0" push: branches: - main From 3d011ce4422b4c17bde9f61856150ef3dc962d8b Mon Sep 17 00:00:00 2001 From: Alisue Date: Sun, 4 Aug 2024 18:21:59 +0900 Subject: [PATCH 4/7] chore: remove broken `udd` workflow --- .github/workflows/update.yml | 50 ------------------------------------ 1 file changed, 50 deletions(-) delete mode 100644 .github/workflows/update.yml diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml deleted file mode 100644 index 3fa4eed..0000000 --- a/.github/workflows/update.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Update - -on: - schedule: - - cron: "0 0 * * *" - workflow_dispatch: - -jobs: - udd: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: denoland/setup-deno@v1 - with: - deno-version: "1.x" - - name: Update dependencies - run: | - deno task upgrade > ../output.txt - env: - NO_COLOR: 1 - - name: Read ../output.txt - id: log - uses: juliangruber/read-file-action@v1 - with: - path: ../output.txt - - name: Commit changes - run: | - git config user.name '${{ github.actor }}' - git config user.email '${{ github.actor }}@users.noreply.github.com' - git commit -a -F- < Date: Sun, 4 Aug 2024 18:23:06 +0900 Subject: [PATCH 5/7] chore: remove unused environment variable --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9e0223d..ef722c5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,6 @@ name: Test env: DENO_VERSION: 1.x - NODE_VERSION: 16.x on: push: From 696cb0c7e26bce0b8ea5d8fec62c3709214fbac8 Mon Sep 17 00:00:00 2001 From: Alisue Date: Sun, 4 Aug 2024 18:23:48 +0900 Subject: [PATCH 6/7] chore: add prefix to commit message of update --- deno.jsonc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno.jsonc b/deno.jsonc index 885e967..40a3c0a 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -80,6 +80,6 @@ "test:coverage": "deno task test --coverage=.coverage", "coverage": "deno coverage .coverage", "update": "deno run --allow-env --allow-read --allow-write=. --allow-run=git,deno --allow-net=jsr.io,registry.npmjs.org jsr:@molt/cli ./*.ts", - "update:commit": "deno task -q update --commit --pre-commit=fmt,lint" + "update:commit": "deno task -q update --commit --prefix deps: --pre-commit=fmt,lint" } } From a6859bb967f081ec75bd61643070ff87e31b048d Mon Sep 17 00:00:00 2001 From: Alisue Date: Sun, 4 Aug 2024 18:24:06 +0900 Subject: [PATCH 7/7] docs: remove module documentation it seems JSR use README as module documentation when it doesn't exist --- mod.ts | 243 --------------------------------------------------------- 1 file changed, 243 deletions(-) diff --git a/mod.ts b/mod.ts index 8f2d971..2a11ea4 100644 --- a/mod.ts +++ b/mod.ts @@ -1,246 +1,3 @@ -/** - * A utility pack for handling `unknown` type. - * - * ## Usage - * - * It provides `is` module for type predicate functions and `assert`, `ensure`, and - * `maybe` helper functions. - * - * ### is\* and as\* - * - * Type predicate function is a function which returns `true` if a given value is - * expected type. For example, `isString` (or `is.String`) returns `true` if a - * given value is `string`. - * - * ```typescript - * import { is } from "@core/unknownutil"; - * - * const a: unknown = "Hello"; - * if (is.String(a)) { - * // 'a' is 'string' in this block - * } - * ``` - * - * For more complex types, you can use `is*Of` (or `is.*Of`) functions and `as*` - * (or `as.*`) functions like: - * - * ```typescript - * import { - * as, - * is, - * PredicateType, - * } from "@core/unknownutil"; - * - * const isArticle = is.ObjectOf({ - * title: is.String, - * body: is.String, - * refs: is.ArrayOf( - * is.UnionOf([ - * is.String, - * is.ObjectOf({ - * name: is.String, - * url: is.String, - * }), - * ]), - * ), - * createTime: as.Optional(is.InstanceOf(Date)), - * updateTime: as.Optional(is.InstanceOf(Date)), - * }); - * - * // Infer the type of `Article` from the definition of `isArticle` - * type Article = PredicateType; - * - * const a: unknown = { - * title: "Awesome article", - * body: "This is an awesome article", - * refs: [{ name: "Deno", url: "https://deno.land/" }, "https://github.com"], - * }; - * if (isArticle(a)) { - * // a is narrowed to the type of `isArticle` - * console.log(a.title); - * console.log(a.body); - * for (const ref of a.refs) { - * if (is.String(ref)) { - * console.log(ref); - * } else { - * console.log(ref.name); - * console.log(ref.url); - * } - * } - * } - * ``` - * - * Additionally, you can manipulate the predicate function returned from - * `isObjectOf` with `isPickOf`, `isOmitOf`, `isPartialOf`, and `isRequiredOf` - * similar to TypeScript's `Pick`, `Omit`, `Partial`, `Required` utility types. - * - * ```typescript - * import { as, is } from "@core/unknownutil"; - * - * const isArticle = is.ObjectOf({ - * title: is.String, - * body: is.String, - * refs: is.ArrayOf( - * is.UnionOf([ - * is.String, - * is.ObjectOf({ - * name: is.String, - * url: is.String, - * }), - * ]), - * ), - * createTime: as.Optional(is.InstanceOf(Date)), - * updateTime: as.Optional(is.InstanceOf(Date)), - * }); - * - * const isArticleCreateParams = is.PickOf(isArticle, ["title", "body", "refs"]); - * // is equivalent to - * //const isArticleCreateParams = is.ObjectOf({ - * // title: is.String, - * // body: is.String, - * // refs: is.ArrayOf( - * // is.UnionOf([ - * // is.String, - * // is.ObjectOf({ - * // name: is.String, - * // url: is.String, - * // }), - * // ]), - * // ), - * //}); - * - * const isArticleUpdateParams = is.OmitOf(isArticleCreateParams, ["title"]); - * // is equivalent to - * //const isArticleUpdateParams = is.ObjectOf({ - * // body: is.String, - * // refs: is.ArrayOf( - * // is.UnionOf([ - * // is.String, - * // is.ObjectOf({ - * // name: is.String, - * // url: is.String, - * // }), - * // ]), - * // ), - * //}); - * - * const isArticlePatchParams = is.PartialOf(isArticleUpdateParams); - * // is equivalent to - * //const isArticlePatchParams = is.ObjectOf({ - * // body: as.Optional(is.String), - * // refs: as.Optional(is.ArrayOf( - * // is.UnionOf([ - * // is.String, - * // is.ObjectOf({ - * // name: is.String, - * // url: is.String, - * // }), - * // ]), - * // )), - * //}); - * - * const isArticleAvailableParams = is.RequiredOf(isArticle); - * // is equivalent to - * //const isArticlePutParams = is.ObjectOf({ - * // body: is.String, - * // refs: is.ArrayOf( - * // is.UnionOf([ - * // is.String, - * // is.ObjectOf({ - * // name: is.String, - * // url: is.String, - * // }), - * // ]), - * // ), - * // createTime: is.InstanceOf(Date), - * // updateTime: is.InstanceOf(Date), - * //}); - * ``` - * - * If you need an union type or an intersection type, use `isUnionOf` and `isIntersectionOf` - * like: - * - * ```typescript - * import { is } from "@core/unknownutil"; - * - * const isFoo = is.ObjectOf({ - * foo: is.String, - * }); - * - * const isBar = is.ObjectOf({ - * bar: is.String, - * }); - * - * const isFooOrBar = is.UnionOf([isFoo, isBar]); - * // { foo: string } | { bar: string } - * - * const isFooAndBar = is.IntersectionOf([isFoo, isBar]); - * // { foo: string } & { bar: string } - * ``` - * - * ### assert - * - * The `assert` function does nothing if a given value is expected type. Otherwise, - * it throws an `AssertError` exception like: - * - * ```typescript - * import { - * assert, - * is, - * } from "@core/unknownutil"; - * - * const a: unknown = "Hello"; - * - * // `assert` does nothing or throws an `AssertError` - * assert(a, is.String); - * // a is now narrowed to string - * - * // With custom message - * assert(a, is.String, { message: "a must be a string" }); - * ``` - * - * ### ensure - * - * The `ensure` function return the value as-is if a given value is expected type. - * Otherwise, it throws an `AssertError` exception like: - * - * ```typescript - * import { - * ensure, - * is, - * } from "@core/unknownutil"; - * - * const a: unknown = "Hello"; - * - * // `ensure` returns `string` or throws an `AssertError` - * const _: string = ensure(a, is.String); - * - * // With custom message - * const __: string = ensure(a, is.String, { message: "a must be a string" }); - * ``` - * - * ### maybe - * - * The `maybe` function return the value as-is if a given value is expected type. - * Otherwise, it returns `undefined` that suites with - * [nullish coalescing operator (`??`)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing) - * like: - * - * ```typescript - * import { - * is, - * maybe, - * } from "@core/unknownutil"; - * - * const a: unknown = "Hello"; - * - * // `maybe` returns `string | undefined` so it suites with `??` - * const _: string = maybe(a, is.String) ?? "default value"; - * ``` - * - * @module - */ - export type * from "./type.ts"; export * from "./as/mod.ts";