diff --git a/.github/release.yaml b/.github/release.yaml deleted file mode 100644 index ae38baa..0000000 --- a/.github/release.yaml +++ /dev/null @@ -1,25 +0,0 @@ -changelog: - exclude: - labels: - - ignore-for-release - authors: - - octocat - categories: - - title: Breaking Changes 🛠 - labels: - - breaking - - title: Exciting New Features 🎉 - labels: - - feature - - title: Fixes 🔧 - labels: - - fix - - title: Documentation 🔧 - labels: - - docs - - title: CI 👷 - labels: - - ci - - title: Other Changes - labels: - - '*' \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index 33d8a9d..0000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,174 +0,0 @@ -name: ci -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - - test_lint: - runs-on: ubuntu-latest - if: ${{ !github.event.created && github.repository != 'garronej/denoify_ci' }} - steps: - - uses: actions/checkout@v2.3.4 - - uses: actions/setup-node@v2.1.3 - - uses: bahmutov/npm-install@v1 - - name: If this step fails run 'npm run lint' and 'npm run format' then commit again. - run: | - PACKAGE_MANAGER=npm - if [ -f "./yarn.lock" ]; then - PACKAGE_MANAGER=yarn - fi - $PACKAGE_MANAGER run lint:check - $PACKAGE_MANAGER run format:check - test_node: - runs-on: ${{ matrix.os }} - needs: test_lint - strategy: - matrix: - node: [ '15', '14', '12' ] - os: [ windows-latest, ubuntu-latest ] - name: Test with Node v${{ matrix.node }} on ${{ matrix.os }} - steps: - - name: Tell if project is using npm or yarn - id: step1 - uses: garronej/ts-ci@v1.1.2 - with: - action_name: tell_if_project_uses_npm_or_yarn - - uses: actions/checkout@v2.3.4 - - uses: actions/setup-node@v2.1.3 - with: - node-version: ${{ matrix.node }} - - uses: bahmutov/npm-install@v1 - - if: steps.step1.outputs.npm_or_yarn == 'yarn' - run: | - yarn build - yarn test:node - - if: steps.step1.outputs.npm_or_yarn == 'npm' - run: | - npm run build - npm test:node - test_deno: - runs-on: ubuntu-latest - needs: test_lint - name: test with Deno - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - - name: Cache - uses: actions/cache@v1 - with: - path: ~/.cache/deno - key: deno-${{ runner.os }}-${{ hashFiles('deno-lock.json') }} - restore-keys: | - deno-${{ runner.os }}-${{ hashFiles('deno-lock.json') }} - deno-${{ runner.os }}- - deno- - - uses: denolib/setup-deno@master - with: - deno-version: v1.x - - run: deno --version - - uses: bahmutov/npm-install@v1 - - run: | - PACKAGE_MANAGER=npm - if [ -f "./yarn.lock" ]; then - PACKAGE_MANAGER=yarn - fi - $PACKAGE_MANAGER run build - $PACKAGE_MANAGER run test:deno - - check_if_version_upgraded: - name: Check if version upgrade - # We run this only if it's a push on the default branch or if it's a PR from a - # branch (meaning not a PR from a fork). It would be more straightforward to test if secrets.NPM_TOKEN is - # defined but GitHub Action don't allow it yet. - if: | - github.event_name == 'push' || - github.event.pull_request.head.repo.owner.login == github.event.pull_request.base.repo.owner.login - runs-on: ubuntu-latest - needs: - - test_node - - test_deno - outputs: - from_version: ${{ steps.step1.outputs.from_version }} - to_version: ${{ steps.step1.outputs.to_version }} - is_upgraded_version: ${{ steps.step1.outputs.is_upgraded_version }} - is_release_beta: ${{steps.step1.outputs.is_release_beta }} - steps: - - uses: garronej/ts-ci@v1.1.8 - id: step1 - with: - action_name: is_package_json_version_upgraded - branch: ${{ github.head_ref || github.ref }} - - publish: - runs-on: ubuntu-latest - needs: - - check_if_version_upgraded - # We create a release only if the version have been upgraded and we are on a default branch - # PR on the default branch can release beta but not real release - if: | - needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true' && - ( - github.event_name == 'push' || - needs.check_if_version_upgraded.outputs.is_release_beta == 'true' - ) - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - ref: ${{ github.ref }} - - run: rm -r .github - - run: | - git branch -d latest || true - git push origin :latest || true - - run: | - git branch latest - git checkout latest - - uses: actions/setup-node@v2.1.3 - with: - node-version: '15' - registry-url: https://registry.npmjs.org/ - - uses: bahmutov/npm-install@v1 - - run: | - PACKAGE_MANAGER=npm - if [ -f "./yarn.lock" ]; then - PACKAGE_MANAGER=yarn - fi - $PACKAGE_MANAGER run build - - run: npx -y -p denoify@1.1.4 enable_short_npm_import_path - env: - DRY_RUN: "0" - - run: | - if [ "$(npm show . version)" = "$VERSION" ]; then - echo "This version is already published" - exit 0 - fi - if [ "$NODE_AUTH_TOKEN" = "" ]; then - echo "Can't publish on NPM, You must first create a secret called NPM_TOKEN that contains your NPM auth token. https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets" - false - fi - npm publish - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - VERSION: ${{ needs.check_if_version_upgraded.outputs.to_version }} - - run: | - git config --global user.name "actions" - git config --global user.email actions@example.com - git add -A - git commit -am "Enabling shorter import paths" - git push origin latest - - uses: softprops/action-gh-release@v1 - with: - name: Release v${{ needs.check_if_version_upgraded.outputs.to_version }} - tag_name: v${{ needs.check_if_version_upgraded.outputs.to_version }} - target_commitish: latest - generate_release_notes: true - draft: false - prerelease: ${{ needs.check_if_version_upgraded.outputs.is_release_beta == 'true' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - diff --git a/.gitignore b/.gitignore index e5ab84a..13be271 100644 --- a/.gitignore +++ b/.gitignore @@ -1,44 +1,2 @@ -# Logs -logs -*.log -npm-debug.log* - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules -jspm_packages - -# Optional npm cache directory -.npm - -# Optional REPL history -.node_repl_history - -.vscode - -.DS_Store - -/dist -/deno_dist + +/node_modules diff --git a/Equals.d.ts b/Equals.d.ts new file mode 100644 index 0000000..4479308 --- /dev/null +++ b/Equals.d.ts @@ -0,0 +1,4 @@ +import type { Unite } from "./tools/Unite"; +import type { StrictEquals } from "./tools/StrictEquals"; +/** https://docs.tsafe.dev/main/equals */ +export declare type Equals = StrictEquals, Unite>; diff --git a/Equals.js b/Equals.js new file mode 100644 index 0000000..a1e8026 --- /dev/null +++ b/Equals.js @@ -0,0 +1,4 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +// Credit https://stackoverflow.com/a/52473108/3570903 +//# sourceMappingURL=Equals.js.map \ No newline at end of file diff --git a/Equals.js.map b/Equals.js.map new file mode 100644 index 0000000..cd51b08 --- /dev/null +++ b/Equals.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Equals.js","sourceRoot":"","sources":["src/Equals.ts"],"names":[],"mappings":";;AAOA,sDAAsD"} \ No newline at end of file diff --git a/Extends.d.ts b/Extends.d.ts new file mode 100644 index 0000000..fe6ba71 --- /dev/null +++ b/Extends.d.ts @@ -0,0 +1,3 @@ +import { StrictEquals } from "./tools/StrictEquals"; +/** https://docs.tsafe.dev/main/extends */ +export declare type Extends = StrictEquals extends true ? true : StrictEquals extends true ? false : StrictEquals extends true ? true : StrictEquals extends true ? true : StrictEquals extends true ? false : StrictEquals extends true ? false : A1 extends A2 ? true : false; diff --git a/Extends.js b/Extends.js new file mode 100644 index 0000000..c45c6c9 --- /dev/null +++ b/Extends.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=Extends.js.map \ No newline at end of file diff --git a/Extends.js.map b/Extends.js.map new file mode 100644 index 0000000..fde128f --- /dev/null +++ b/Extends.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Extends.js","sourceRoot":"","sources":["src/Extends.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/MethodNames.d.ts b/MethodNames.d.ts new file mode 100644 index 0000000..b0ef628 --- /dev/null +++ b/MethodNames.d.ts @@ -0,0 +1,4 @@ +/** https://docs.tsafe.dev/methodnames */ +export declare type MethodNames = NonNullable<{ + [Key in keyof Api]: Api[Key] extends ((...args: any[]) => unknown) | undefined ? Key : never; +}[keyof Api]>; diff --git a/MethodNames.js b/MethodNames.js new file mode 100644 index 0000000..0709e1f --- /dev/null +++ b/MethodNames.js @@ -0,0 +1,5 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/ban-types */ +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=MethodNames.js.map \ No newline at end of file diff --git a/MethodNames.js.map b/MethodNames.js.map new file mode 100644 index 0000000..585cf01 --- /dev/null +++ b/MethodNames.js.map @@ -0,0 +1 @@ +{"version":3,"file":"MethodNames.js","sourceRoot":"","sources":["src/MethodNames.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,iDAAiD"} \ No newline at end of file diff --git a/Not.d.ts b/Not.d.ts new file mode 100644 index 0000000..d884102 --- /dev/null +++ b/Not.d.ts @@ -0,0 +1,2 @@ +/** https://docs.tsafe.dev/main/not */ +export declare type Not = B extends true ? false : true; diff --git a/Not.js b/Not.js new file mode 100644 index 0000000..7ec187a --- /dev/null +++ b/Not.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=Not.js.map \ No newline at end of file diff --git a/Not.js.map b/Not.js.map new file mode 100644 index 0000000..a253ef5 --- /dev/null +++ b/Not.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Not.js","sourceRoot":"","sources":["src/Not.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/Param0.d.ts b/Param0.d.ts new file mode 100644 index 0000000..26b4d17 --- /dev/null +++ b/Param0.d.ts @@ -0,0 +1,7 @@ +import type { Parameters } from "./Parameters"; +declare type NonUndefined = T extends undefined ? never : T; +/** Shorthand for Parameters[0] https://docs.tsafe.dev/param0 */ +export declare type Param0 unknown) | null | undefined | false | ""> = [ + Parameters +] extends [never] ? never : Parameters extends [] ? void : NonUndefined[0]>; +export {}; diff --git a/Param0.js b/Param0.js new file mode 100644 index 0000000..efb2100 --- /dev/null +++ b/Param0.js @@ -0,0 +1,4 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=Param0.js.map \ No newline at end of file diff --git a/Param0.js.map b/Param0.js.map new file mode 100644 index 0000000..9cadb5a --- /dev/null +++ b/Param0.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Param0.js","sourceRoot":"","sources":["src/Param0.ts"],"names":[],"mappings":";AAAA,uDAAuD"} \ No newline at end of file diff --git a/Parameters.d.ts b/Parameters.d.ts new file mode 100644 index 0000000..24f7d64 --- /dev/null +++ b/Parameters.d.ts @@ -0,0 +1,2 @@ +/** https://docs.tsafe.dev/parameters */ +export declare type Parameters unknown) | null | undefined | false | ""> = T extends (...args: infer P) => any ? P : never; diff --git a/Parameters.js b/Parameters.js new file mode 100644 index 0000000..a266d95 --- /dev/null +++ b/Parameters.js @@ -0,0 +1,4 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=Parameters.js.map \ No newline at end of file diff --git a/Parameters.js.map b/Parameters.js.map new file mode 100644 index 0000000..1a6a653 --- /dev/null +++ b/Parameters.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Parameters.js","sourceRoot":"","sources":["src/Parameters.ts"],"names":[],"mappings":";AAAA,uDAAuD"} \ No newline at end of file diff --git a/PickOptionals.d.ts b/PickOptionals.d.ts new file mode 100644 index 0000000..7be648d --- /dev/null +++ b/PickOptionals.d.ts @@ -0,0 +1,10 @@ +declare type OptionalKeyof> = Exclude<{ + [Key in keyof T]: T extends Record ? never : Key; +}[keyof T], undefined>; +/** + * PickOptionals<{ p1: string; p2?: string; p3?: number; }> + * is the type + * { p2: string; p3: number; } + */ +export declare type PickOptionals> = Required>>; +export {}; diff --git a/PickOptionals.js b/PickOptionals.js new file mode 100644 index 0000000..9ec0b7c --- /dev/null +++ b/PickOptionals.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=PickOptionals.js.map \ No newline at end of file diff --git a/PickOptionals.js.map b/PickOptionals.js.map new file mode 100644 index 0000000..98d179e --- /dev/null +++ b/PickOptionals.js.map @@ -0,0 +1 @@ +{"version":3,"file":"PickOptionals.js","sourceRoot":"","sources":["src/PickOptionals.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/PickRequired.d.ts b/PickRequired.d.ts new file mode 100644 index 0000000..9d9b44b --- /dev/null +++ b/PickRequired.d.ts @@ -0,0 +1,7 @@ +import { PickOptionals } from "./PickOptionals"; +/** + * PickRequired<{ p1: string; p2?: string; p3?: number; p4: string; }> + * is the type + * { p1: string; p4: number; } + */ +export declare type PickRequired> = Omit>; diff --git a/PickRequired.js b/PickRequired.js new file mode 100644 index 0000000..285609b --- /dev/null +++ b/PickRequired.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=PickRequired.js.map \ No newline at end of file diff --git a/PickRequired.js.map b/PickRequired.js.map new file mode 100644 index 0000000..97fbf94 --- /dev/null +++ b/PickRequired.js.map @@ -0,0 +1 @@ +{"version":3,"file":"PickRequired.js","sourceRoot":"","sources":["src/PickRequired.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/Reflect.d.ts b/Reflect.d.ts new file mode 100644 index 0000000..fa64428 --- /dev/null +++ b/Reflect.d.ts @@ -0,0 +1,2 @@ +/** Always return null but pretends it returns an object of type T */ +export declare function Reflect(): T; diff --git a/Reflect.js b/Reflect.js new file mode 100644 index 0000000..30141aa --- /dev/null +++ b/Reflect.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Reflect = void 0; +/** Always return null but pretends it returns an object of type T */ +function Reflect() { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return null; +} +exports.Reflect = Reflect; +//# sourceMappingURL=Reflect.js.map \ No newline at end of file diff --git a/Reflect.js.map b/Reflect.js.map new file mode 100644 index 0000000..6043ac0 --- /dev/null +++ b/Reflect.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Reflect.js","sourceRoot":"","sources":["src/Reflect.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACrE,SAAgB,OAAO;IACnB,8DAA8D;IAC9D,OAAO,IAAW,CAAC;AACvB,CAAC;AAHD,0BAGC"} \ No newline at end of file diff --git a/ReturnType.d.ts b/ReturnType.d.ts new file mode 100644 index 0000000..755cf17 --- /dev/null +++ b/ReturnType.d.ts @@ -0,0 +1,2 @@ +/** https://docs.tsafe.dev/returntype */ +export declare type ReturnType unknown) | undefined | null | false | ""> = T extends (...args: any[]) => infer R ? (R extends PromiseLike ? J : R) : never; diff --git a/ReturnType.js b/ReturnType.js new file mode 100644 index 0000000..bc4f657 --- /dev/null +++ b/ReturnType.js @@ -0,0 +1,10 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +// ReturnType<(()=> Promise | number) | undefined> = (()=> Promise | number) | undefined extends (...args: any[]) => infer R ? +// = ( ()=> Promise | number extends (...args: any[]) => infer R ? ) | (undefined extends (...args: any[]) => infer R ? ) +// = ( Promise | number extends PromiseLike ? ) | never +// = Promise | number extends PromiseLike ? +// = ( Promise extends PromiseLike ?) | ( number extends PromiseLike ?) +// = string | number +//# sourceMappingURL=ReturnType.js.map \ No newline at end of file diff --git a/ReturnType.js.map b/ReturnType.js.map new file mode 100644 index 0000000..9f2eee4 --- /dev/null +++ b/ReturnType.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ReturnType.js","sourceRoot":"","sources":["src/ReturnType.ts"],"names":[],"mappings":";AAAA,uDAAuD;;AAMvD,8IAA8I;AAC9I,yLAAyL;AACzL,4IAA4I;AAC5I,sHAAsH;AACtH,2JAA2J;AAC3J,0HAA0H"} \ No newline at end of file diff --git a/UnpackPromise.d.ts b/UnpackPromise.d.ts new file mode 100644 index 0000000..005d463 --- /dev/null +++ b/UnpackPromise.d.ts @@ -0,0 +1,6 @@ +/** + * Use case: + * declare const pr: Promise; + * const x: UnpackPromise; <== x is string[] + */ +export declare type UnpackPromise | undefined | null | false | ""> = T extends PromiseLike ? U : never; diff --git a/UnpackPromise.js b/UnpackPromise.js new file mode 100644 index 0000000..4bbbe90 --- /dev/null +++ b/UnpackPromise.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=UnpackPromise.js.map \ No newline at end of file diff --git a/UnpackPromise.js.map b/UnpackPromise.js.map new file mode 100644 index 0000000..d2135b6 --- /dev/null +++ b/UnpackPromise.js.map @@ -0,0 +1 @@ +{"version":3,"file":"UnpackPromise.js","sourceRoot":"","sources":["src/UnpackPromise.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/assert.d.ts b/assert.d.ts new file mode 100644 index 0000000..bea4da5 --- /dev/null +++ b/assert.d.ts @@ -0,0 +1,6 @@ +/** @see */ +export declare class AssertionError extends Error { + constructor(msg: string | undefined); +} +/** https://docs.tsafe.dev/assert */ +export declare function assert<_T extends true>(condition?: any, msg?: string): asserts condition; diff --git a/assert.js b/assert.js new file mode 100644 index 0000000..39c1be2 --- /dev/null +++ b/assert.js @@ -0,0 +1,83 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __read = (this && this.__read) || function (o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.assert = exports.AssertionError = void 0; +/* eslint-disable @typescript-eslint/no-unused-vars */ +var overwriteReadonlyProp_1 = require("./lab/overwriteReadonlyProp"); +var assertIsRefWrapper_1 = require("./zz_internal/assertIsRefWrapper"); +/** @see */ +var AssertionError = /** @class */ (function (_super) { + __extends(AssertionError, _super); + function AssertionError(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, "Wrong assertion encountered" + (!msg ? "" : ": \"" + msg + "\"")) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + if (!_this.stack) { + return _this; + } + try { + (0, overwriteReadonlyProp_1.overwriteReadonlyProp)(_this, "stack", _this.stack + .split("\n") + .filter(function () { + var _a = []; + for (var _i = 0; _i < arguments.length; _i++) { + _a[_i] = arguments[_i]; + } + var _b = __read(_a, 2), i = _b[1]; + return i !== 1 && i !== 2; + }) + .join("\n")); + // eslint-disable-next-line no-empty + } + catch (_a) { } + return _this; + } + return AssertionError; +}(Error)); +exports.AssertionError = AssertionError; +/** https://docs.tsafe.dev/assert */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function assert(condition, msg) { + if (arguments.length === 0) { + condition = true; + } + if (assertIsRefWrapper_1.assertIsRefWrapper.ref !== undefined) { + assertIsRefWrapper_1.assertIsRefWrapper.ref = undefined; + return; + } + if (!condition) { + throw new AssertionError(msg); + } +} +exports.assert = assert; +//# sourceMappingURL=assert.js.map \ No newline at end of file diff --git a/assert.js.map b/assert.js.map new file mode 100644 index 0000000..bf62503 --- /dev/null +++ b/assert.js.map @@ -0,0 +1 @@ +{"version":3,"file":"assert.js","sourceRoot":"","sources":["src/assert.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,qEAAoE;AACpE,uEAAsE;AAEtE,wDAAwD;AACxD;IAAoC,kCAAK;IACrC,wBAAY,GAAuB;;QAAnC,YACI,kBAAM,6BAA6B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAM,GAAG,OAAG,CAAC,CAAC,SAmBpE;QAjBG,MAAM,CAAC,cAAc,CAAC,KAAI,EAAE,WAAW,SAAS,CAAC,CAAC;QAElD,IAAI,CAAC,KAAI,CAAC,KAAK,EAAE;;SAEhB;QAED,IAAI;YACA,IAAA,6CAAqB,EACjB,KAAI,EACJ,OAAO,EACP,KAAI,CAAC,KAAK;iBACL,KAAK,CAAC,IAAI,CAAC;iBACX,MAAM,CAAC;gBAAC,YAAQ;qBAAR,UAAQ,EAAR,qBAAQ,EAAR,IAAQ;oBAAR,uBAAQ;;gBAAR,IAAA,KAAA,aAAQ,EAAF,CAAC,QAAA,CAAC;gBAAK,OAAA,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;YAAlB,CAAkB,CAAC;iBACxC,IAAI,CAAC,IAAI,CAAC,CAClB,CAAC;YACF,oCAAoC;SACvC;QAAC,WAAM,GAAE;;IACd,CAAC;IACL,qBAAC;AAAD,CAAC,AAtBD,CAAoC,KAAK,GAsBxC;AAtBY,wCAAc;AAwB3B,oCAAoC;AACpC,8DAA8D;AAC9D,SAAgB,MAAM,CAAkB,SAAe,EAAE,GAAY;IACjE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,SAAS,GAAG,IAAI,CAAC;KACpB;IACD,IAAI,uCAAkB,CAAC,GAAG,KAAK,SAAS,EAAE;QACtC,uCAAkB,CAAC,GAAG,GAAG,SAAS,CAAC;QACnC,OAAO;KACV;IAED,IAAI,CAAC,SAAS,EAAE;QACZ,MAAM,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC;KACjC;AACL,CAAC;AAZD,wBAYC"} \ No newline at end of file diff --git a/capitalize.d.ts b/capitalize.d.ts new file mode 100644 index 0000000..cbd5235 --- /dev/null +++ b/capitalize.d.ts @@ -0,0 +1,2 @@ +/** @see */ +export declare function capitalize(str: S): Capitalize; diff --git a/capitalize.js b/capitalize.js new file mode 100644 index 0000000..cdb4e57 --- /dev/null +++ b/capitalize.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.capitalize = void 0; +/** @see */ +function capitalize(str) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (str.charAt(0).toUpperCase() + str.slice(1)); +} +exports.capitalize = capitalize; +//# sourceMappingURL=capitalize.js.map \ No newline at end of file diff --git a/capitalize.js.map b/capitalize.js.map new file mode 100644 index 0000000..f71d34c --- /dev/null +++ b/capitalize.js.map @@ -0,0 +1 @@ +{"version":3,"file":"capitalize.js","sourceRoot":"","sources":["src/capitalize.ts"],"names":[],"mappings":";;;AAAA,+CAA+C;AAC/C,SAAgB,UAAU,CAAmB,GAAM;IAC/C,8DAA8D;IAC9D,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAQ,CAAC;AAC/D,CAAC;AAHD,gCAGC"} \ No newline at end of file diff --git a/deno_dist/Equals.ts b/deno_dist/Equals.ts new file mode 100644 index 0000000..316f4cb --- /dev/null +++ b/deno_dist/Equals.ts @@ -0,0 +1,8 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import type { Unite } from "./tools/Unite.ts"; +import type { StrictEquals } from "./tools/StrictEquals.ts"; + +/** https://docs.tsafe.dev/main/equals */ +export type Equals = StrictEquals, Unite>; + +// Credit https://stackoverflow.com/a/52473108/3570903 diff --git a/deno_dist/Extends.ts b/deno_dist/Extends.ts new file mode 100644 index 0000000..ad09dd8 --- /dev/null +++ b/deno_dist/Extends.ts @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { StrictEquals } from "./tools/StrictEquals.ts"; + +/** https://docs.tsafe.dev/main/extends */ +export type Extends = StrictEquals extends true + ? true + : StrictEquals extends true + ? false + : StrictEquals extends true + ? true + : StrictEquals extends true + ? true + : StrictEquals extends true + ? false + : StrictEquals extends true + ? false + : A1 extends A2 + ? true + : false; diff --git a/deno_dist/LICENSE b/deno_dist/LICENSE new file mode 100644 index 0000000..61f220f --- /dev/null +++ b/deno_dist/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 GitHub user u/garronej + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/deno_dist/MethodNames.ts b/deno_dist/MethodNames.ts new file mode 100644 index 0000000..c7b0b26 --- /dev/null +++ b/deno_dist/MethodNames.ts @@ -0,0 +1,9 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/ban-types */ + +/** https://docs.tsafe.dev/methodnames */ +export type MethodNames = NonNullable< + { + [Key in keyof Api]: Api[Key] extends ((...args: any[]) => unknown) | undefined ? Key : never; + }[keyof Api] +>; diff --git a/deno_dist/Not.ts b/deno_dist/Not.ts new file mode 100644 index 0000000..c5bd642 --- /dev/null +++ b/deno_dist/Not.ts @@ -0,0 +1,2 @@ +/** https://docs.tsafe.dev/main/not */ +export type Not = B extends true ? false : true; diff --git a/deno_dist/Param0.ts b/deno_dist/Param0.ts new file mode 100644 index 0000000..284c847 --- /dev/null +++ b/deno_dist/Param0.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import type { Parameters } from "./Parameters.ts"; + +type NonUndefined = T extends undefined ? never : T; + +/** Shorthand for Parameters[0] https://docs.tsafe.dev/param0 */ +export type Param0 unknown) | null | undefined | false | ""> = [ + Parameters, +] extends [never] + ? never + : Parameters extends [] + ? void + : NonUndefined[0]>; diff --git a/deno_dist/Parameters.ts b/deno_dist/Parameters.ts new file mode 100644 index 0000000..da900d6 --- /dev/null +++ b/deno_dist/Parameters.ts @@ -0,0 +1,5 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +/** https://docs.tsafe.dev/parameters */ +export type Parameters unknown) | null | undefined | false | ""> = + T extends (...args: infer P) => any ? P : never; diff --git a/deno_dist/PickOptionals.ts b/deno_dist/PickOptionals.ts new file mode 100644 index 0000000..048bd95 --- /dev/null +++ b/deno_dist/PickOptionals.ts @@ -0,0 +1,13 @@ +type OptionalKeyof> = Exclude< + { + [Key in keyof T]: T extends Record ? never : Key; + }[keyof T], + undefined +>; + +/** + * PickOptionals<{ p1: string; p2?: string; p3?: number; }> + * is the type + * { p2: string; p3: number; } + */ +export type PickOptionals> = Required>>; diff --git a/deno_dist/PickRequired.ts b/deno_dist/PickRequired.ts new file mode 100644 index 0000000..2a37d0a --- /dev/null +++ b/deno_dist/PickRequired.ts @@ -0,0 +1,8 @@ +import { PickOptionals } from "./PickOptionals.ts"; + +/** + * PickRequired<{ p1: string; p2?: string; p3?: number; p4: string; }> + * is the type + * { p1: string; p4: number; } + */ +export type PickRequired> = Omit>; diff --git a/deno_dist/README.md b/deno_dist/README.md new file mode 100644 index 0000000..2375d8a --- /dev/null +++ b/deno_dist/README.md @@ -0,0 +1,84 @@ +

+ +

+

+ A collection of utilities to take your TypeScript development up a notch +
+
+ + + + + + + + + + + + +
+ + + + (you can cherrypick what you import) +

+

+ Home + - + Documentation +

+ +## Three GIFs to convince you that you need `tsafe` in your life + +

+
+ Assert things you know are true, get runtime errors where you were wrong: +
+
+ +

+

+ Implement compile time unit testing +
+
+ + + Playground +

+

+ Make TypeScript believe whatever you say: +
+
+ +

+ +## Motivations + +Powerful TypeScript features like [assertion functions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions) or [user-defined type guards](https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards) are only useful if paired with utility functions. + +TypeScript, however, only exports type helpers \(e.g. `Record`, `ReturnType`, etc.\). + +This module provides _«the missing builtins»_ such as [the assert function](https://docs.tsafe.dev/assert) +and corrects frustrating aspects of default utility types such as [`ReturnType`](https://docs.tsafe.dev/returntype). + +[**Documentation website**](https://docs.tsafe.dev) + +## Installation + +`tsafe` is both an [NPM](https://www.npmjs.com/package/tsafe) and a [Deno](https://deno.land/x/tsafe) module. +(Achieved with [denoify](https://github.com/garronej/denoify)) + +## Import in deno: + +```typescript +import { assert, typeGuard, ... } from "https://deno.land/x/tsafe/mod.ts"; +``` + +## Install elsewhere: + +```bash +$ npm install --save tsafe +#OR +$ yarn add tsafe +``` diff --git a/deno_dist/Reflect.ts b/deno_dist/Reflect.ts new file mode 100644 index 0000000..d7e7dca --- /dev/null +++ b/deno_dist/Reflect.ts @@ -0,0 +1,5 @@ +/** Always return null but pretends it returns an object of type T */ +export function Reflect(): T { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return null as any; +} diff --git a/deno_dist/ReturnType.ts b/deno_dist/ReturnType.ts new file mode 100644 index 0000000..ddad4d3 --- /dev/null +++ b/deno_dist/ReturnType.ts @@ -0,0 +1,12 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +/** https://docs.tsafe.dev/returntype */ +export type ReturnType unknown) | undefined | null | false | ""> = + T extends (...args: any[]) => infer R ? (R extends PromiseLike ? J : R) : never; + +// ReturnType<(()=> Promise | number) | undefined> = (()=> Promise | number) | undefined extends (...args: any[]) => infer R ? +// = ( ()=> Promise | number extends (...args: any[]) => infer R ? ) | (undefined extends (...args: any[]) => infer R ? ) +// = ( Promise | number extends PromiseLike ? ) | never +// = Promise | number extends PromiseLike ? +// = ( Promise extends PromiseLike ?) | ( number extends PromiseLike ?) +// = string | number diff --git a/deno_dist/UnpackPromise.ts b/deno_dist/UnpackPromise.ts new file mode 100644 index 0000000..3d2ae2c --- /dev/null +++ b/deno_dist/UnpackPromise.ts @@ -0,0 +1,7 @@ +/** + * Use case: + * declare const pr: Promise; + * const x: UnpackPromise; <== x is string[] + */ +export type UnpackPromise | undefined | null | false | ""> = + T extends PromiseLike ? U : never; diff --git a/deno_dist/assert.ts b/deno_dist/assert.ts new file mode 100644 index 0000000..5bb21b0 --- /dev/null +++ b/deno_dist/assert.ts @@ -0,0 +1,44 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { overwriteReadonlyProp } from "./lab/overwriteReadonlyProp.ts"; +import { assertIsRefWrapper } from "./zz_internal/assertIsRefWrapper.ts"; + +/** @see */ +export class AssertionError extends Error { + constructor(msg: string | undefined) { + super(`Wrong assertion encountered` + (!msg ? "" : `: "${msg}"`)); + + Object.setPrototypeOf(this, new.target.prototype); + + if (!this.stack) { + return; + } + + try { + overwriteReadonlyProp( + this, + "stack", + this.stack + .split("\n") + .filter((...[, i]) => i !== 1 && i !== 2) + .join("\n"), + ); + // eslint-disable-next-line no-empty + } catch {} + } +} + +/** https://docs.tsafe.dev/assert */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function assert<_T extends true>(condition?: any, msg?: string): asserts condition { + if (arguments.length === 0) { + condition = true; + } + if (assertIsRefWrapper.ref !== undefined) { + assertIsRefWrapper.ref = undefined; + return; + } + + if (!condition) { + throw new AssertionError(msg); + } +} diff --git a/deno_dist/capitalize.ts b/deno_dist/capitalize.ts new file mode 100644 index 0000000..b29fce6 --- /dev/null +++ b/deno_dist/capitalize.ts @@ -0,0 +1,5 @@ +/** @see */ +export function capitalize(str: S): Capitalize { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (str.charAt(0).toUpperCase() + str.slice(1)) as any; +} diff --git a/deno_dist/exclude.ts b/deno_dist/exclude.ts new file mode 100644 index 0000000..8c4b7be --- /dev/null +++ b/deno_dist/exclude.ts @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +/** Return a function to use as Array.prototype.filter argument + * to exclude one or many primitive value element from the array. + * Ex: ([ "a", "b", "c" ] as const).filter(exclude("a")) return ("b" | "c")[] + * Ex: ([ "a", "b", "c", "d"] as const).filter(exclude(["a", "b"]) gives ("c" | "d")[] + */ +export function exclude( + target: readonly T[] | T, +) { + const test: (element: any) => boolean = + target instanceof Object + ? element => target.indexOf(element) < 0 + : element => element !== target; + + return function (str: U): str is Exclude { + return test(str); + }; +} diff --git a/deno_dist/flip.ts b/deno_dist/flip.ts new file mode 100644 index 0000000..96940f3 --- /dev/null +++ b/deno_dist/flip.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +type KeyOfType, U> = NonNullable< + { + [Key in keyof T]: T[Key] extends U | undefined ? Key : never; + }[keyof T] +>; + +/** + * Flip the value of a boolean without having to reference it twice + * after running flip(x.y, "z") x.y.z !== x.y.z, + * https://docs.tsafe.dev/flip + */ +export function flip>(object: T, prop: KeyOfType) { + if (object[prop] === undefined) { + return; + } + + return (object[prop] = !object[prop] as any); +} diff --git a/deno_dist/id.ts b/deno_dist/id.ts new file mode 100644 index 0000000..9d202e3 --- /dev/null +++ b/deno_dist/id.ts @@ -0,0 +1,37 @@ +/** https://docs.tsafe.dev/id */ +export const id = (x: T) => x; + +/** + * Ensure that a that a specific type that we are declaring extends a more generic type + * + * Use case example 1: + * + * type MyObject = { + * p1: string; + * p2: string; + * a: string; + * b: string; + * }; + * + * We want to define a type that consist in an union of + * all the property name that are letters: + * + * type AlphabeticalKeys = Id; + * + * Here AlphabeticalKeys is "a" | "b" but it's better than + * simply writing it explicitly as we get autocompletion + * and we can't include a property name that does not exist on MyObject. + * + * Use case example 2: + * + * We want to declare object type that only take string or number + * as key value: + * + * export type MyObject = Id, { + * p1: string; + * p2: number; + * }>; + * + * If later on someone adds "p3": string[] he will get a type error. + * */ +export type Id = Specific; diff --git a/deno_dist/index.ts b/deno_dist/index.ts new file mode 100644 index 0000000..a300cb2 --- /dev/null +++ b/deno_dist/index.ts @@ -0,0 +1,20 @@ +export * from "./assert.ts"; +export * from "./exclude.ts"; +export * from "./flip.ts"; +export * from "./id.ts"; +export * from "./isPromiseLike.ts"; +export type { MethodNames } from "./MethodNames.ts"; +export * from "./objectKeys.ts"; +export type { Parameters } from "./Parameters.ts"; +export type { Param0 } from "./Param0.ts"; +export type { PickOptionals } from "./PickOptionals.ts"; +export type { ReturnType } from "./ReturnType.ts"; +export * from "./typeGuard.ts"; +export type { UnpackPromise } from "./UnpackPromise.ts"; +export * from "./is.ts"; +export type { Equals } from "./Equals.ts"; +export type { Not } from "./Not.ts"; +export * from "./objectEntries.ts"; +export * from "./objectFromEntries.ts"; +export * from "./noUndefined.ts"; +export * from "./Reflect.ts"; diff --git a/deno_dist/is.ts b/deno_dist/is.ts new file mode 100644 index 0000000..042eea3 --- /dev/null +++ b/deno_dist/is.ts @@ -0,0 +1,28 @@ +/* eslint-disable @typescript-eslint/no-namespace */ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { assertIsRefWrapper } from "./zz_internal/assertIsRefWrapper.ts"; + +const errorMessage = [ + `Wrong usage of the ${is.name} function refer to`, + `https://docs.tsafe.dev/${is.name.toLowerCase()}`, +].join(" "); + +export function is(_value: any): _value is T { + const ref = {}; + + if (assertIsRefWrapper.ref !== undefined) { + assertIsRefWrapper.ref = undefined; + throw new Error(errorMessage); + } + + assertIsRefWrapper.ref = ref; + + Promise.resolve().then(() => { + if (assertIsRefWrapper.ref === ref) { + throw new Error(errorMessage); + } + }); + + return null as any; +} diff --git a/deno_dist/isPromiseLike.ts b/deno_dist/isPromiseLike.ts new file mode 100644 index 0000000..fdd00a1 --- /dev/null +++ b/deno_dist/isPromiseLike.ts @@ -0,0 +1,4 @@ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function isPromiseLike(o: any): o is PromiseLike { + return typeof o?.then === "function"; +} diff --git a/deno_dist/lab/PromiseOrNot.ts b/deno_dist/lab/PromiseOrNot.ts new file mode 100644 index 0000000..5ad9139 --- /dev/null +++ b/deno_dist/lab/PromiseOrNot.ts @@ -0,0 +1 @@ +export type PromiseOrNot = PromiseLike | T; diff --git a/deno_dist/lab/UnpackTypeGuard.ts b/deno_dist/lab/UnpackTypeGuard.ts new file mode 100644 index 0000000..d6e90ea --- /dev/null +++ b/deno_dist/lab/UnpackTypeGuard.ts @@ -0,0 +1,5 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +export type UnpackTypeGuard o is unknown> = T extends (o: any) => o is infer U + ? U + : never; diff --git a/deno_dist/lab/defineAccessors.ts b/deno_dist/lab/defineAccessors.ts new file mode 100644 index 0000000..7fc7aa7 --- /dev/null +++ b/deno_dist/lab/defineAccessors.ts @@ -0,0 +1,31 @@ +export const defineAccessors = , K extends keyof T>( + obj: T, + propertyName: K, + propertyDescriptor: { + get?: () => T[K]; + set?: (value: T[K]) => void; + }, +): void => { + const { get, set } = propertyDescriptor; + + Object.defineProperty(obj, propertyName, { + ...(Object.getOwnPropertyDescriptor(obj, propertyName) || { + "enumerable": true, + "configurable": true, + }), + ...(get !== undefined + ? { + "get": function () { + return get.call(this); + }, + } + : {}), + ...(set !== undefined + ? { + "set": function (value: T[K]) { + set.call(this, value); + }, + } + : {}), + }); +}; diff --git a/deno_dist/lab/overwriteReadonlyProp.ts b/deno_dist/lab/overwriteReadonlyProp.ts new file mode 100644 index 0000000..b684d12 --- /dev/null +++ b/deno_dist/lab/overwriteReadonlyProp.ts @@ -0,0 +1,52 @@ +/* eslint-disable no-empty */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { assert } from "../assert.ts"; +import { is } from "../is.ts"; + +/** + * Assign a value to a property even if the object is freezed or if the property is not writable + * Throw if the assignation fail ( for example if the property is non configurable write: false ) + * */ +export const overwriteReadonlyProp = ( + obj: T, + propertyName: K, + value: T[K], +): T[K] => { + try { + obj[propertyName] = value; + } catch {} + + if (obj[propertyName] === value) { + return value; + } + + let errorDefineProperty: Error | undefined = undefined; + + const propertyDescriptor: PropertyDescriptor = Object.getOwnPropertyDescriptor( + obj, + propertyName, + ) || { + "enumerable": true, + "configurable": true, + }; + + if (!!propertyDescriptor.get) { + throw new Error(`Probably a wrong ides to overwrite ${String(propertyName)} getter`); + } + + try { + Object.defineProperty(obj, propertyName, { + ...propertyDescriptor, + value, + }); + } catch (error) { + assert(is(error)); + errorDefineProperty = error; + } + + if (obj[propertyName] !== value) { + throw errorDefineProperty || new Error("Can't assign"); + } + + return value; +}; diff --git a/deno_dist/lab/withDefaults.ts b/deno_dist/lab/withDefaults.ts new file mode 100644 index 0000000..00144e2 --- /dev/null +++ b/deno_dist/lab/withDefaults.ts @@ -0,0 +1,33 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import "../tools/Object.fromEntries.ts"; +/** + * Like Function.prototype.bind() but for a function that + * receives their parameters wrapped in an object. + * See documentation for more details: + * https://docs.tsafe.dev/withdefaults + */ +export function withDefaults, DefaultKey extends keyof Params, R>( + f: (params: Params) => R, + defaultParams: keyof Params extends never + ? Record + : { [Key in DefaultKey]: Params[Key] }, +): ( + params: { [Key in keyof Omit]: Params[Key] } & { + defaultsOverwrite?: { [Key in DefaultKey]?: [Params[Key]] }; + }, +) => R { + return params => { + const { defaultsOverwrite = {}, ...actualParams } = params; + + return f({ + ...defaultParams, + ...actualParams, + ...Object.fromEntries( + Object.entries(defaultsOverwrite) + .filter(([, value]) => value !== undefined) + .map(([key, value]) => [key, (value as any)[0]]), + ), + } as any); + }; +} diff --git a/deno_dist/mod.ts b/deno_dist/mod.ts new file mode 100644 index 0000000..da5ee32 --- /dev/null +++ b/deno_dist/mod.ts @@ -0,0 +1 @@ +export * from "./index.ts"; \ No newline at end of file diff --git a/deno_dist/noUndefined.ts b/deno_dist/noUndefined.ts new file mode 100644 index 0000000..d2d1012 --- /dev/null +++ b/deno_dist/noUndefined.ts @@ -0,0 +1,24 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/ban-types */ + +/** + * Removes the enumerable properties whose values are + * undefined. + * + * Example: + * noUndefined({ "foo": undefined, "bar": 3 }) returns + * a new object { "bar": 3 } + */ +export function noUndefined(obj: T): T { + const out: typeof obj = {} as any; + + for (const key in obj) { + if (obj[key] === undefined) { + continue; + } + + out[key] = obj[key]; + } + + return out; +} diff --git a/deno_dist/objectEntries.ts b/deno_dist/objectEntries.ts new file mode 100644 index 0000000..c7d0c51 --- /dev/null +++ b/deno_dist/objectEntries.ts @@ -0,0 +1,11 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +/** https://docs.tsafe.dev/objectentries */ +export function objectEntries>( + o: O, +): { [Key in keyof O]: [Key, O[Key]] }[keyof O] { + return Object.entries(o) as any; +} + +/** Return type of objectEntries https://docs.tsafe.dev/objectentries */ +export type ObjectEntries> = { [Key in keyof O]: [Key, O[Key]] }[keyof O]; diff --git a/deno_dist/objectFromEntries.ts b/deno_dist/objectFromEntries.ts new file mode 100644 index 0000000..8c060a0 --- /dev/null +++ b/deno_dist/objectFromEntries.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +/** https://docs.tsafe.dev/objectFromEntries */ +export function objectFromEntries( + entries: readonly Entry[], +): { [Key in Entry[0]]: Extract[1] } { + return Object.fromEntries(entries) as any; +} + +/** Return type of objectFromEntries https://docs.tsafe.dev/objectFromEntries */ +export type ObjectFromEntries = { + [Key in Entry[0]]: Extract[1]; +}; diff --git a/deno_dist/objectKeys.ts b/deno_dist/objectKeys.ts new file mode 100644 index 0000000..f732807 --- /dev/null +++ b/deno_dist/objectKeys.ts @@ -0,0 +1,6 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +/** https://docs.tsafe.dev/objectKeys */ +export function objectKeys>(o: T): (keyof T)[] { + return Object.keys(o) as any; +} diff --git a/deno_dist/res/Equals_example1.ts b/deno_dist/res/Equals_example1.ts new file mode 100644 index 0000000..8af71e3 --- /dev/null +++ b/deno_dist/res/Equals_example1.ts @@ -0,0 +1,12 @@ +/* eslint-disable @typescript-eslint/ban-types */ +import type { Equals } from "../index.ts"; +import { assert } from "../assert.ts"; + +export function myFunction(params: { foo: string; bar: string; baz: string }) { + const { foo, bar, baz, ...rest } = params; + + //We check that whe have deconstructed all the parameters. + assert>(); + + console.log(foo, bar, baz); +} diff --git a/deno_dist/res/Equals_example2.ts b/deno_dist/res/Equals_example2.ts new file mode 100644 index 0000000..9176422 --- /dev/null +++ b/deno_dist/res/Equals_example2.ts @@ -0,0 +1,8 @@ +/* eslint-disable @typescript-eslint/ban-types */ +import type { Equals } from "../index.ts"; +import { assert } from "../assert.ts"; + +type A = { foo: string } | undefined; +type B = undefined | { foo: string }; + +assert>(); diff --git a/deno_dist/res/Equals_example3.ts b/deno_dist/res/Equals_example3.ts new file mode 100644 index 0000000..c368435 --- /dev/null +++ b/deno_dist/res/Equals_example3.ts @@ -0,0 +1,9 @@ +/* eslint-disable @typescript-eslint/ban-types */ +import type { Equals } from "../index.ts"; +import { assert } from "../assert.ts"; + +declare function theTestedFunction(): Record; + +const out = theTestedFunction<"foo" | "bar">(); + +assert>(); diff --git a/deno_dist/res/Equals_example4.ts b/deno_dist/res/Equals_example4.ts new file mode 100644 index 0000000..6faa56b --- /dev/null +++ b/deno_dist/res/Equals_example4.ts @@ -0,0 +1,11 @@ +/* eslint-disable @typescript-eslint/ban-types */ +import type { Equals, Not } from "../index.ts"; +import { assert } from "../assert.ts"; + +type A = { foo: string }; +type B = { foo: number }; + +//@ts-expect-error: A is not equal to B +assert>(); + +assert>>(); diff --git a/deno_dist/symToStr.ts b/deno_dist/symToStr.ts new file mode 100644 index 0000000..333cfa9 --- /dev/null +++ b/deno_dist/symToStr.ts @@ -0,0 +1,4 @@ +/** @see */ +export function symToStr>(wrap: T): keyof T { + return Object.keys(wrap)[0]; +} diff --git a/deno_dist/test/Equals.ts b/deno_dist/test/Equals.ts new file mode 100644 index 0000000..18bc049 --- /dev/null +++ b/deno_dist/test/Equals.ts @@ -0,0 +1,42 @@ +import type { Equals } from "../Equals.ts"; +import { assert } from "../assert.ts"; +import type { Unite } from "../tools/Unite.ts"; +import type { StrictEquals } from "../tools/StrictEquals.ts"; + +type Shape = Circle | Square; + +type Circle = { + type: "circle"; + radius: number; +}; + +type Square = { + type: "square"; + sideLength: number; +}; + +{ + type Got = Unite; + + type Expected = Shape; + + assert>(); +} + +{ + type A = { + foo: string; + } & { + bar: number; + }; + + type B = { + foo: string; + bar: number; + }; + + //@ts-expect-error: Because of the & + assert>(); + + assert>(); +} diff --git a/deno_dist/test/Extends.ts b/deno_dist/test/Extends.ts new file mode 100644 index 0000000..1969aad --- /dev/null +++ b/deno_dist/test/Extends.ts @@ -0,0 +1,139 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import type { Equals } from "../Equals.ts"; +import type { Extends } from "../Extends.ts"; +import { assert } from "../assert.ts"; + +const emptyObj = {}; + +type EmptyObj = typeof emptyObj; + +type Fn = (...args: A) => R; + +type Obj = Record; + +function fn() { + return undefined; +} + +class A { + a = 1; +} + +{ + // identity + assert, true>>(); + assert, true>>(); + assert, true>>(); + assert, true>>(); + assert, true>>(); + assert, true>>(); + assert, true>>(); + assert, true>>(); + assert, true>>(); + assert, true>>(); + assert, true>>(); + assert, true>>(); + assert, true>>(); + assert, true>>(); +} + +{ + // never extends everything + assert, true>>(); + assert, true>>(); + assert, true>>(); + assert, true>>(); + + // nothing but itself extends never + assert, true>>(); + assert, false>>(); + assert, false>>(); + assert, false>>(); + + // any extends nothing but itself and unknown + assert, true>>(); + assert, false>>(); + assert, true>>(); + assert, false>>(); + + // unknown extends nothing but itself and any + assert, true>>(); + assert, false>>(); + assert, true>>(); + assert, false>>(); + + // everything extends any + assert, true>>(); + assert, true>>(); + assert, true>>(); + + // everything extends unknown + assert, true>>(); + assert, true>>(); + assert, true>>(); +} + +{ + // numbers + assert, true>>(); + assert, false>>(); +} + +{ + // functions + assert any, Fn>, true>>(); + assert void, Fn>, true>>(); + assert any, Fn>, true>>(); + assert, true>>(); + + assert, false>>(); + assert, false>>(); + assert, false>>(); + assert, false>>(); + assert, false>>(); + assert, false>>(); + assert, false>>(); + assert, false>>(); + assert, Fn>, false>>(); + assert, false>>(); +} + +{ + // arrays + assert, true>>(); + assert, true>>(); + assert, false>>(); + assert, true>>(); + assert, false>>(); + assert, true>>(); + assert, false>>(); + + assert, true>>(); + assert, false>>(); + assert, true>>(); + assert, false>>(); + + assert, true>>(); + assert, true>>(); + assert, false>>(); + assert, false>>(); + assert, false>>(); + assert, false>>(); +} + +{ + // objects + assert, true>>(); + assert, false>>(); + + assert>, true>>(); + assert, A>, false>>(); + + assert, true>>(); + assert, false>>(); + + assert, false>>(); + assert, true>>(); + assert, true>>(); + assert, false>>(); +} diff --git a/deno_dist/test/MethodNames.ts b/deno_dist/test/MethodNames.ts new file mode 100644 index 0000000..0c8f530 --- /dev/null +++ b/deno_dist/test/MethodNames.ts @@ -0,0 +1,60 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import type { MethodNames } from "../MethodNames.ts"; +import { assert } from "../assert.ts"; +import type { Equals } from "../Equals.ts"; + +{ + type A = { + a: string; + b: number; + + method1(): void; + method2?(params: { a: boolean; b: string }): number; + }; + + type Expected = "method1" | "method2"; + + type Got = MethodNames; + + assert>(); +} + +class Car { + public readonly foo: string; + + constructor() { + this.foo = "caca"; + } +} + +{ + type A = { + a: unknown; + b: unknown; + method1?(): void; + // eslint-disable-next-line @typescript-eslint/ban-types + method2: Function; + method3?: (args: { a: unknown }) => unknown; + Car: typeof Car; + }; + + type Expected = "method1" | "method3"; + type Got = MethodNames; + + assert>(); +} + +{ + interface A { + a: string; + b: string; + + method1(arg: unknown): unknown; + method2?: (arg: unknown) => unknown; + } + + type Expected = "method1" | "method2"; + type Got = MethodNames; + + assert>(); +} diff --git a/deno_dist/test/Parameters.ts b/deno_dist/test/Parameters.ts new file mode 100644 index 0000000..30c3ea7 --- /dev/null +++ b/deno_dist/test/Parameters.ts @@ -0,0 +1,56 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import type { Parameters } from "../Parameters.ts"; +import { assert } from "../assert.ts"; +import type { Equals } from "../Equals.ts"; + +{ + const myFunction = (arg1: unknown, arg2: string, extraParams: { a: number; b: number }) => { + return { + arg1, + arg2, + extraParams, + }; + }; + + type Expected = [arg1: unknown, arg2: string, extraParams: { a: number; b: number }]; + type Got = Parameters; + + assert>(); +} + +{ + type A = { + a: number; + method: (arg1: number, arg2?: string) => void; + }; + + type Expected = [arg1: number, arg2?: string | undefined]; // [number] | [number, string | undefined] + type Got = Parameters; + + assert>(); +} + +{ + //@ts-expect-error + type X = Parameters; +} + +{ + type Expected = [searchString: string, position?: number | undefined]; + type Got = Parameters; + + assert>(); +} + +{ + class A { + a: string; + constructor(a: string) { + this.a = a; + } + } + + //@ts-expect-error + type Got = Parameters; +} diff --git a/deno_dist/test/Params0.ts b/deno_dist/test/Params0.ts new file mode 100644 index 0000000..0be03b0 --- /dev/null +++ b/deno_dist/test/Params0.ts @@ -0,0 +1,80 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import type { Param0 } from "../Param0.ts"; +import { assert } from "../assert.ts"; +import type { Equals } from "../Equals.ts"; + +//@ts-ignore +function test() { + const f = (params: { foo: T; bar: U }) => { + return params; + }; + + type Expected = { + foo: T; + bar: U; + }; + + type Got = Param0; + + assert>(); +} + +//@ts-ignore +function test() { + const f = (params: { foo: T; bar: U }, a: unknown, b: unknown) => { + return { + ...params, + a, + b, + }; + }; + + type Expected = { + foo: T; + bar: U; + }; + + type Got = Param0; + + assert>(); +} + +{ + //@ts-expect-error + type Got = Params; +} + +{ + class A { + foo: number; + + constructor(foo: number) { + this.foo = foo; + } + } + + //@ts-expect-error + type Got = Params; +} + +{ + type Got = Param0; + type Expected = never; + + assert>(); +} + +{ + type Got = Param0<((params: { foo: string }) => void) | undefined | null | false | "">; + type Expected = { foo: string }; + + assert>(); +} + +{ + type Got = Param0<(() => void) | undefined | null | false | "">; + type Expected = void; + + assert>(); +} diff --git a/deno_dist/test/PickOptionals.ts b/deno_dist/test/PickOptionals.ts new file mode 100644 index 0000000..32e59a6 --- /dev/null +++ b/deno_dist/test/PickOptionals.ts @@ -0,0 +1,51 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import type { PickOptionals } from "../PickOptionals.ts"; +import { assert } from "../assert.ts"; +import type { Equals } from "../Equals.ts"; + +{ + type A = { + a: number; + b?: number; + method1(param: string): number; + method2?(params: { a: string; b: number }): typeof params; + }; + + type Expected = { + b: number; + method2(params: { a: string; b: number }): typeof params; + }; + type Got = PickOptionals; + + assert>(); +} + +{ + type A = { + a: number | undefined; + b?: string; + }; + + type Expected = { + b: string; + }; + type Got = PickOptionals; + + assert>(); +} + +{ + interface A { + a: number; + b: string; + c?: unknown; + method1?: () => void; + } + + //@ts-expect-error + type Got = PickOptionals; +} + +//@ts-expect-error +type X = PickOptionals; diff --git a/deno_dist/test/PickRequired.ts b/deno_dist/test/PickRequired.ts new file mode 100644 index 0000000..08dc03b --- /dev/null +++ b/deno_dist/test/PickRequired.ts @@ -0,0 +1,53 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import { PickRequired } from "../PickRequired.ts"; +import { assert } from "../assert.ts"; +import type { Equals } from "../Equals.ts"; + +{ + type A = { + a: number; + b?: number; + method1(param: string): number; + method2?(params: { a: string; b: number }): typeof params; + }; + + type Expected = { + a: number; + method1(param: string): number; + }; + + type Got = PickRequired; + + assert>(); +} + +{ + type A = { + a: number | undefined; + b?: string; + }; + + type Expected = { + a: number | undefined; + }; + + type Got = PickRequired; + + assert>(); +} + +{ + interface A { + a: number; + b: string; + c?: unknown; + method1?: () => void; + } + + //@ts-expect-error + type Got = PickRequired; +} + +//@ts-expect-error +type X = PickRequired; diff --git a/deno_dist/test/ReturnType.ts b/deno_dist/test/ReturnType.ts new file mode 100644 index 0000000..af6cfef --- /dev/null +++ b/deno_dist/test/ReturnType.ts @@ -0,0 +1,72 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import type { ReturnType } from "../ReturnType.ts"; +import { assert } from "../assert.ts"; +import type { Equals } from "../Equals.ts"; + +{ + const getStringAsync: () => Promise = null as any; + + type Got = ReturnType; + type Expected = string; + + assert>(); +} + +{ + const getString = (): string => { + return null as any; + }; + + type Got = ReturnType; + type Expected = string; + + assert>(); +} + +{ + const getString: () => PromiseLike = null as any; + + type Got = ReturnType; + type Expected = string; + + assert>(); +} + +{ + const getString: () => PromiseLike | number = null as any; + + type Got = ReturnType; + type Expected = string | number; + + assert>(); +} + +{ + //@ts-expect-error + type Got = ReturnType; +} + +{ + //@ts-expect-error + type Got = ReturnType>; +} + +{ + const getString: (() => PromiseLike) | undefined = null as any; + + type Got = ReturnType; + type Expected = string; + + assert>(); +} + +{ + const getString: (() => PromiseLike) | null = null as any; + + type Got = ReturnType; + type Expected = string; + + assert>(); +} diff --git a/deno_dist/test/UnpackPromise.ts b/deno_dist/test/UnpackPromise.ts new file mode 100644 index 0000000..a2731ed --- /dev/null +++ b/deno_dist/test/UnpackPromise.ts @@ -0,0 +1,43 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import type { UnpackPromise } from "../UnpackPromise.ts"; +import { assert } from "../assert.ts"; +import type { Equals } from "../Equals.ts"; + +//@ts-ignore +function test() { + const prT = new Promise(resolve => setTimeout(resolve, 1)); + + type Expected = T; + type Got = UnpackPromise; + + assert>(); +} + +//@ts-ignore +function test() { + const f = async () => { + const out: T = null as any; + return out; + }; + + const prT = f(); + + type Expected = T; + type Got = UnpackPromise; + + assert>(); +} + +{ + type Got = UnpackPromise; + type Expected = never; + + assert>(); +} + +{ + //@ts-expect-error + type Got = UnpackPromise; +} diff --git a/deno_dist/test/UnpackTypeGuard.ts b/deno_dist/test/UnpackTypeGuard.ts new file mode 100644 index 0000000..2e18896 --- /dev/null +++ b/deno_dist/test/UnpackTypeGuard.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import type { UnpackTypeGuard } from "../lab/UnpackTypeGuard.ts"; +import { assert } from "../assert.ts"; +import type { Equals } from "../Equals.ts"; + +{ + const isFoo = (_o: any): _o is "foo" => { + return null as any; + }; + + type Expected = "foo"; + type Got = UnpackTypeGuard; + + assert>(); +} diff --git a/deno_dist/test/assertIs.ts b/deno_dist/test/assertIs.ts new file mode 100644 index 0000000..9dc1ee4 --- /dev/null +++ b/deno_dist/test/assertIs.ts @@ -0,0 +1,49 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { assert } from "../assert.ts"; +import { is } from "../is.ts"; +import type { Equals } from "../Equals.ts"; + +{ + const x: string | number | boolean = null as any; + + assert(is(x)); + + assert>(); + + console.log("PASS"); +} + +{ + const x: string | number | boolean = null as any; + + assert(!is(x)); + + assert>(); + + console.log("PASS"); +} + +{ + is(null); + + try { + is(null); + throw new Error("FAIL"); + // eslint-disable-next-line no-empty + } catch {} + + console.log("PASS"); +} + +scope: { + try { + assert(undefined); + } catch { + console.log("PASS"); + + break scope; + } + + throw new Error("Fail"); +} diff --git a/deno_dist/test/exclude.ts b/deno_dist/test/exclude.ts new file mode 100644 index 0000000..1a4c289 --- /dev/null +++ b/deno_dist/test/exclude.ts @@ -0,0 +1,43 @@ +import { exclude } from "../exclude.ts"; +import { assert } from "../assert.ts"; +import { same } from "https://raw.githubusercontent.com/garronej/evt/v2.3.0/deno_dist/tools/inDepth/same.ts"; + +{ + const got = ["a", "b", "c"].filter(exclude("a")); + + const expected = ["b", "c"]; + + assert(same(got, expected)); + + console.log("PASS TEST 1"); +} + +{ + const got = ["a", "b", "c"].filter(exclude(["a"])); + + const expected = ["b", "c"]; + + assert(same(got, expected)); + + console.log("PASS TEST 2"); +} + +{ + const got = [1, 2, 3].filter(exclude("foo")); + + const expected = [1, 2, 3]; + + assert(same(got, expected)); + + console.log("PASS TEST 3"); +} + +{ + const got = ["a", "b", "c", "d"].filter(exclude(["a", "b"])); + + const expected = ["c", "d"]; + + assert(same(got, expected)); + + console.log("PASS TEST 4"); +} diff --git a/deno_dist/test/exclude.types.ts b/deno_dist/test/exclude.types.ts new file mode 100644 index 0000000..46a69f0 --- /dev/null +++ b/deno_dist/test/exclude.types.ts @@ -0,0 +1,38 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import { exclude } from "../exclude.ts"; +import { assert } from "../assert.ts"; +import type { Equals } from "../Equals.ts"; + +{ + const x = (["a", "b", "c"] as const).filter(exclude(["a"])); + + type Got = typeof x; + type Expected = ("b" | "c")[]; + + assert>(); +} + +{ + const x = (["a", "b", "c", "d"] as const).filter(exclude(["a", "b"])); + + type Got = typeof x; + type Expected = ("c" | "d")[]; + + assert>(); +} + +{ + const x = [3, "a", false].filter(exclude([3])); + + type Got = typeof x; + + type Expected = (number | string | boolean)[]; + + assert>(); +} + +{ + //@ts-expect-error + const x = (["a", "b", "c", "d"] as const).filter(exclude("a", "b")); +} diff --git a/deno_dist/test/flip.ts b/deno_dist/test/flip.ts new file mode 100644 index 0000000..79d1b26 --- /dev/null +++ b/deno_dist/test/flip.ts @@ -0,0 +1,142 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { flip } from "../flip.ts"; +import { assert } from "../assert.ts"; + +{ + const obj = { + "is_": true, + "a": 1, + }; + + const expected = false; + + flip(obj, "is_"); + + const got = obj.is_; + + assert(got === expected); + + console.log("PASS TEST 1"); +} + +{ + const obj = { + "is_": true, + }; + + const expected = false; + + const got = flip(obj, "is_"); + + assert(got === expected); + + console.log("PASS TEST 2"); +} + +{ + const obj = { + "a": { + "is_": true, + "aa": 1, + }, + }; + + const expected = false; + + flip(obj.a, "is_"); + + const got = obj.a.is_; + + assert(got === expected); + + console.log("PASS TEST 3"); +} + +{ + interface A { + is_: boolean; + a: number; + } + + const obj: A = { + "a": 1, + "is_": true, + }; + + const expected = false; + + flip(obj, "is_"); + + const got = obj.is_; + + assert(got === expected); + + console.log("PASS TEST 4"); +} + +{ + class A { + is_: boolean; + a: number; + + constructor(is_: boolean, a: number) { + this.is_ = is_; + this.a = a; + } + } + + const obj = new A(true, 1); + + const expected = false; + + flip(obj, "is_"); + + const got = obj.is_; + + assert(got === expected); + + console.log("PASS TEST 5"); +} + +{ + type A = { + is_?: boolean; + a: number; + }; + + const obj: A = { + "a": 1, + "is_": true, + }; + + const expected = false; + + flip(obj, "is_"); + + const got = obj.is_; + + assert(got === expected); + + console.log("PASS TEST 6"); +} + +{ + type A = { + is_?: boolean; + a: number; + }; + + const obj: A = { + "a": 1, + }; + + const expected = undefined; + + flip(obj, "is_"); + + const got = obj.is_; + + assert(got === expected); + + console.log("PASS TEST 7"); +} diff --git a/deno_dist/test/flip.type.ts b/deno_dist/test/flip.type.ts new file mode 100644 index 0000000..2a6fa5e --- /dev/null +++ b/deno_dist/test/flip.type.ts @@ -0,0 +1,26 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import { flip } from "../flip.ts"; + +{ + const obj = { + "is_": true, + "a": 1, + }; + + //@ts-expect-error + flip(obj, "a"); +} + +{ + type A = { + "is_": boolean; + "a"?: number; + }; + + const obj: A = { + "is_": true, + }; + + //@ts-expect-error + flip(obj, "a"); +} diff --git a/deno_dist/test/getProjectRoot.ts b/deno_dist/test/getProjectRoot.ts new file mode 100644 index 0000000..cf41fb0 --- /dev/null +++ b/deno_dist/test/getProjectRoot.ts @@ -0,0 +1,3 @@ +import { getProjectRoot } from "../tools/getProjectRoot.ts"; + +console.log(`Project root path: ${getProjectRoot()} does it seems right ? If yes then PASS`); diff --git a/deno_dist/test/id.ts b/deno_dist/test/id.ts new file mode 100644 index 0000000..5edd8c7 --- /dev/null +++ b/deno_dist/test/id.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import { id } from "../id.ts"; + +{ + type Square = { + type: "SQUARE"; + side: number; + }; + + type Circle = { + type: "CIRCLE"; + radius: number; + }; + + id({ "type": "SQUARE", "side": 12 }); + + //@ts-expect-error + id({ "type": "SQUARE", "side": 12 }); +} diff --git a/deno_dist/test/index.ts b/deno_dist/test/index.ts new file mode 100644 index 0000000..c651288 --- /dev/null +++ b/deno_dist/test/index.ts @@ -0,0 +1,92 @@ +const __dirname = (() => { + const { url: urlStr } = import.meta; + const url = new URL(urlStr); + const __filename = (url.protocol === "file:" ? url.pathname : urlStr) + .replace(/[/][^/]*$/, ''); + + const isWindows = (() => { + + let NATIVE_OS: typeof Deno.build.os = "linux"; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const navigator = (globalThis as any).navigator; + if (globalThis.Deno != null) { + NATIVE_OS = Deno.build.os; + } else if (navigator?.appVersion?.includes?.("Win") ?? false) { + NATIVE_OS = "windows"; + } + + return NATIVE_OS == "windows"; + + })(); + + return isWindows ? + __filename.split("/").join("\\").substring(1) : + __filename; +})(); + +const __filename = (() => { + const { url: urlStr } = import.meta; + const url = new URL(urlStr); + const __filename = (url.protocol === "file:" ? url.pathname : urlStr); + + const isWindows = (() => { + + let NATIVE_OS: typeof Deno.build.os = "linux"; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const navigator = (globalThis as any).navigator; + if (globalThis.Deno != null) { + NATIVE_OS = Deno.build.os; + } else if (navigator?.appVersion?.includes?.("Win") ?? false) { + NATIVE_OS = "windows"; + } + + return NATIVE_OS == "windows"; + + })(); + + return isWindows ? + __filename.split("/").join("\\").substring(1) : + __filename; +})(); + +//This will not run on deno, we need a separate test runner for Deno (./mod.ts). + +import * as child_process from "https://deno.land/std@0.157.0/node/child_process.ts"; +import * as path from "https://deno.land/std@0.157.0/node/path.ts"; +import { Deferred } from "https://raw.githubusercontent.com/garronej/evt/v2.3.0/deno_dist/tools/Deferred.ts"; + +const names = ["withDefault", "flip", "objectKeys", "isPromiseLike", "assertIs", "exclude"]; + +(async () => { + if (!!process.env.FORK) { + process.once("unhandledRejection", error => { + throw error; + }); + + require(process.env.FORK); + + return; + } + + for (const name of names) { + console.log(`Running: ${name}`); + + const dExitCode = new Deferred(); + + child_process + .fork(__filename, undefined, { + "env": { "FORK": path.join(__dirname, name) }, + }) + .on("message", console.log) + .once("exit", code => dExitCode.resolve(code ?? 1)); + + const exitCode = await dExitCode.pr; + + if (exitCode !== 0) { + console.log(`${name} exited with error code: ${exitCode}`); + process.exit(exitCode); + } + + console.log("\n"); + } +})(); diff --git a/deno_dist/test/isPromiseLike.ts b/deno_dist/test/isPromiseLike.ts new file mode 100644 index 0000000..9aee073 --- /dev/null +++ b/deno_dist/test/isPromiseLike.ts @@ -0,0 +1,94 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { isPromiseLike } from "../isPromiseLike.ts"; +import { assert } from "../assert.ts"; + +{ + const x = new Promise(resolve => setTimeout(() => resolve, 1000)); + + const got = isPromiseLike(x); + + assert(got === true); + + console.log("PASS TEST 1"); +} + +{ + const x = { + "then": () => null, + "a": 1, + "b": "foo", + "c": null, + }; + + assert(isPromiseLike(x)); + + console.log("PASS TEST 2"); +} + +{ + const x = async () => { + return 1; + }; + + assert(isPromiseLike(x())); + + console.log("PASS TEST 3"); +} + +{ + const x = async () => { + return 1; + }; + + assert(!isPromiseLike(x)); + + console.log("PASS TESt 4"); +} + +{ + const x: PromiseLike = { + "then": () => null as any, + }; + + assert(isPromiseLike(x)); + + console.log("PASS TEST 5"); +} + +{ + const x = false; + + assert(!isPromiseLike(x)); + + console.log("PASS TEST 6"); +} + +{ + class X { + then: () => void; + + constructor(then: () => void) { + this.then = then; + } + } + + const x = new X(() => null); + + assert(isPromiseLike(x)); + + console.log("PASS TEST 7"); +} + +{ + interface X { + then: () => void; + } + + const x: X = { + "then": () => null, + }; + + assert(isPromiseLike(x)); + + console.log("PASS TEST 8"); +} diff --git a/deno_dist/test/mod.ts b/deno_dist/test/mod.ts new file mode 100644 index 0000000..82569e5 --- /dev/null +++ b/deno_dist/test/mod.ts @@ -0,0 +1,5 @@ +import "./withDefault.ts"; +import "./flip.ts"; +import "./objectKeys.ts"; +import "./isPromiseLike.ts"; +import "./assertIs.ts"; diff --git a/deno_dist/test/objectEntries.types.ts b/deno_dist/test/objectEntries.types.ts new file mode 100644 index 0000000..f354dd9 --- /dev/null +++ b/deno_dist/test/objectEntries.types.ts @@ -0,0 +1,35 @@ +import type { Equals, ObjectEntries } from "../index.ts"; +import { objectEntries } from "../objectEntries.ts"; +import { assert } from "../assert.ts"; + +{ + const o = { + "a": "foo", + "b": 33, + "c": true, + }; + + const entries = objectEntries(o); + + assert>(); +} + +{ + const o = { + "a": "foo", + "b": 33, + "c": true, + } as const; + + const entries = objectEntries(o); + + assert>(); +} + +{ + type Input = { a: string; b: number; c: boolean }; + + type Expect = ["a", string] | ["b", number] | ["c", boolean]; + + assert, Expect>>(); +} diff --git a/deno_dist/test/objectFromEntries.types.ts b/deno_dist/test/objectFromEntries.types.ts new file mode 100644 index 0000000..29a396f --- /dev/null +++ b/deno_dist/test/objectFromEntries.types.ts @@ -0,0 +1,64 @@ +import type { Equals, ObjectFromEntries } from "../index.ts"; +import { objectFromEntries } from "../objectFromEntries.ts"; +import { assert } from "../assert.ts"; +import { id } from "../id.ts"; + +{ + const entries = [ + ["a", "foo"], + ["b", 33], + ["c", true], + ] as const; + + const obj = objectFromEntries(entries); + + Object.entries; + + assert< + Equals< + typeof obj, + { + a: "foo"; + b: 33; + c: true; + } + > + >(); +} + +{ + const entries = [ + ["a", id("foo")], + ["b", id(33)], + ["c", id(true)], + ] as const; + + const obj = objectFromEntries(entries); + + assert< + Equals< + typeof obj, + { + a: string; + b: number; + c: boolean; + } + > + >(); +} + +{ + type Entry = readonly ["a", string] | readonly ["b", number]; + + type O = ObjectFromEntries; + + assert< + Equals< + O, + { + a: string; + b: number; + } + > + >(); +} diff --git a/deno_dist/test/objectKeys.ts b/deno_dist/test/objectKeys.ts new file mode 100644 index 0000000..caa6d36 --- /dev/null +++ b/deno_dist/test/objectKeys.ts @@ -0,0 +1,41 @@ +import { objectKeys } from "../objectKeys.ts"; +import { assert } from "../assert.ts"; +import { same } from "https://raw.githubusercontent.com/garronej/evt/v2.3.0/deno_dist/tools/inDepth/same.ts"; + +{ + type A = { + a: number; + b: number; + c: number; + }; + + const obj: A = { + "a": 1, + "b": 2, + "c": 3, + }; + + const got = objectKeys(obj); + + const expected = ["a", "b", "c"]; + + assert(same(got, expected)); + + console.log("PASS TEST 1"); +} + +{ + const obj = { + "a": 1, + "b": 2, + "c": 3, + }; + + const got = objectKeys<{ a: number; b: number }>(obj); + + const expected = ["a", "b", "c"]; + + assert(same(got, expected)); + + console.log("PASS TEST 2"); +} diff --git a/deno_dist/test/objectKeys.types.ts b/deno_dist/test/objectKeys.types.ts new file mode 100644 index 0000000..1b6aa7e --- /dev/null +++ b/deno_dist/test/objectKeys.types.ts @@ -0,0 +1,111 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import { objectKeys } from "../objectKeys.ts"; +import { assert } from "../assert.ts"; +import type { Equals } from "../Equals.ts"; + +{ + const obj = { + "a": 1, + "b": "ok", + "c": null, + }; + + const x = objectKeys(obj); + + type Expected = ("a" | "b" | "c")[]; + + type Got = typeof x; + + assert>(); +} + +{ + type A = { + a: number; + b: string; + c: null; + }; + const obj: A = { + "a": 1, + "b": "ok", + "c": null, + }; + + const x = objectKeys<{ a: number; b: string }>(obj); + + type Expected = ("a" | "b")[]; + + type Got = typeof x; + + assert>(); +} + +{ + interface A { + a: number; + b: string; + c: null; + } + + const obj: A = { + "a": 1, + "b": "ok", + "c": null, + }; + + //@ts-expect-error + const x = objectKeys(obj); +} + +{ + class A { + a: number; + b: string; + c: null; + + constructor(a: number, b: string, c: null) { + this.a = a; + this.b = b; + this.c = c; + } + } + + const obj: A = new A(1, "ok", null); + + //@ts-expect-error + const x = objectKeys(obj); +} + +{ + const obj = {}; + + const x = objectKeys(obj); + + type Expected = never[]; + + type Got = typeof x; + + assert>(); +} + +{ + const x = "ok"; + + //@ts-expect-error + const got = objectKeys(x); +} + +{ + const x = 1; + + //@ts-expect-error + const got = objectKeys(x); +} + +{ + const x = true; + + //@ts-expect-error + const got = objectKeys(x); +} diff --git a/deno_dist/test/withDefault.ts b/deno_dist/test/withDefault.ts new file mode 100644 index 0000000..3d17662 --- /dev/null +++ b/deno_dist/test/withDefault.ts @@ -0,0 +1,120 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import { withDefaults } from "../lab/withDefaults.ts"; +import { same } from "https://raw.githubusercontent.com/garronej/evt/v2.3.0/deno_dist/tools/inDepth/same.ts"; +import { assert } from "../assert.ts"; + +{ + const f = (params: { foo: string; bar: number }): string => { + const { foo, bar } = params; + return `${foo} ${bar}`; + }; + + const got = withDefaults(f, { "foo": "xxx" })({ "bar": 44 }); + + const expected = `xxx 44`; + + assert(got === expected); + + console.log("PASS TEST 1"); +} + +{ + const f = (params: { a: number; b: number }) => { + return params; + }; + + const got = withDefaults(f, { "a": 44 })({ "defaultsOverwrite": { "a": [33] }, "b": 22 }); + + const expected = { + "a": 33, + "b": 22, + }; + + assert(same(got, expected)); + + console.log("PASS TEST 2"); +} + +{ + const f = (params: { a?: number; b?: number }) => { + return params; + }; + + const got = withDefaults(f, { "a": 44 })({}); + const expected = { + "a": 44, + "b": undefined, + }; + + assert(same(got, expected)); + + console.log("PASS TEST 3"); +} + +{ + const f = (params: { a: number; b: number }) => { + const { a, b } = params; + return `${a}${b}`; + }; + + const fWd = withDefaults(f, { "a": 44 }); + + const got = fWd({ "b": 33 }) + fWd({ "b": 12 }); + + const expected = "44334412"; + + assert(got === expected); + + console.log("PASS TEST 4"); +} + +{ + const f = (params: { a: number; b: number }) => { + const { a, b } = params; + return `${a}${b}`; + }; + + const fWd = withDefaults(f, { "a": 44 }); + const got = fWd({ "defaultsOverwrite": { "a": undefined }, "b": 33 }); + const expected = "4433"; + + assert(got === expected); + + console.log("PASS TEST 5"); +} + +{ + const f = (params: { a: number | undefined; b: number }) => { + return params; + }; + + const fWd = withDefaults(f, { "a": 33 }); + + const got = fWd({ "b": 44, "defaultsOverwrite": { "a": [undefined] } }); + const expected = { + "a": undefined, + "b": 44, + }; + + assert(same(got, expected)); + + console.log("PASS TEST 6"); +} + +{ + const f = (params: { a?: number; b: number }) => { + return params; + }; + + const fWd = withDefaults(f, { "a": 33 }); + + const got = fWd({ "b": 44, "defaultsOverwrite": { "a": [undefined] } }); + const expected = { + "a": undefined, + "b": 44, + }; + + assert(same(got, expected)); + + console.log("PASS TEST 7"); +} diff --git a/deno_dist/test/withDefaults.types.ts b/deno_dist/test/withDefaults.types.ts new file mode 100644 index 0000000..d1d27d6 --- /dev/null +++ b/deno_dist/test/withDefaults.types.ts @@ -0,0 +1,108 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { assert } from "../assert.ts"; +import { withDefaults } from "../lab/withDefaults.ts"; +import type { Equals } from "../Equals.ts"; + +const x: () => T = null as any; + +//@ts-ignore +function test() { + const f: (params: { foo: T | undefined; bar: U }) => V = x(); + const got = withDefaults(f, { "foo": x() }); + + const expected: ( + params: { + bar: U; + } & { + defaultsOverwrite?: { + foo?: [T | undefined]; + }; + }, + ) => V = x(); + + assert>(); +} + +//@ts-ignore +function test() { + const f: (params: { foo: T; bar: U }) => V = x(); + const got = withDefaults(f, { "foo": x() }); + + const expected: ( + params: { + bar: U; + } & { + defaultsOverwrite?: { + foo?: [T]; + }; + }, + ) => V = x(); + + assert>(); +} + +//@ts-ignore +function test() { + const f: (params: { foo?: T; bar: U }) => V = x(); + const got = withDefaults(f, { "foo": x() }); + + const expected: ( + params: { + bar: U; + } & { + defaultsOverwrite?: { + foo?: [T | undefined]; + }; + }, + ) => V = x(); + + assert>(); +} + +//@ts-ignore +function test() { + // eslint-disable-next-line @typescript-eslint/ban-types + const f: (params: {}) => T = null as any; + + //@ts-expect-error + withDefaults(f, { "foo": null as any }); +} + +//@ts-ignore +function test() { + // eslint-disable-next-line @typescript-eslint/ban-types + const f: (params: { bar: number }) => T = null as any; + + //@ts-expect-error + withDefaults(f, { "foo": null as any }); +} + +//@ts-ignore +function test() { + // eslint-disable-next-line @typescript-eslint/ban-types + const f: (params: {}) => T = null as any; + + withDefaults(f, {}); +} + +//@ts-ignore +function test() { + // eslint-disable-next-line @typescript-eslint/ban-types + const f: (params: { foo: number; bar: string }) => T = null as any; + + //@ts-expect-error + withDefaults(f, { "foo": null as any, "baz": "" }); +} + +//@ts-ignore +function test() { + const f: (params: { a: U; b: T }) => V = x(); + + const fWd = withDefaults(f, { "a": x() }); + + //@ts-expect-error + const got = fWd({ "b": x(), "defaultsOverwrite": { "a": [undefined] } }); +} diff --git a/deno_dist/tools/Object.fromEntries.ts b/deno_dist/tools/Object.fromEntries.ts new file mode 100644 index 0000000..dd31775 --- /dev/null +++ b/deno_dist/tools/Object.fromEntries.ts @@ -0,0 +1,23 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +if (!(Object as any).fromEntries) { + Object.defineProperty(Object, "fromEntries", { + "value": function (entries: any) { + if (!entries || !entries[Symbol.iterator]) { + throw new Error("Object.fromEntries() requires a single iterable argument"); + } + + const o: any = {}; + + Object.keys(entries).forEach(key => { + const [k, v] = entries[key]; + + o[k] = v; + }); + + return o; + }, + }); +} + +export {}; diff --git a/deno_dist/tools/StrictEquals.ts b/deno_dist/tools/StrictEquals.ts new file mode 100644 index 0000000..f6b5bfd --- /dev/null +++ b/deno_dist/tools/StrictEquals.ts @@ -0,0 +1,5 @@ +export type StrictEquals = (() => A extends A2 ? true : false) extends () => A extends A1 + ? true + : false + ? true + : false; diff --git a/deno_dist/tools/Unite.ts b/deno_dist/tools/Unite.ts new file mode 100644 index 0000000..fc3014e --- /dev/null +++ b/deno_dist/tools/Unite.ts @@ -0,0 +1 @@ +export type Unite = T extends Record ? { [Key in keyof T]: T[Key] } : T; diff --git a/deno_dist/tools/getProjectRoot.ts b/deno_dist/tools/getProjectRoot.ts new file mode 100644 index 0000000..170622a --- /dev/null +++ b/deno_dist/tools/getProjectRoot.ts @@ -0,0 +1,45 @@ +const __dirname = (() => { + const { url: urlStr } = import.meta; + const url = new URL(urlStr); + const __filename = (url.protocol === "file:" ? url.pathname : urlStr) + .replace(/[/][^/]*$/, ''); + + const isWindows = (() => { + + let NATIVE_OS: typeof Deno.build.os = "linux"; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const navigator = (globalThis as any).navigator; + if (globalThis.Deno != null) { + NATIVE_OS = Deno.build.os; + } else if (navigator?.appVersion?.includes?.("Win") ?? false) { + NATIVE_OS = "windows"; + } + + return NATIVE_OS == "windows"; + + })(); + + return isWindows ? + __filename.split("/").join("\\").substring(1) : + __filename; +})(); + +import * as fs from "https://deno.land/std@0.157.0/node/fs.ts"; +import * as path from "https://deno.land/std@0.157.0/node/path.ts"; + +function getProjectRootRec(dirPath: string): string { + if (fs.existsSync(path.join(dirPath, "package.json"))) { + return dirPath; + } + return getProjectRootRec(path.join(dirPath, "..")); +} + +let result: string | undefined = undefined; + +export function getProjectRoot(): string { + if (result !== undefined) { + return result; + } + + return (result = getProjectRootRec(__dirname)); +} diff --git a/deno_dist/tools/toUpperCase.ts b/deno_dist/tools/toUpperCase.ts new file mode 100644 index 0000000..a4d5672 --- /dev/null +++ b/deno_dist/tools/toUpperCase.ts @@ -0,0 +1,3 @@ +export function toUpperCase(str: string): string { + return str.toUpperCase(); +} diff --git a/deno_dist/typeGuard.ts b/deno_dist/typeGuard.ts new file mode 100644 index 0000000..4e17714 --- /dev/null +++ b/deno_dist/typeGuard.ts @@ -0,0 +1,7 @@ +/* eslint-disable @typescript-eslint/no-namespace */ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +/** https://docs.tsafe.dev/typeguard */ +export function typeGuard(_value: any, isMatched: boolean): _value is T { + return isMatched; +} diff --git a/deno_dist/zz_internal/assertIsRefWrapper.ts b/deno_dist/zz_internal/assertIsRefWrapper.ts new file mode 100644 index 0000000..39553fc --- /dev/null +++ b/deno_dist/zz_internal/assertIsRefWrapper.ts @@ -0,0 +1,5 @@ +import { id } from "../id.ts"; + +export const assertIsRefWrapper = { + "ref": id>(undefined), +}; diff --git a/exclude.d.ts b/exclude.d.ts new file mode 100644 index 0000000..909ca29 --- /dev/null +++ b/exclude.d.ts @@ -0,0 +1,6 @@ +/** Return a function to use as Array.prototype.filter argument + * to exclude one or many primitive value element from the array. + * Ex: ([ "a", "b", "c" ] as const).filter(exclude("a")) return ("b" | "c")[] + * Ex: ([ "a", "b", "c", "d"] as const).filter(exclude(["a", "b"]) gives ("c" | "d")[] + */ +export declare function exclude(target: readonly T[] | T): (str: U) => str is Exclude; diff --git a/exclude.js b/exclude.js new file mode 100644 index 0000000..eaa1ebf --- /dev/null +++ b/exclude.js @@ -0,0 +1,19 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.exclude = void 0; +/** Return a function to use as Array.prototype.filter argument + * to exclude one or many primitive value element from the array. + * Ex: ([ "a", "b", "c" ] as const).filter(exclude("a")) return ("b" | "c")[] + * Ex: ([ "a", "b", "c", "d"] as const).filter(exclude(["a", "b"]) gives ("c" | "d")[] + */ +function exclude(target) { + var test = target instanceof Object + ? function (element) { return target.indexOf(element) < 0; } + : function (element) { return element !== target; }; + return function (str) { + return test(str); + }; +} +exports.exclude = exclude; +//# sourceMappingURL=exclude.js.map \ No newline at end of file diff --git a/exclude.js.map b/exclude.js.map new file mode 100644 index 0000000..bbc1914 --- /dev/null +++ b/exclude.js.map @@ -0,0 +1 @@ +{"version":3,"file":"exclude.js","sourceRoot":"","sources":["src/exclude.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;AAEvD;;;;GAIG;AACH,SAAgB,OAAO,CACnB,MAAwB;IAExB,IAAM,IAAI,GACN,MAAM,YAAY,MAAM;QACpB,CAAC,CAAC,UAAA,OAAO,IAAI,OAAA,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAA3B,CAA2B;QACxC,CAAC,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,KAAK,MAAM,EAAlB,CAAkB,CAAC;IAExC,OAAO,UAAa,GAAM;QACtB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC,CAAC;AACN,CAAC;AAXD,0BAWC"} \ No newline at end of file diff --git a/flip.d.ts b/flip.d.ts new file mode 100644 index 0000000..b3e1c01 --- /dev/null +++ b/flip.d.ts @@ -0,0 +1,10 @@ +declare type KeyOfType, U> = NonNullable<{ + [Key in keyof T]: T[Key] extends U | undefined ? Key : never; +}[keyof T]>; +/** + * Flip the value of a boolean without having to reference it twice + * after running flip(x.y, "z") x.y.z !== x.y.z, + * https://docs.tsafe.dev/flip + */ +export declare function flip>(object: T, prop: KeyOfType): any; +export {}; diff --git a/flip.js b/flip.js new file mode 100644 index 0000000..5d065b4 --- /dev/null +++ b/flip.js @@ -0,0 +1,17 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.flip = void 0; +/** + * Flip the value of a boolean without having to reference it twice + * after running flip(x.y, "z") x.y.z !== x.y.z, + * https://docs.tsafe.dev/flip + */ +function flip(object, prop) { + if (object[prop] === undefined) { + return; + } + return (object[prop] = !object[prop]); +} +exports.flip = flip; +//# sourceMappingURL=flip.js.map \ No newline at end of file diff --git a/flip.js.map b/flip.js.map new file mode 100644 index 0000000..5439ad2 --- /dev/null +++ b/flip.js.map @@ -0,0 +1 @@ +{"version":3,"file":"flip.js","sourceRoot":"","sources":["src/flip.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;AAQvD;;;;GAIG;AACH,SAAgB,IAAI,CAAgC,MAAS,EAAE,IAA2B;IACtF,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS,EAAE;QAC5B,OAAO;KACV;IAED,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAQ,CAAC,CAAC;AACjD,CAAC;AAND,oBAMC"} \ No newline at end of file diff --git a/id.d.ts b/id.d.ts new file mode 100644 index 0000000..d19e066 --- /dev/null +++ b/id.d.ts @@ -0,0 +1,36 @@ +/** https://docs.tsafe.dev/id */ +export declare const id: (x: T) => T; +/** + * Ensure that a that a specific type that we are declaring extends a more generic type + * + * Use case example 1: + * + * type MyObject = { + * p1: string; + * p2: string; + * a: string; + * b: string; + * }; + * + * We want to define a type that consist in an union of + * all the property name that are letters: + * + * type AlphabeticalKeys = Id; + * + * Here AlphabeticalKeys is "a" | "b" but it's better than + * simply writing it explicitly as we get autocompletion + * and we can't include a property name that does not exist on MyObject. + * + * Use case example 2: + * + * We want to declare object type that only take string or number + * as key value: + * + * export type MyObject = Id, { + * p1: string; + * p2: number; + * }>; + * + * If later on someone adds "p3": string[] he will get a type error. + * */ +export declare type Id = Specific; diff --git a/id.js b/id.js new file mode 100644 index 0000000..e4c2976 --- /dev/null +++ b/id.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.id = void 0; +/** https://docs.tsafe.dev/id */ +var id = function (x) { return x; }; +exports.id = id; +//# sourceMappingURL=id.js.map \ No newline at end of file diff --git a/id.js.map b/id.js.map new file mode 100644 index 0000000..f7f4697 --- /dev/null +++ b/id.js.map @@ -0,0 +1 @@ +{"version":3,"file":"id.js","sourceRoot":"","sources":["src/id.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAC1B,IAAM,EAAE,GAAG,UAAI,CAAI,IAAK,OAAA,CAAC,EAAD,CAAC,CAAC;AAApB,QAAA,EAAE,MAAkB"} \ No newline at end of file diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..ea23372 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,20 @@ +export * from "./assert"; +export * from "./exclude"; +export * from "./flip"; +export * from "./id"; +export * from "./isPromiseLike"; +export type { MethodNames } from "./MethodNames"; +export * from "./objectKeys"; +export type { Parameters } from "./Parameters"; +export type { Param0 } from "./Param0"; +export type { PickOptionals } from "./PickOptionals"; +export type { ReturnType } from "./ReturnType"; +export * from "./typeGuard"; +export type { UnpackPromise } from "./UnpackPromise"; +export * from "./is"; +export type { Equals } from "./Equals"; +export type { Not } from "./Not"; +export * from "./objectEntries"; +export * from "./objectFromEntries"; +export * from "./noUndefined"; +export * from "./Reflect"; diff --git a/index.js b/index.js new file mode 100644 index 0000000..18892a3 --- /dev/null +++ b/index.js @@ -0,0 +1,25 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./assert"), exports); +__exportStar(require("./exclude"), exports); +__exportStar(require("./flip"), exports); +__exportStar(require("./id"), exports); +__exportStar(require("./isPromiseLike"), exports); +__exportStar(require("./objectKeys"), exports); +__exportStar(require("./typeGuard"), exports); +__exportStar(require("./is"), exports); +__exportStar(require("./objectEntries"), exports); +__exportStar(require("./objectFromEntries"), exports); +__exportStar(require("./noUndefined"), exports); +__exportStar(require("./Reflect"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..7cccdf7 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB;AACzB,4CAA0B;AAC1B,yCAAuB;AACvB,uCAAqB;AACrB,kDAAgC;AAEhC,+CAA6B;AAK7B,8CAA4B;AAE5B,uCAAqB;AAGrB,kDAAgC;AAChC,sDAAoC;AACpC,gDAA8B;AAC9B,4CAA0B"} \ No newline at end of file diff --git a/is.d.ts b/is.d.ts new file mode 100644 index 0000000..076cac5 --- /dev/null +++ b/is.d.ts @@ -0,0 +1 @@ +export declare function is(_value: any): _value is T; diff --git a/is.js b/is.js new file mode 100644 index 0000000..0a92052 --- /dev/null +++ b/is.js @@ -0,0 +1,26 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-namespace */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.is = void 0; +var assertIsRefWrapper_1 = require("./zz_internal/assertIsRefWrapper"); +var errorMessage = [ + "Wrong usage of the " + is.name + " function refer to", + "https://docs.tsafe.dev/" + is.name.toLowerCase(), +].join(" "); +function is(_value) { + var ref = {}; + if (assertIsRefWrapper_1.assertIsRefWrapper.ref !== undefined) { + assertIsRefWrapper_1.assertIsRefWrapper.ref = undefined; + throw new Error(errorMessage); + } + assertIsRefWrapper_1.assertIsRefWrapper.ref = ref; + Promise.resolve().then(function () { + if (assertIsRefWrapper_1.assertIsRefWrapper.ref === ref) { + throw new Error(errorMessage); + } + }); + return null; +} +exports.is = is; +//# sourceMappingURL=is.js.map \ No newline at end of file diff --git a/is.js.map b/is.js.map new file mode 100644 index 0000000..c3437dc --- /dev/null +++ b/is.js.map @@ -0,0 +1 @@ +{"version":3,"file":"is.js","sourceRoot":"","sources":["src/is.ts"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,uDAAuD;;;AAEvD,uEAAsE;AAEtE,IAAM,YAAY,GAAG;IACjB,wBAAsB,EAAE,CAAC,IAAI,uBAAoB;IACjD,4BAA0B,EAAE,CAAC,IAAI,CAAC,WAAW,EAAI;CACpD,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ,SAAgB,EAAE,CAAI,MAAW;IAC7B,IAAM,GAAG,GAAG,EAAE,CAAC;IAEf,IAAI,uCAAkB,CAAC,GAAG,KAAK,SAAS,EAAE;QACtC,uCAAkB,CAAC,GAAG,GAAG,SAAS,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;KACjC;IAED,uCAAkB,CAAC,GAAG,GAAG,GAAG,CAAC;IAE7B,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;QACnB,IAAI,uCAAkB,CAAC,GAAG,KAAK,GAAG,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;SACjC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,IAAW,CAAC;AACvB,CAAC;AAjBD,gBAiBC"} \ No newline at end of file diff --git a/isPromiseLike.d.ts b/isPromiseLike.d.ts new file mode 100644 index 0000000..e881cb9 --- /dev/null +++ b/isPromiseLike.d.ts @@ -0,0 +1 @@ +export declare function isPromiseLike(o: any): o is PromiseLike; diff --git a/isPromiseLike.js b/isPromiseLike.js new file mode 100644 index 0000000..f39295a --- /dev/null +++ b/isPromiseLike.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isPromiseLike = void 0; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function isPromiseLike(o) { + return typeof (o === null || o === void 0 ? void 0 : o.then) === "function"; +} +exports.isPromiseLike = isPromiseLike; +//# sourceMappingURL=isPromiseLike.js.map \ No newline at end of file diff --git a/isPromiseLike.js.map b/isPromiseLike.js.map new file mode 100644 index 0000000..4d13d01 --- /dev/null +++ b/isPromiseLike.js.map @@ -0,0 +1 @@ +{"version":3,"file":"isPromiseLike.js","sourceRoot":"","sources":["src/isPromiseLike.ts"],"names":[],"mappings":";;;AAAA,8DAA8D;AAC9D,SAAgB,aAAa,CAAW,CAAM;IAC1C,OAAO,OAAO,CAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,IAAI,CAAA,KAAK,UAAU,CAAC;AACzC,CAAC;AAFD,sCAEC"} \ No newline at end of file diff --git a/lab/PromiseOrNot.d.ts b/lab/PromiseOrNot.d.ts new file mode 100644 index 0000000..a52de04 --- /dev/null +++ b/lab/PromiseOrNot.d.ts @@ -0,0 +1 @@ +export declare type PromiseOrNot = PromiseLike | T; diff --git a/lab/PromiseOrNot.js b/lab/PromiseOrNot.js new file mode 100644 index 0000000..206c5b9 --- /dev/null +++ b/lab/PromiseOrNot.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=PromiseOrNot.js.map \ No newline at end of file diff --git a/lab/PromiseOrNot.js.map b/lab/PromiseOrNot.js.map new file mode 100644 index 0000000..e203d42 --- /dev/null +++ b/lab/PromiseOrNot.js.map @@ -0,0 +1 @@ +{"version":3,"file":"PromiseOrNot.js","sourceRoot":"","sources":["../src/lab/PromiseOrNot.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lab/UnpackTypeGuard.d.ts b/lab/UnpackTypeGuard.d.ts new file mode 100644 index 0000000..e10df5c --- /dev/null +++ b/lab/UnpackTypeGuard.d.ts @@ -0,0 +1 @@ +export declare type UnpackTypeGuard o is unknown> = T extends (o: any) => o is infer U ? U : never; diff --git a/lab/UnpackTypeGuard.js b/lab/UnpackTypeGuard.js new file mode 100644 index 0000000..d72952f --- /dev/null +++ b/lab/UnpackTypeGuard.js @@ -0,0 +1,4 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=UnpackTypeGuard.js.map \ No newline at end of file diff --git a/lab/UnpackTypeGuard.js.map b/lab/UnpackTypeGuard.js.map new file mode 100644 index 0000000..314c53e --- /dev/null +++ b/lab/UnpackTypeGuard.js.map @@ -0,0 +1 @@ +{"version":3,"file":"UnpackTypeGuard.js","sourceRoot":"","sources":["../src/lab/UnpackTypeGuard.ts"],"names":[],"mappings":";AAAA,uDAAuD"} \ No newline at end of file diff --git a/lab/defineAccessors.d.ts b/lab/defineAccessors.d.ts new file mode 100644 index 0000000..0b07e45 --- /dev/null +++ b/lab/defineAccessors.d.ts @@ -0,0 +1,4 @@ +export declare const defineAccessors: , K extends keyof T>(obj: T, propertyName: K, propertyDescriptor: { + get?: (() => T[K]) | undefined; + set?: ((value: T[K]) => void) | undefined; +}) => void; diff --git a/lab/defineAccessors.js b/lab/defineAccessors.js new file mode 100644 index 0000000..10a67d8 --- /dev/null +++ b/lab/defineAccessors.js @@ -0,0 +1,35 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.defineAccessors = void 0; +var defineAccessors = function (obj, propertyName, propertyDescriptor) { + var get = propertyDescriptor.get, set = propertyDescriptor.set; + Object.defineProperty(obj, propertyName, __assign(__assign(__assign({}, (Object.getOwnPropertyDescriptor(obj, propertyName) || { + "enumerable": true, + "configurable": true, + })), (get !== undefined + ? { + "get": function () { + return get.call(this); + }, + } + : {})), (set !== undefined + ? { + "set": function (value) { + set.call(this, value); + }, + } + : {}))); +}; +exports.defineAccessors = defineAccessors; +//# sourceMappingURL=defineAccessors.js.map \ No newline at end of file diff --git a/lab/defineAccessors.js.map b/lab/defineAccessors.js.map new file mode 100644 index 0000000..7875dd4 --- /dev/null +++ b/lab/defineAccessors.js.map @@ -0,0 +1 @@ +{"version":3,"file":"defineAccessors.js","sourceRoot":"","sources":["../src/lab/defineAccessors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAO,IAAM,eAAe,GAAG,UAC3B,GAAM,EACN,YAAe,EACf,kBAGC;IAEO,IAAA,GAAG,GAAU,kBAAkB,IAA5B,EAAE,GAAG,GAAK,kBAAkB,IAAvB,CAAwB;IAExC,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,YAAY,iCAChC,CAAC,MAAM,CAAC,wBAAwB,CAAC,GAAG,EAAE,YAAY,CAAC,IAAI;QACtD,YAAY,EAAE,IAAI;QAClB,cAAc,EAAE,IAAI;KACvB,CAAC,GACC,CAAC,GAAG,KAAK,SAAS;QACjB,CAAC,CAAC;YACI,KAAK,EAAE;gBACH,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;SACJ;QACH,CAAC,CAAC,EAAE,CAAC,GACN,CAAC,GAAG,KAAK,SAAS;QACjB,CAAC,CAAC;YACI,KAAK,EAAE,UAAU,KAAW;gBACxB,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC1B,CAAC;SACJ;QACH,CAAC,CAAC,EAAE,CAAC,EACX,CAAC;AACP,CAAC,CAAC;AA9BW,QAAA,eAAe,mBA8B1B"} \ No newline at end of file diff --git a/lab/overwriteReadonlyProp.d.ts b/lab/overwriteReadonlyProp.d.ts new file mode 100644 index 0000000..225c2c2 --- /dev/null +++ b/lab/overwriteReadonlyProp.d.ts @@ -0,0 +1,7 @@ +/** + * Assign a value to a property even if the object is freezed or if the property is not writable + * Throw if the assignation fail ( for example if the property is non configurable write: false ) + * */ +export declare const overwriteReadonlyProp: (obj: T, propertyName: K, value: T[K]) => T[K]; diff --git a/lab/overwriteReadonlyProp.js b/lab/overwriteReadonlyProp.js new file mode 100644 index 0000000..ec430ee --- /dev/null +++ b/lab/overwriteReadonlyProp.js @@ -0,0 +1,52 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.overwriteReadonlyProp = void 0; +/* eslint-disable no-empty */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +var assert_1 = require("../assert"); +var is_1 = require("../is"); +/** + * Assign a value to a property even if the object is freezed or if the property is not writable + * Throw if the assignation fail ( for example if the property is non configurable write: false ) + * */ +var overwriteReadonlyProp = function (obj, propertyName, value) { + try { + obj[propertyName] = value; + } + catch (_a) { } + if (obj[propertyName] === value) { + return value; + } + var errorDefineProperty = undefined; + var propertyDescriptor = Object.getOwnPropertyDescriptor(obj, propertyName) || { + "enumerable": true, + "configurable": true, + }; + if (!!propertyDescriptor.get) { + throw new Error("Probably a wrong ides to overwrite " + String(propertyName) + " getter"); + } + try { + Object.defineProperty(obj, propertyName, __assign(__assign({}, propertyDescriptor), { value: value })); + } + catch (error) { + (0, assert_1.assert)((0, is_1.is)(error)); + errorDefineProperty = error; + } + if (obj[propertyName] !== value) { + throw errorDefineProperty || new Error("Can't assign"); + } + return value; +}; +exports.overwriteReadonlyProp = overwriteReadonlyProp; +//# sourceMappingURL=overwriteReadonlyProp.js.map \ No newline at end of file diff --git a/lab/overwriteReadonlyProp.js.map b/lab/overwriteReadonlyProp.js.map new file mode 100644 index 0000000..d5177da --- /dev/null +++ b/lab/overwriteReadonlyProp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"overwriteReadonlyProp.js","sourceRoot":"","sources":["../src/lab/overwriteReadonlyProp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6BAA6B;AAC7B,uDAAuD;AACvD,oCAAmC;AACnC,4BAA2B;AAE3B;;;KAGK;AACE,IAAM,qBAAqB,GAAG,UACjC,GAAM,EACN,YAAe,EACf,KAAW;IAEX,IAAI;QACA,GAAG,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;KAC7B;IAAC,WAAM,GAAE;IAEV,IAAI,GAAG,CAAC,YAAY,CAAC,KAAK,KAAK,EAAE;QAC7B,OAAO,KAAK,CAAC;KAChB;IAED,IAAI,mBAAmB,GAAsB,SAAS,CAAC;IAEvD,IAAM,kBAAkB,GAAuB,MAAM,CAAC,wBAAwB,CAC1E,GAAG,EACH,YAAY,CACf,IAAI;QACD,YAAY,EAAE,IAAI;QAClB,cAAc,EAAE,IAAI;KACvB,CAAC;IAEF,IAAI,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,wCAAsC,MAAM,CAAC,YAAY,CAAC,YAAS,CAAC,CAAC;KACxF;IAED,IAAI;QACA,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,YAAY,wBAChC,kBAAkB,KACrB,KAAK,OAAA,IACP,CAAC;KACN;IAAC,OAAO,KAAK,EAAE;QACZ,IAAA,eAAM,EAAC,IAAA,OAAE,EAAQ,KAAK,CAAC,CAAC,CAAC;QACzB,mBAAmB,GAAG,KAAK,CAAC;KAC/B;IAED,IAAI,GAAG,CAAC,YAAY,CAAC,KAAK,KAAK,EAAE;QAC7B,MAAM,mBAAmB,IAAI,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;KAC1D;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AA1CW,QAAA,qBAAqB,yBA0ChC"} \ No newline at end of file diff --git a/lab/withDefaults.d.ts b/lab/withDefaults.d.ts new file mode 100644 index 0000000..e6ec041 --- /dev/null +++ b/lab/withDefaults.d.ts @@ -0,0 +1,16 @@ +import "../tools/Object.fromEntries"; +/** + * Like Function.prototype.bind() but for a function that + * receives their parameters wrapped in an object. + * See documentation for more details: + * https://docs.tsafe.dev/withdefaults + */ +export declare function withDefaults, DefaultKey extends keyof Params, R>(f: (params: Params) => R, defaultParams: keyof Params extends never ? Record : { + [Key in DefaultKey]: Params[Key]; +}): (params: { + [Key in keyof Omit]: Params[Key]; +} & { + defaultsOverwrite?: { + [Key in DefaultKey]?: [Params[Key]]; + }; +}) => R; diff --git a/lab/withDefaults.js b/lab/withDefaults.js new file mode 100644 index 0000000..81ae1bc --- /dev/null +++ b/lab/withDefaults.js @@ -0,0 +1,66 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var __read = (this && this.__read) || function (o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.withDefaults = void 0; +/* eslint-disable @typescript-eslint/ban-ts-comment */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +require("../tools/Object.fromEntries"); +/** + * Like Function.prototype.bind() but for a function that + * receives their parameters wrapped in an object. + * See documentation for more details: + * https://docs.tsafe.dev/withdefaults + */ +function withDefaults(f, defaultParams) { + return function (params) { + var _a = params.defaultsOverwrite, defaultsOverwrite = _a === void 0 ? {} : _a, actualParams = __rest(params, ["defaultsOverwrite"]); + return f(__assign(__assign(__assign({}, defaultParams), actualParams), Object.fromEntries(Object.entries(defaultsOverwrite) + .filter(function (_a) { + var _b = __read(_a, 2), value = _b[1]; + return value !== undefined; + }) + .map(function (_a) { + var _b = __read(_a, 2), key = _b[0], value = _b[1]; + return [key, value[0]]; + })))); + }; +} +exports.withDefaults = withDefaults; +//# sourceMappingURL=withDefaults.js.map \ No newline at end of file diff --git a/lab/withDefaults.js.map b/lab/withDefaults.js.map new file mode 100644 index 0000000..4820e9a --- /dev/null +++ b/lab/withDefaults.js.map @@ -0,0 +1 @@ +{"version":3,"file":"withDefaults.js","sourceRoot":"","sources":["../src/lab/withDefaults.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,uDAAuD;AACvD,uCAAqC;AACrC;;;;;GAKG;AACH,SAAgB,YAAY,CACxB,CAAwB,EACxB,aAE0C;IAM1C,OAAO,UAAA,MAAM;QACD,IAAA,KAA4C,MAAM,kBAA5B,EAAtB,iBAAiB,mBAAG,EAAE,KAAA,EAAK,YAAY,UAAK,MAAM,EAApD,qBAA2C,CAAF,CAAY;QAE3D,OAAO,CAAC,CAAC,+BACF,aAAa,GACb,YAAY,GACZ,MAAM,CAAC,WAAW,CACjB,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;aAC5B,MAAM,CAAC,UAAC,EAAS;gBAAT,KAAA,aAAS,EAAN,KAAK,QAAA;YAAM,OAAA,KAAK,KAAK,SAAS;QAAnB,CAAmB,CAAC;aAC1C,GAAG,CAAC,UAAC,EAAY;gBAAZ,KAAA,aAAY,EAAX,GAAG,QAAA,EAAE,KAAK,QAAA;YAAM,OAAA,CAAC,GAAG,EAAG,KAAa,CAAC,CAAC,CAAC,CAAC;QAAxB,CAAwB,CAAC,CACvD,CACG,CAAC,CAAC;IACd,CAAC,CAAC;AACN,CAAC;AAvBD,oCAuBC"} \ No newline at end of file diff --git a/noUndefined.d.ts b/noUndefined.d.ts new file mode 100644 index 0000000..51e3bbc --- /dev/null +++ b/noUndefined.d.ts @@ -0,0 +1,9 @@ +/** + * Removes the enumerable properties whose values are + * undefined. + * + * Example: + * noUndefined({ "foo": undefined, "bar": 3 }) returns + * a new object { "bar": 3 } + */ +export declare function noUndefined(obj: T): T; diff --git a/noUndefined.js b/noUndefined.js new file mode 100644 index 0000000..38de3a4 --- /dev/null +++ b/noUndefined.js @@ -0,0 +1,25 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/ban-types */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.noUndefined = void 0; +/** + * Removes the enumerable properties whose values are + * undefined. + * + * Example: + * noUndefined({ "foo": undefined, "bar": 3 }) returns + * a new object { "bar": 3 } + */ +function noUndefined(obj) { + var out = {}; + for (var key in obj) { + if (obj[key] === undefined) { + continue; + } + out[key] = obj[key]; + } + return out; +} +exports.noUndefined = noUndefined; +//# sourceMappingURL=noUndefined.js.map \ No newline at end of file diff --git a/noUndefined.js.map b/noUndefined.js.map new file mode 100644 index 0000000..0cdec46 --- /dev/null +++ b/noUndefined.js.map @@ -0,0 +1 @@ +{"version":3,"file":"noUndefined.js","sourceRoot":"","sources":["src/noUndefined.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,iDAAiD;;;AAEjD;;;;;;;GAOG;AACH,SAAgB,WAAW,CAAmB,GAAM;IAChD,IAAM,GAAG,GAAe,EAAS,CAAC;IAElC,KAAK,IAAM,GAAG,IAAI,GAAG,EAAE;QACnB,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;YACxB,SAAS;SACZ;QAED,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;KACvB;IAED,OAAO,GAAG,CAAC;AACf,CAAC;AAZD,kCAYC"} \ No newline at end of file diff --git a/objectEntries.d.ts b/objectEntries.d.ts new file mode 100644 index 0000000..1f95606 --- /dev/null +++ b/objectEntries.d.ts @@ -0,0 +1,8 @@ +/** https://docs.tsafe.dev/objectentries */ +export declare function objectEntries>(o: O): { + [Key in keyof O]: [Key, O[Key]]; +}[keyof O]; +/** Return type of objectEntries https://docs.tsafe.dev/objectentries */ +export declare type ObjectEntries> = { + [Key in keyof O]: [Key, O[Key]]; +}[keyof O]; diff --git a/objectEntries.js b/objectEntries.js new file mode 100644 index 0000000..9ed95e4 --- /dev/null +++ b/objectEntries.js @@ -0,0 +1,10 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.objectEntries = void 0; +/** https://docs.tsafe.dev/objectentries */ +function objectEntries(o) { + return Object.entries(o); +} +exports.objectEntries = objectEntries; +//# sourceMappingURL=objectEntries.js.map \ No newline at end of file diff --git a/objectEntries.js.map b/objectEntries.js.map new file mode 100644 index 0000000..db776db --- /dev/null +++ b/objectEntries.js.map @@ -0,0 +1 @@ +{"version":3,"file":"objectEntries.js","sourceRoot":"","sources":["src/objectEntries.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;AAEvD,2CAA2C;AAC3C,SAAgB,aAAa,CACzB,CAAI;IAEJ,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAQ,CAAC;AACpC,CAAC;AAJD,sCAIC"} \ No newline at end of file diff --git a/objectFromEntries.d.ts b/objectFromEntries.d.ts new file mode 100644 index 0000000..209bf6c --- /dev/null +++ b/objectFromEntries.d.ts @@ -0,0 +1,8 @@ +/** https://docs.tsafe.dev/objectFromEntries */ +export declare function objectFromEntries(entries: readonly Entry[]): { + [Key in Entry[0]]: Extract[1]; +}; +/** Return type of objectFromEntries https://docs.tsafe.dev/objectFromEntries */ +export declare type ObjectFromEntries = { + [Key in Entry[0]]: Extract[1]; +}; diff --git a/objectFromEntries.js b/objectFromEntries.js new file mode 100644 index 0000000..dfd9517 --- /dev/null +++ b/objectFromEntries.js @@ -0,0 +1,10 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.objectFromEntries = void 0; +/** https://docs.tsafe.dev/objectFromEntries */ +function objectFromEntries(entries) { + return Object.fromEntries(entries); +} +exports.objectFromEntries = objectFromEntries; +//# sourceMappingURL=objectFromEntries.js.map \ No newline at end of file diff --git a/objectFromEntries.js.map b/objectFromEntries.js.map new file mode 100644 index 0000000..7067ac6 --- /dev/null +++ b/objectFromEntries.js.map @@ -0,0 +1 @@ +{"version":3,"file":"objectFromEntries.js","sourceRoot":"","sources":["src/objectFromEntries.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;AAEvD,+CAA+C;AAC/C,SAAgB,iBAAiB,CAC7B,OAAyB;IAEzB,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAQ,CAAC;AAC9C,CAAC;AAJD,8CAIC"} \ No newline at end of file diff --git a/objectKeys.d.ts b/objectKeys.d.ts new file mode 100644 index 0000000..103b048 --- /dev/null +++ b/objectKeys.d.ts @@ -0,0 +1,2 @@ +/** https://docs.tsafe.dev/objectKeys */ +export declare function objectKeys>(o: T): (keyof T)[]; diff --git a/objectKeys.js b/objectKeys.js new file mode 100644 index 0000000..3dc1c30 --- /dev/null +++ b/objectKeys.js @@ -0,0 +1,10 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.objectKeys = void 0; +/** https://docs.tsafe.dev/objectKeys */ +function objectKeys(o) { + return Object.keys(o); +} +exports.objectKeys = objectKeys; +//# sourceMappingURL=objectKeys.js.map \ No newline at end of file diff --git a/objectKeys.js.map b/objectKeys.js.map new file mode 100644 index 0000000..9d4adca --- /dev/null +++ b/objectKeys.js.map @@ -0,0 +1 @@ +{"version":3,"file":"objectKeys.js","sourceRoot":"","sources":["src/objectKeys.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;AAEvD,wCAAwC;AACxC,SAAgB,UAAU,CAAoC,CAAI;IAC9D,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAQ,CAAC;AACjC,CAAC;AAFD,gCAEC"} \ No newline at end of file diff --git a/package.json b/package.json index a0918af..0f15e2a 100755 --- a/package.json +++ b/package.json @@ -6,19 +6,8 @@ "type": "git", "url": "git://github.com/garronej/tsafe.git" }, - "main": "dist/index.js", - "types": "dist/index.d.ts", - "scripts": { - "test": "yarn test:node && yarn test:deno", - "test:deno": "deno run --reload --unstable --no-check deno_dist/test/mod.ts", - "test:node": "node dist/test/", - "build": "tsc && denoify", - "lint:check": "eslint . --ext .ts,.tsx", - "lint": "npm run lint:check -- --fix", - "_format": "prettier '**/*.{ts,tsx,json,md}'", - "format": "npm run _format -- --write", - "format:check": "npm run _format -- --list-different" - }, + "main": "index.js", + "types": "index.d.ts", "lint-staged": { "*.{ts,tsx}": [ "eslint --fix" @@ -35,11 +24,166 @@ "author": "u/garronej", "license": "MIT", "files": [ - "src/", - "!src/test/", - "dist/", - "!dist/test/", - "!dist/tsconfig.tsbuildinfo" + "src/Equals.ts", + "src/Extends.ts", + "src/MethodNames.ts", + "src/Not.ts", + "src/Param0.ts", + "src/Parameters.ts", + "src/PickOptionals.ts", + "src/PickRequired.ts", + "src/Reflect.ts", + "src/ReturnType.ts", + "src/UnpackPromise.ts", + "src/assert.ts", + "src/capitalize.ts", + "src/exclude.ts", + "src/flip.ts", + "src/id.ts", + "src/index.ts", + "src/is.ts", + "src/isPromiseLike.ts", + "src/lab/PromiseOrNot.ts", + "src/lab/UnpackTypeGuard.ts", + "src/lab/defineAccessors.ts", + "src/lab/overwriteReadonlyProp.ts", + "src/lab/withDefaults.ts", + "src/noUndefined.ts", + "src/objectEntries.ts", + "src/objectFromEntries.ts", + "src/objectKeys.ts", + "src/res/Equals_example1.ts", + "src/res/Equals_example2.ts", + "src/res/Equals_example3.ts", + "src/res/Equals_example4.ts", + "src/symToStr.ts", + "src/tools/Object.fromEntries.ts", + "src/tools/StrictEquals.ts", + "src/tools/Unite.ts", + "src/tools/getProjectRoot.ts", + "src/tools/toUpperCase.ts", + "src/typeGuard.ts", + "src/zz_internal/assertIsRefWrapper.ts", + "Equals.d.ts", + "Equals.js", + "Equals.js.map", + "Extends.d.ts", + "Extends.js", + "Extends.js.map", + "MethodNames.d.ts", + "MethodNames.js", + "MethodNames.js.map", + "Not.d.ts", + "Not.js", + "Not.js.map", + "Param0.d.ts", + "Param0.js", + "Param0.js.map", + "Parameters.d.ts", + "Parameters.js", + "Parameters.js.map", + "PickOptionals.d.ts", + "PickOptionals.js", + "PickOptionals.js.map", + "PickRequired.d.ts", + "PickRequired.js", + "PickRequired.js.map", + "Reflect.d.ts", + "Reflect.js", + "Reflect.js.map", + "ReturnType.d.ts", + "ReturnType.js", + "ReturnType.js.map", + "UnpackPromise.d.ts", + "UnpackPromise.js", + "UnpackPromise.js.map", + "assert.d.ts", + "assert.js", + "assert.js.map", + "capitalize.d.ts", + "capitalize.js", + "capitalize.js.map", + "exclude.d.ts", + "exclude.js", + "exclude.js.map", + "flip.d.ts", + "flip.js", + "flip.js.map", + "id.d.ts", + "id.js", + "id.js.map", + "index.d.ts", + "index.js", + "index.js.map", + "is.d.ts", + "is.js", + "is.js.map", + "isPromiseLike.d.ts", + "isPromiseLike.js", + "isPromiseLike.js.map", + "lab/PromiseOrNot.d.ts", + "lab/PromiseOrNot.js", + "lab/PromiseOrNot.js.map", + "lab/UnpackTypeGuard.d.ts", + "lab/UnpackTypeGuard.js", + "lab/UnpackTypeGuard.js.map", + "lab/defineAccessors.d.ts", + "lab/defineAccessors.js", + "lab/defineAccessors.js.map", + "lab/overwriteReadonlyProp.d.ts", + "lab/overwriteReadonlyProp.js", + "lab/overwriteReadonlyProp.js.map", + "lab/withDefaults.d.ts", + "lab/withDefaults.js", + "lab/withDefaults.js.map", + "noUndefined.d.ts", + "noUndefined.js", + "noUndefined.js.map", + "objectEntries.d.ts", + "objectEntries.js", + "objectEntries.js.map", + "objectFromEntries.d.ts", + "objectFromEntries.js", + "objectFromEntries.js.map", + "objectKeys.d.ts", + "objectKeys.js", + "objectKeys.js.map", + "res/Equals_example1.d.ts", + "res/Equals_example1.js", + "res/Equals_example1.js.map", + "res/Equals_example2.d.ts", + "res/Equals_example2.js", + "res/Equals_example2.js.map", + "res/Equals_example3.d.ts", + "res/Equals_example3.js", + "res/Equals_example3.js.map", + "res/Equals_example4.d.ts", + "res/Equals_example4.js", + "res/Equals_example4.js.map", + "symToStr.d.ts", + "symToStr.js", + "symToStr.js.map", + "tools/Object.fromEntries.d.ts", + "tools/Object.fromEntries.js", + "tools/Object.fromEntries.js.map", + "tools/StrictEquals.d.ts", + "tools/StrictEquals.js", + "tools/StrictEquals.js.map", + "tools/Unite.d.ts", + "tools/Unite.js", + "tools/Unite.js.map", + "tools/getProjectRoot.d.ts", + "tools/getProjectRoot.js", + "tools/getProjectRoot.js.map", + "tools/toUpperCase.d.ts", + "tools/toUpperCase.js", + "tools/toUpperCase.js.map", + "typeGuard.d.ts", + "typeGuard.js", + "typeGuard.js.map", + "zz_internal/assertIsRefWrapper.d.ts", + "zz_internal/assertIsRefWrapper.js", + "zz_internal/assertIsRefWrapper.js.map" ], "keywords": [], "homepage": "https://github.com/garronej/tsafe", diff --git a/res/Equals_example1.d.ts b/res/Equals_example1.d.ts new file mode 100644 index 0000000..e450c1a --- /dev/null +++ b/res/Equals_example1.d.ts @@ -0,0 +1,5 @@ +export declare function myFunction(params: { + foo: string; + bar: string; + baz: string; +}): void; diff --git a/res/Equals_example1.js b/res/Equals_example1.js new file mode 100644 index 0000000..6b5b557 --- /dev/null +++ b/res/Equals_example1.js @@ -0,0 +1,23 @@ +"use strict"; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.myFunction = void 0; +var assert_1 = require("../assert"); +function myFunction(params) { + var foo = params.foo, bar = params.bar, baz = params.baz, rest = __rest(params, ["foo", "bar", "baz"]); + //We check that whe have deconstructed all the parameters. + (0, assert_1.assert)(); + console.log(foo, bar, baz); +} +exports.myFunction = myFunction; +//# sourceMappingURL=Equals_example1.js.map \ No newline at end of file diff --git a/res/Equals_example1.js.map b/res/Equals_example1.js.map new file mode 100644 index 0000000..4a27e1b --- /dev/null +++ b/res/Equals_example1.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Equals_example1.js","sourceRoot":"","sources":["../src/res/Equals_example1.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,oCAAmC;AAEnC,SAAgB,UAAU,CAAC,MAAiD;IAChE,IAAA,GAAG,GAAwB,MAAM,IAA9B,EAAE,GAAG,GAAmB,MAAM,IAAzB,EAAE,GAAG,GAAc,MAAM,IAApB,EAAK,IAAI,UAAK,MAAM,EAAnC,qBAA0B,CAAF,CAAY;IAE1C,0DAA0D;IAC1D,IAAA,eAAM,GAA2B,CAAC;IAElC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC;AAPD,gCAOC"} \ No newline at end of file diff --git a/res/Equals_example2.d.ts b/res/Equals_example2.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/res/Equals_example2.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/res/Equals_example2.js b/res/Equals_example2.js new file mode 100644 index 0000000..d51b090 --- /dev/null +++ b/res/Equals_example2.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +(0, assert_1.assert)(); +//# sourceMappingURL=Equals_example2.js.map \ No newline at end of file diff --git a/res/Equals_example2.js.map b/res/Equals_example2.js.map new file mode 100644 index 0000000..298ef65 --- /dev/null +++ b/res/Equals_example2.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Equals_example2.js","sourceRoot":"","sources":["../src/res/Equals_example2.ts"],"names":[],"mappings":";;AAEA,oCAAmC;AAKnC,IAAA,eAAM,GAAgB,CAAC"} \ No newline at end of file diff --git a/res/Equals_example3.d.ts b/res/Equals_example3.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/res/Equals_example3.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/res/Equals_example3.js b/res/Equals_example3.js new file mode 100644 index 0000000..b7fa55f --- /dev/null +++ b/res/Equals_example3.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +var out = theTestedFunction(); +(0, assert_1.assert)(); +//# sourceMappingURL=Equals_example3.js.map \ No newline at end of file diff --git a/res/Equals_example3.js.map b/res/Equals_example3.js.map new file mode 100644 index 0000000..94dbe8e --- /dev/null +++ b/res/Equals_example3.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Equals_example3.js","sourceRoot":"","sources":["../src/res/Equals_example3.ts"],"names":[],"mappings":";;AAEA,oCAAmC;AAInC,IAAM,GAAG,GAAG,iBAAiB,EAAiB,CAAC;AAE/C,IAAA,eAAM,GAAoD,CAAC"} \ No newline at end of file diff --git a/res/Equals_example4.d.ts b/res/Equals_example4.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/res/Equals_example4.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/res/Equals_example4.js b/res/Equals_example4.js new file mode 100644 index 0000000..034c836 --- /dev/null +++ b/res/Equals_example4.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +//@ts-expect-error: A is not equal to B +(0, assert_1.assert)(); +(0, assert_1.assert)(); +//# sourceMappingURL=Equals_example4.js.map \ No newline at end of file diff --git a/res/Equals_example4.js.map b/res/Equals_example4.js.map new file mode 100644 index 0000000..877b344 --- /dev/null +++ b/res/Equals_example4.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Equals_example4.js","sourceRoot":"","sources":["../src/res/Equals_example4.ts"],"names":[],"mappings":";;AAEA,oCAAmC;AAKnC,uCAAuC;AACvC,IAAA,eAAM,GAAgB,CAAC;AAEvB,IAAA,eAAM,GAAqB,CAAC"} \ No newline at end of file diff --git a/symToStr.d.ts b/symToStr.d.ts new file mode 100644 index 0000000..2b817d2 --- /dev/null +++ b/symToStr.d.ts @@ -0,0 +1,2 @@ +/** @see */ +export declare function symToStr>(wrap: T): keyof T; diff --git a/symToStr.js b/symToStr.js new file mode 100644 index 0000000..ba19037 --- /dev/null +++ b/symToStr.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.symToStr = void 0; +/** @see */ +function symToStr(wrap) { + return Object.keys(wrap)[0]; +} +exports.symToStr = symToStr; +//# sourceMappingURL=symToStr.js.map \ No newline at end of file diff --git a/symToStr.js.map b/symToStr.js.map new file mode 100644 index 0000000..16feaa0 --- /dev/null +++ b/symToStr.js.map @@ -0,0 +1 @@ +{"version":3,"file":"symToStr.js","sourceRoot":"","sources":["src/symToStr.ts"],"names":[],"mappings":";;;AAAA,kDAAkD;AAClD,SAAgB,QAAQ,CAAoC,IAAO;IAC/D,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC;AAFD,4BAEC"} \ No newline at end of file diff --git a/test/Equals.d.ts b/test/Equals.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/Equals.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/Equals.js b/test/Equals.js new file mode 100644 index 0000000..ebd45b9 --- /dev/null +++ b/test/Equals.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +{ + (0, assert_1.assert)(); +} +{ + //@ts-expect-error: Because of the & + (0, assert_1.assert)(); + (0, assert_1.assert)(); +} +//# sourceMappingURL=Equals.js.map \ No newline at end of file diff --git a/test/Equals.js.map b/test/Equals.js.map new file mode 100644 index 0000000..dfa5921 --- /dev/null +++ b/test/Equals.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Equals.js","sourceRoot":"","sources":["../src/test/Equals.ts"],"names":[],"mappings":";;AACA,oCAAmC;AAgBnC;IAKI,IAAA,eAAM,GAA+B,CAAC;CACzC;AAED;IAYI,oCAAoC;IACpC,IAAA,eAAM,GAAsB,CAAC;IAE7B,IAAA,eAAM,GAAgB,CAAC;CAC1B"} \ No newline at end of file diff --git a/test/Extends.d.ts b/test/Extends.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/Extends.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/Extends.js b/test/Extends.js new file mode 100644 index 0000000..3bf9911 --- /dev/null +++ b/test/Extends.js @@ -0,0 +1,116 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +var emptyObj = {}; +function fn() { + return undefined; +} +var A = /** @class */ (function () { + function A() { + this.a = 1; + } + return A; +}()); +{ + // identity + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); +} +{ + // never extends everything + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + // nothing but itself extends never + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + // any extends nothing but itself and unknown + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + // unknown extends nothing but itself and any + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + // everything extends any + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + // everything extends unknown + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); +} +{ + // numbers + (0, assert_1.assert)(); + (0, assert_1.assert)(); +} +{ + // functions + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); +} +{ + // arrays + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); +} +{ + // objects + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); + (0, assert_1.assert)(); +} +//# sourceMappingURL=Extends.js.map \ No newline at end of file diff --git a/test/Extends.js.map b/test/Extends.js.map new file mode 100644 index 0000000..ede0f33 --- /dev/null +++ b/test/Extends.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Extends.js","sourceRoot":"","sources":["../src/test/Extends.ts"],"names":[],"mappings":";;AAGA,oCAAmC;AAEnC,IAAM,QAAQ,GAAG,EAAE,CAAC;AAQpB,SAAS,EAAE;IACP,OAAO,SAAS,CAAC;AACrB,CAAC;AAED;IAAA;QACI,MAAC,GAAG,CAAC,CAAC;IACV,CAAC;IAAD,QAAC;AAAD,CAAC,AAFD,IAEC;AAED;IACI,WAAW;IACX,IAAA,eAAM,GAAmC,CAAC;IAC1C,IAAA,eAAM,GAAuC,CAAC;IAC9C,IAAA,eAAM,GAA2C,CAAC;IAClD,IAAA,eAAM,GAAqC,CAAC;IAC5C,IAAA,eAAM,GAA+C,CAAC;IACtD,IAAA,eAAM,GAAqC,CAAC;IAC5C,IAAA,eAAM,GAA2C,CAAC;IAClD,IAAA,eAAM,GAAyC,CAAC;IAChD,IAAA,eAAM,GAAyC,CAAC;IAChD,IAAA,eAAM,GAAyC,CAAC;IAChD,IAAA,eAAM,GAAuC,CAAC;IAC9C,IAAA,eAAM,GAAiC,CAAC;IACxC,IAAA,eAAM,GAAmC,CAAC;IAC1C,IAAA,eAAM,GAA+B,CAAC;CACzC;AAED;IACI,2BAA2B;IAC3B,IAAA,eAAM,GAAuC,CAAC;IAC9C,IAAA,eAAM,GAAqC,CAAC;IAC5C,IAAA,eAAM,GAAyC,CAAC;IAChD,IAAA,eAAM,GAAmC,CAAC;IAE1C,mCAAmC;IACnC,IAAA,eAAM,GAAuC,CAAC;IAC9C,IAAA,eAAM,GAAsC,CAAC;IAC7C,IAAA,eAAM,GAA0C,CAAC;IACjD,IAAA,eAAM,GAAoC,CAAC;IAE3C,6CAA6C;IAC7C,IAAA,eAAM,GAAmC,CAAC;IAC1C,IAAA,eAAM,GAAsC,CAAC;IAC7C,IAAA,eAAM,GAAuC,CAAC;IAC9C,IAAA,eAAM,GAAkC,CAAC;IAEzC,6CAA6C;IAC7C,IAAA,eAAM,GAA2C,CAAC;IAClD,IAAA,eAAM,GAA0C,CAAC;IACjD,IAAA,eAAM,GAAuC,CAAC;IAC9C,IAAA,eAAM,GAAsC,CAAC;IAE7C,yBAAyB;IACzB,IAAA,eAAM,GAAqC,CAAC;IAC5C,IAAA,eAAM,GAAuC,CAAC;IAC9C,IAAA,eAAM,GAAiC,CAAC;IAExC,6BAA6B;IAC7B,IAAA,eAAM,GAAuC,CAAC;IAC9C,IAAA,eAAM,GAAyC,CAAC;IAChD,IAAA,eAAM,GAAqC,CAAC;CAC/C;AAED;IACI,UAAU;IACV,IAAA,eAAM,GAAoC,CAAC;IAC3C,IAAA,eAAM,GAAqC,CAAC;CAC/C;AAED;IACI,YAAY;IACZ,IAAA,eAAM,GAAwC,CAAC;IAC/C,IAAA,eAAM,GAAyC,CAAC;IAChD,IAAA,eAAM,GAAsD,CAAC;IAC7D,IAAA,eAAM,GAAwC,CAAC;IAE/C,IAAA,eAAM,GAAuC,CAAC;IAC9C,IAAA,eAAM,GAAoC,CAAC;IAC3C,IAAA,eAAM,GAAyC,CAAC;IAChD,IAAA,eAAM,GAAoC,CAAC;IAC3C,IAAA,eAAM,GAAuC,CAAC;IAC9C,IAAA,eAAM,GAAsC,CAAC;IAC7C,IAAA,eAAM,GAAsC,CAAC;IAC7C,IAAA,eAAM,GAAqC,CAAC;IAC5C,IAAA,eAAM,GAAuD,CAAC;IAC9D,IAAA,eAAM,GAAiC,CAAC;CAC3C;AAED;IACI,SAAS;IACT,IAAA,eAAM,GAAuC,CAAC;IAC9C,IAAA,eAAM,GAAiC,CAAC;IACxC,IAAA,eAAM,GAAqC,CAAC;IAC5C,IAAA,eAAM,GAAoC,CAAC;IAC3C,IAAA,eAAM,GAAqC,CAAC;IAC5C,IAAA,eAAM,GAAuC,CAAC;IAC9C,IAAA,eAAM,GAAqC,CAAC;IAE5C,IAAA,eAAM,GAAwC,CAAC;IAC/C,IAAA,eAAM,GAAyC,CAAC;IAChD,IAAA,eAAM,GAAmC,CAAC;IAC1C,IAAA,eAAM,GAAoC,CAAC;IAE3C,IAAA,eAAM,GAAoD,CAAC;IAC3D,IAAA,eAAM,GAAiD,CAAC;IACxD,IAAA,eAAM,GAAoD,CAAC;IAC3D,IAAA,eAAM,GAAqD,CAAC;IAC5D,IAAA,eAAM,GAAkD,CAAC;IACzD,IAAA,eAAM,GAAoD,CAAC;CAC9D;AAED;IACI,UAAU;IACV,IAAA,eAAM,GAAsC,CAAC;IAC7C,IAAA,eAAM,GAAuC,CAAC;IAE9C,IAAA,eAAM,GAAiD,CAAC;IACxD,IAAA,eAAM,GAAkD,CAAC;IAEzD,IAAA,eAAM,GAAqC,CAAC;IAC5C,IAAA,eAAM,GAAsC,CAAC;IAE7C,IAAA,eAAM,GAA8C,CAAC;IACrD,IAAA,eAAM,GAA6C,CAAC;IACpD,IAAA,eAAM,GAAkD,CAAC;IACzD,IAAA,eAAM,GAAmD,CAAC;CAC7D"} \ No newline at end of file diff --git a/test/MethodNames.d.ts b/test/MethodNames.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/MethodNames.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/MethodNames.js b/test/MethodNames.js new file mode 100644 index 0000000..5416fa1 --- /dev/null +++ b/test/MethodNames.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +{ + (0, assert_1.assert)(); +} +var Car = /** @class */ (function () { + function Car() { + this.foo = "caca"; + } + return Car; +}()); +{ + (0, assert_1.assert)(); +} +{ + (0, assert_1.assert)(); +} +//# sourceMappingURL=MethodNames.js.map \ No newline at end of file diff --git a/test/MethodNames.js.map b/test/MethodNames.js.map new file mode 100644 index 0000000..a34fa37 --- /dev/null +++ b/test/MethodNames.js.map @@ -0,0 +1 @@ +{"version":3,"file":"MethodNames.js","sourceRoot":"","sources":["../src/test/MethodNames.ts"],"names":[],"mappings":";;AAEA,oCAAmC;AAGnC;IAaI,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IAGI;QACI,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC;IACtB,CAAC;IACL,UAAC;AAAD,CAAC,AAND,IAMC;AAED;IAcI,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IAYI,IAAA,eAAM,GAAyB,CAAC;CACnC"} \ No newline at end of file diff --git a/test/Parameters.d.ts b/test/Parameters.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/Parameters.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/Parameters.js b/test/Parameters.js new file mode 100644 index 0000000..449de0b --- /dev/null +++ b/test/Parameters.js @@ -0,0 +1,30 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +{ + var myFunction = function (arg1, arg2, extraParams) { + return { + arg1: arg1, + arg2: arg2, + extraParams: extraParams, + }; + }; + (0, assert_1.assert)(); +} +{ + (0, assert_1.assert)(); +} +{ +} +{ + (0, assert_1.assert)(); +} +{ + var A = /** @class */ (function () { + function A(a) { + this.a = a; + } + return A; + }()); +} +//# sourceMappingURL=Parameters.js.map \ No newline at end of file diff --git a/test/Parameters.js.map b/test/Parameters.js.map new file mode 100644 index 0000000..b6811fc --- /dev/null +++ b/test/Parameters.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Parameters.js","sourceRoot":"","sources":["../src/test/Parameters.ts"],"names":[],"mappings":";;AAGA,oCAAmC;AAGnC;IACI,IAAM,UAAU,GAAG,UAAC,IAAa,EAAE,IAAY,EAAE,WAAqC;QAClF,OAAO;YACH,IAAI,MAAA;YACJ,IAAI,MAAA;YACJ,WAAW,aAAA;SACd,CAAC;IACN,CAAC,CAAC;IAKF,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IASI,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;CAGC;AAED;IAII,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IACI;QAEI,WAAY,CAAS;YACjB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;QACL,QAAC;IAAD,CAAC,AALD,IAKC;CAIJ"} \ No newline at end of file diff --git a/test/Params0.d.ts b/test/Params0.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/Params0.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/Params0.js b/test/Params0.js new file mode 100644 index 0000000..309ffe3 --- /dev/null +++ b/test/Params0.js @@ -0,0 +1,48 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +//@ts-ignore +function test() { + var f = function (params) { + return params; + }; + (0, assert_1.assert)(); +} +//@ts-ignore +function test() { + var f = function (params, a, b) { + return __assign(__assign({}, params), { a: a, b: b }); + }; + (0, assert_1.assert)(); +} +{ +} +{ + var A = /** @class */ (function () { + function A(foo) { + this.foo = foo; + } + return A; + }()); +} +{ + (0, assert_1.assert)(); +} +{ + (0, assert_1.assert)(); +} +{ + (0, assert_1.assert)(); +} +//# sourceMappingURL=Params0.js.map \ No newline at end of file diff --git a/test/Params0.js.map b/test/Params0.js.map new file mode 100644 index 0000000..7a37be2 --- /dev/null +++ b/test/Params0.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Params0.js","sourceRoot":"","sources":["../src/test/Params0.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAGA,oCAAmC;AAGnC,YAAY;AACZ,SAAS,IAAI;IACT,IAAM,CAAC,GAAG,UAAC,MAA0B;QACjC,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;IASF,IAAA,eAAM,GAAyB,CAAC;AACpC,CAAC;AAED,YAAY;AACZ,SAAS,IAAI;IACT,IAAM,CAAC,GAAG,UAAC,MAA0B,EAAE,CAAU,EAAE,CAAU;QACzD,6BACO,MAAM,KACT,CAAC,GAAA,EACD,CAAC,GAAA,IACH;IACN,CAAC,CAAC;IASF,IAAA,eAAM,GAAyB,CAAC;AACpC,CAAC;AAED;CAGC;AAED;IACI;QAGI,WAAY,GAAW;YACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACnB,CAAC;QACL,QAAC;IAAD,CAAC,AAND,IAMC;CAIJ;AAED;IAII,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IAII,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IAII,IAAA,eAAM,GAAyB,CAAC;CACnC"} \ No newline at end of file diff --git a/test/PickOptionals.d.ts b/test/PickOptionals.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/PickOptionals.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/PickOptionals.js b/test/PickOptionals.js new file mode 100644 index 0000000..6a03249 --- /dev/null +++ b/test/PickOptionals.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +{ + (0, assert_1.assert)(); +} +{ + (0, assert_1.assert)(); +} +{ +} +//# sourceMappingURL=PickOptionals.js.map \ No newline at end of file diff --git a/test/PickOptionals.js.map b/test/PickOptionals.js.map new file mode 100644 index 0000000..2a75832 --- /dev/null +++ b/test/PickOptionals.js.map @@ -0,0 +1 @@ +{"version":3,"file":"PickOptionals.js","sourceRoot":"","sources":["../src/test/PickOptionals.ts"],"names":[],"mappings":";;AAGA,oCAAmC;AAGnC;IAcI,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IAWI,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;CAUC"} \ No newline at end of file diff --git a/test/PickRequired.d.ts b/test/PickRequired.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/PickRequired.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/PickRequired.js b/test/PickRequired.js new file mode 100644 index 0000000..b263225 --- /dev/null +++ b/test/PickRequired.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +{ + (0, assert_1.assert)(); +} +{ + (0, assert_1.assert)(); +} +{ +} +//# sourceMappingURL=PickRequired.js.map \ No newline at end of file diff --git a/test/PickRequired.js.map b/test/PickRequired.js.map new file mode 100644 index 0000000..544a851 --- /dev/null +++ b/test/PickRequired.js.map @@ -0,0 +1 @@ +{"version":3,"file":"PickRequired.js","sourceRoot":"","sources":["../src/test/PickRequired.ts"],"names":[],"mappings":";;AAGA,oCAAmC;AAGnC;IAeI,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IAYI,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;CAUC"} \ No newline at end of file diff --git a/test/ReturnType.d.ts b/test/ReturnType.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/ReturnType.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/ReturnType.js b/test/ReturnType.js new file mode 100644 index 0000000..fe8a9b1 --- /dev/null +++ b/test/ReturnType.js @@ -0,0 +1,34 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +{ + var getStringAsync = null; + (0, assert_1.assert)(); +} +{ + var getString = function () { + return null; + }; + (0, assert_1.assert)(); +} +{ + var getString = null; + (0, assert_1.assert)(); +} +{ + var getString = null; + (0, assert_1.assert)(); +} +{ +} +{ +} +{ + var getString = null; + (0, assert_1.assert)(); +} +{ + var getString = null; + (0, assert_1.assert)(); +} +//# sourceMappingURL=ReturnType.js.map \ No newline at end of file diff --git a/test/ReturnType.js.map b/test/ReturnType.js.map new file mode 100644 index 0000000..0d72648 --- /dev/null +++ b/test/ReturnType.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ReturnType.js","sourceRoot":"","sources":["../src/test/ReturnType.ts"],"names":[],"mappings":";;AAIA,oCAAmC;AAGnC;IACI,IAAM,cAAc,GAA0B,IAAW,CAAC;IAK1D,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IACI,IAAM,SAAS,GAAG;QACd,OAAO,IAAW,CAAC;IACvB,CAAC,CAAC;IAKF,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IACI,IAAM,SAAS,GAA8B,IAAW,CAAC;IAKzD,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IACI,IAAM,SAAS,GAAuC,IAAW,CAAC;IAKlE,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;CAGC;AAED;CAGC;AAED;IACI,IAAM,SAAS,GAA4C,IAAW,CAAC;IAKvE,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IACI,IAAM,SAAS,GAAuC,IAAW,CAAC;IAKlE,IAAA,eAAM,GAAyB,CAAC;CACnC"} \ No newline at end of file diff --git a/test/UnpackPromise.d.ts b/test/UnpackPromise.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/UnpackPromise.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/UnpackPromise.js b/test/UnpackPromise.js new file mode 100644 index 0000000..8c63cb3 --- /dev/null +++ b/test/UnpackPromise.js @@ -0,0 +1,63 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +//@ts-ignore +function test() { + var prT = new Promise(function (resolve) { return setTimeout(resolve, 1); }); + (0, assert_1.assert)(); +} +//@ts-ignore +function test() { + var _this = this; + var f = function () { return __awaiter(_this, void 0, void 0, function () { + var out; + return __generator(this, function (_a) { + out = null; + return [2 /*return*/, out]; + }); + }); }; + var prT = f(); + (0, assert_1.assert)(); +} +{ + (0, assert_1.assert)(); +} +{ +} +//# sourceMappingURL=UnpackPromise.js.map \ No newline at end of file diff --git a/test/UnpackPromise.js.map b/test/UnpackPromise.js.map new file mode 100644 index 0000000..c4649c9 --- /dev/null +++ b/test/UnpackPromise.js.map @@ -0,0 +1 @@ +{"version":3,"file":"UnpackPromise.js","sourceRoot":"","sources":["../src/test/UnpackPromise.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oCAAmC;AAGnC,YAAY;AACZ,SAAS,IAAI;IACT,IAAM,GAAG,GAAG,IAAI,OAAO,CAAI,UAAA,OAAO,IAAI,OAAA,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,EAAtB,CAAsB,CAAC,CAAC;IAK9D,IAAA,eAAM,GAAyB,CAAC;AACpC,CAAC;AAED,YAAY;AACZ,SAAS,IAAI;IAAb,iBAYC;IAXG,IAAM,CAAC,GAAG;;;YACA,GAAG,GAAM,IAAW,CAAC;YAC3B,sBAAO,GAAG,EAAC;;SACd,CAAC;IAEF,IAAM,GAAG,GAAG,CAAC,EAAE,CAAC;IAKhB,IAAA,eAAM,GAAyB,CAAC;AACpC,CAAC;AAED;IAII,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;CAGC"} \ No newline at end of file diff --git a/test/UnpackTypeGuard.d.ts b/test/UnpackTypeGuard.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/UnpackTypeGuard.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/UnpackTypeGuard.js b/test/UnpackTypeGuard.js new file mode 100644 index 0000000..414074b --- /dev/null +++ b/test/UnpackTypeGuard.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +{ + var isFoo = function (_o) { + return null; + }; + (0, assert_1.assert)(); +} +//# sourceMappingURL=UnpackTypeGuard.js.map \ No newline at end of file diff --git a/test/UnpackTypeGuard.js.map b/test/UnpackTypeGuard.js.map new file mode 100644 index 0000000..8a26420 --- /dev/null +++ b/test/UnpackTypeGuard.js.map @@ -0,0 +1 @@ +{"version":3,"file":"UnpackTypeGuard.js","sourceRoot":"","sources":["../src/test/UnpackTypeGuard.ts"],"names":[],"mappings":";;AAEA,oCAAmC;AAGnC;IACI,IAAM,KAAK,GAAG,UAAC,EAAO;QAClB,OAAO,IAAW,CAAC;IACvB,CAAC,CAAC;IAKF,IAAA,eAAM,GAAyB,CAAC;CACnC"} \ No newline at end of file diff --git a/test/assertIs.d.ts b/test/assertIs.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/assertIs.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/assertIs.js b/test/assertIs.js new file mode 100644 index 0000000..924ccba --- /dev/null +++ b/test/assertIs.js @@ -0,0 +1,38 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +var is_1 = require("../is"); +{ + var x = null; + (0, assert_1.assert)((0, is_1.is)(x)); + (0, assert_1.assert)(); + console.log("PASS"); +} +{ + var x = null; + (0, assert_1.assert)(!(0, is_1.is)(x)); + (0, assert_1.assert)(); + console.log("PASS"); +} +{ + (0, is_1.is)(null); + try { + (0, is_1.is)(null); + throw new Error("FAIL"); + // eslint-disable-next-line no-empty + } + catch (_a) { } + console.log("PASS"); +} +scope: { + try { + (0, assert_1.assert)(undefined); + } + catch (_b) { + console.log("PASS"); + break scope; + } + throw new Error("Fail"); +} +//# sourceMappingURL=assertIs.js.map \ No newline at end of file diff --git a/test/assertIs.js.map b/test/assertIs.js.map new file mode 100644 index 0000000..504b1e2 --- /dev/null +++ b/test/assertIs.js.map @@ -0,0 +1 @@ +{"version":3,"file":"assertIs.js","sourceRoot":"","sources":["../src/test/assertIs.ts"],"names":[],"mappings":";AAAA,uDAAuD;;AAEvD,oCAAmC;AACnC,4BAA2B;AAG3B;IACI,IAAM,CAAC,GAA8B,IAAW,CAAC;IAEjD,IAAA,eAAM,EAAC,IAAA,OAAE,EAAS,CAAC,CAAC,CAAC,CAAC;IAEtB,IAAA,eAAM,GAA4B,CAAC;IAEnC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CACvB;AAED;IACI,IAAM,CAAC,GAA8B,IAAW,CAAC;IAEjD,IAAA,eAAM,EAAC,CAAC,IAAA,OAAE,EAAS,CAAC,CAAC,CAAC,CAAC;IAEvB,IAAA,eAAM,GAAsC,CAAC;IAE7C,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CACvB;AAED;IACI,IAAA,OAAE,EAAU,IAAI,CAAC,CAAC;IAElB,IAAI;QACA,IAAA,OAAE,EAAU,IAAI,CAAC,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;QACxB,oCAAoC;KACvC;IAAC,WAAM,GAAE;IAEV,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CACvB;AAED,KAAK,EAAE;IACH,IAAI;QACA,IAAA,eAAM,EAAC,SAAS,CAAC,CAAC;KACrB;IAAC,WAAM;QACJ,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAEpB,MAAM,KAAK,CAAC;KACf;IAED,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;CAC3B"} \ No newline at end of file diff --git a/test/exclude.d.ts b/test/exclude.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/exclude.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/exclude.js b/test/exclude.js new file mode 100644 index 0000000..b510d17 --- /dev/null +++ b/test/exclude.js @@ -0,0 +1,30 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var exclude_1 = require("../exclude"); +var assert_1 = require("../assert"); +var same_1 = require("evt/tools/inDepth/same"); +{ + var got = ["a", "b", "c"].filter((0, exclude_1.exclude)("a")); + var expected = ["b", "c"]; + (0, assert_1.assert)((0, same_1.same)(got, expected)); + console.log("PASS TEST 1"); +} +{ + var got = ["a", "b", "c"].filter((0, exclude_1.exclude)(["a"])); + var expected = ["b", "c"]; + (0, assert_1.assert)((0, same_1.same)(got, expected)); + console.log("PASS TEST 2"); +} +{ + var got = [1, 2, 3].filter((0, exclude_1.exclude)("foo")); + var expected = [1, 2, 3]; + (0, assert_1.assert)((0, same_1.same)(got, expected)); + console.log("PASS TEST 3"); +} +{ + var got = ["a", "b", "c", "d"].filter((0, exclude_1.exclude)(["a", "b"])); + var expected = ["c", "d"]; + (0, assert_1.assert)((0, same_1.same)(got, expected)); + console.log("PASS TEST 4"); +} +//# sourceMappingURL=exclude.js.map \ No newline at end of file diff --git a/test/exclude.js.map b/test/exclude.js.map new file mode 100644 index 0000000..af9b29b --- /dev/null +++ b/test/exclude.js.map @@ -0,0 +1 @@ +{"version":3,"file":"exclude.js","sourceRoot":"","sources":["../src/test/exclude.ts"],"names":[],"mappings":";;AAAA,sCAAqC;AACrC,oCAAmC;AACnC,+CAA8C;AAE9C;IACI,IAAM,GAAG,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAA,iBAAO,EAAC,GAAG,CAAC,CAAC,CAAC;IAEjD,IAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAE5B,IAAA,eAAM,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,GAAG,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAA,iBAAO,EAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAEnD,IAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAE5B,IAAA,eAAM,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAA,iBAAO,EAAC,KAAK,CAAC,CAAC,CAAC;IAE7C,IAAM,QAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAE3B,IAAA,eAAM,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,GAAG,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAA,iBAAO,EAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAE7D,IAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAE5B,IAAA,eAAM,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B"} \ No newline at end of file diff --git a/test/exclude.types.d.ts b/test/exclude.types.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/exclude.types.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/exclude.types.js b/test/exclude.types.js new file mode 100644 index 0000000..7a3a900 --- /dev/null +++ b/test/exclude.types.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +var exclude_1 = require("../exclude"); +var assert_1 = require("../assert"); +{ + var x = ["a", "b", "c"].filter((0, exclude_1.exclude)(["a"])); + (0, assert_1.assert)(); +} +{ + var x = ["a", "b", "c", "d"].filter((0, exclude_1.exclude)(["a", "b"])); + (0, assert_1.assert)(); +} +{ + var x = [3, "a", false].filter((0, exclude_1.exclude)([3])); + (0, assert_1.assert)(); +} +{ + //@ts-expect-error + var x = ["a", "b", "c", "d"].filter((0, exclude_1.exclude)("a", "b")); +} +//# sourceMappingURL=exclude.types.js.map \ No newline at end of file diff --git a/test/exclude.types.js.map b/test/exclude.types.js.map new file mode 100644 index 0000000..43ee170 --- /dev/null +++ b/test/exclude.types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"exclude.types.js","sourceRoot":"","sources":["../src/test/exclude.types.ts"],"names":[],"mappings":";;AAAA,sDAAsD;AACtD,sDAAsD;AACtD,sCAAqC;AACrC,oCAAmC;AAGnC;IACI,IAAM,CAAC,GAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAW,CAAC,MAAM,CAAC,IAAA,iBAAO,EAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAK5D,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IACI,IAAM,CAAC,GAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAW,CAAC,MAAM,CAAC,IAAA,iBAAO,EAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAKtE,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IACI,IAAM,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,IAAA,iBAAO,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAM/C,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IACI,kBAAkB;IAClB,IAAM,CAAC,GAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAW,CAAC,MAAM,CAAC,IAAA,iBAAO,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;CACvE"} \ No newline at end of file diff --git a/test/flip.d.ts b/test/flip.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/flip.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/flip.js b/test/flip.js new file mode 100644 index 0000000..9068442 --- /dev/null +++ b/test/flip.js @@ -0,0 +1,86 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable @typescript-eslint/no-explicit-any */ +var flip_1 = require("../flip"); +var assert_1 = require("../assert"); +{ + var obj = { + "is_": true, + "a": 1, + }; + var expected = false; + (0, flip_1.flip)(obj, "is_"); + var got = obj.is_; + (0, assert_1.assert)(got === expected); + console.log("PASS TEST 1"); +} +{ + var obj = { + "is_": true, + }; + var expected = false; + var got = (0, flip_1.flip)(obj, "is_"); + (0, assert_1.assert)(got === expected); + console.log("PASS TEST 2"); +} +{ + var obj = { + "a": { + "is_": true, + "aa": 1, + }, + }; + var expected = false; + (0, flip_1.flip)(obj.a, "is_"); + var got = obj.a.is_; + (0, assert_1.assert)(got === expected); + console.log("PASS TEST 3"); +} +{ + var obj = { + "a": 1, + "is_": true, + }; + var expected = false; + (0, flip_1.flip)(obj, "is_"); + var got = obj.is_; + (0, assert_1.assert)(got === expected); + console.log("PASS TEST 4"); +} +{ + var A = /** @class */ (function () { + function A(is_, a) { + this.is_ = is_; + this.a = a; + } + return A; + }()); + var obj = new A(true, 1); + var expected = false; + (0, flip_1.flip)(obj, "is_"); + var got = obj.is_; + (0, assert_1.assert)(got === expected); + console.log("PASS TEST 5"); +} +{ + var obj = { + "a": 1, + "is_": true, + }; + var expected = false; + (0, flip_1.flip)(obj, "is_"); + var got = obj.is_; + (0, assert_1.assert)(got === expected); + console.log("PASS TEST 6"); +} +{ + var obj = { + "a": 1, + }; + var expected = undefined; + (0, flip_1.flip)(obj, "is_"); + var got = obj.is_; + (0, assert_1.assert)(got === expected); + console.log("PASS TEST 7"); +} +//# sourceMappingURL=flip.js.map \ No newline at end of file diff --git a/test/flip.js.map b/test/flip.js.map new file mode 100644 index 0000000..6f5e4e0 --- /dev/null +++ b/test/flip.js.map @@ -0,0 +1 @@ +{"version":3,"file":"flip.js","sourceRoot":"","sources":["../src/test/flip.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,gCAA+B;AAC/B,oCAAmC;AAEnC;IACI,IAAM,GAAG,GAAG;QACR,KAAK,EAAE,IAAI;QACX,GAAG,EAAE,CAAC;KACT,CAAC;IAEF,IAAM,QAAQ,GAAG,KAAK,CAAC;IAEvB,IAAA,WAAI,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAEjB,IAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IAEpB,IAAA,eAAM,EAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,GAAG,GAAG;QACR,KAAK,EAAE,IAAI;KACd,CAAC;IAEF,IAAM,QAAQ,GAAG,KAAK,CAAC;IAEvB,IAAM,GAAG,GAAG,IAAA,WAAI,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAE7B,IAAA,eAAM,EAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,GAAG,GAAG;QACR,GAAG,EAAE;YACD,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,CAAC;SACV;KACJ,CAAC;IAEF,IAAM,QAAQ,GAAG,KAAK,CAAC;IAEvB,IAAA,WAAI,EAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAEnB,IAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAEtB,IAAA,eAAM,EAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IAMI,IAAM,GAAG,GAAM;QACX,GAAG,EAAE,CAAC;QACN,KAAK,EAAE,IAAI;KACd,CAAC;IAEF,IAAM,QAAQ,GAAG,KAAK,CAAC;IAEvB,IAAA,WAAI,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAEjB,IAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IAEpB,IAAA,eAAM,EAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI;QAII,WAAY,GAAY,EAAE,CAAS;YAC/B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;YACf,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;QACL,QAAC;IAAD,CAAC,AARD,IAQC;IAED,IAAM,GAAG,GAAG,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAE3B,IAAM,QAAQ,GAAG,KAAK,CAAC;IAEvB,IAAA,WAAI,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAEjB,IAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IAEpB,IAAA,eAAM,EAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IAMI,IAAM,GAAG,GAAM;QACX,GAAG,EAAE,CAAC;QACN,KAAK,EAAE,IAAI;KACd,CAAC;IAEF,IAAM,QAAQ,GAAG,KAAK,CAAC;IAEvB,IAAA,WAAI,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAEjB,IAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IAEpB,IAAA,eAAM,EAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IAMI,IAAM,GAAG,GAAM;QACX,GAAG,EAAE,CAAC;KACT,CAAC;IAEF,IAAM,QAAQ,GAAG,SAAS,CAAC;IAE3B,IAAA,WAAI,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAEjB,IAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IAEpB,IAAA,eAAM,EAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B"} \ No newline at end of file diff --git a/test/flip.type.d.ts b/test/flip.type.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/flip.type.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/flip.type.js b/test/flip.type.js new file mode 100644 index 0000000..2b46964 --- /dev/null +++ b/test/flip.type.js @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable @typescript-eslint/ban-ts-comment */ +var flip_1 = require("../flip"); +{ + var obj = { + "is_": true, + "a": 1, + }; + //@ts-expect-error + (0, flip_1.flip)(obj, "a"); +} +{ + var obj = { + "is_": true, + }; + //@ts-expect-error + (0, flip_1.flip)(obj, "a"); +} +//# sourceMappingURL=flip.type.js.map \ No newline at end of file diff --git a/test/flip.type.js.map b/test/flip.type.js.map new file mode 100644 index 0000000..827d8d8 --- /dev/null +++ b/test/flip.type.js.map @@ -0,0 +1 @@ +{"version":3,"file":"flip.type.js","sourceRoot":"","sources":["../src/test/flip.type.ts"],"names":[],"mappings":";;AAAA,sDAAsD;AACtD,gCAA+B;AAE/B;IACI,IAAM,GAAG,GAAG;QACR,KAAK,EAAE,IAAI;QACX,GAAG,EAAE,CAAC;KACT,CAAC;IAEF,kBAAkB;IAClB,IAAA,WAAI,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CAClB;AAED;IAMI,IAAM,GAAG,GAAM;QACX,KAAK,EAAE,IAAI;KACd,CAAC;IAEF,kBAAkB;IAClB,IAAA,WAAI,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CAClB"} \ No newline at end of file diff --git a/test/getProjectRoot.d.ts b/test/getProjectRoot.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/getProjectRoot.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/getProjectRoot.js b/test/getProjectRoot.js new file mode 100644 index 0000000..6349e76 --- /dev/null +++ b/test/getProjectRoot.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var getProjectRoot_1 = require("../tools/getProjectRoot"); +console.log("Project root path: " + (0, getProjectRoot_1.getProjectRoot)() + " does it seems right ? If yes then PASS"); +//# sourceMappingURL=getProjectRoot.js.map \ No newline at end of file diff --git a/test/getProjectRoot.js.map b/test/getProjectRoot.js.map new file mode 100644 index 0000000..aa8f344 --- /dev/null +++ b/test/getProjectRoot.js.map @@ -0,0 +1 @@ +{"version":3,"file":"getProjectRoot.js","sourceRoot":"","sources":["../src/test/getProjectRoot.ts"],"names":[],"mappings":";;AAAA,0DAAyD;AAEzD,OAAO,CAAC,GAAG,CAAC,wBAAsB,IAAA,+BAAc,GAAE,4CAAyC,CAAC,CAAC"} \ No newline at end of file diff --git a/test/id.d.ts b/test/id.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/id.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/id.js b/test/id.js new file mode 100644 index 0000000..399f8af --- /dev/null +++ b/test/id.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +var id_1 = require("../id"); +{ + (0, id_1.id)({ "type": "SQUARE", "side": 12 }); + //@ts-expect-error + (0, id_1.id)({ "type": "SQUARE", "side": 12 }); +} +//# sourceMappingURL=id.js.map \ No newline at end of file diff --git a/test/id.js.map b/test/id.js.map new file mode 100644 index 0000000..a0262e5 --- /dev/null +++ b/test/id.js.map @@ -0,0 +1 @@ +{"version":3,"file":"id.js","sourceRoot":"","sources":["../src/test/id.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,sDAAsD;AACtD,4BAA2B;AAE3B;IAWI,IAAA,OAAE,EAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IAE7C,kBAAkB;IAClB,IAAA,OAAE,EAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;CAChD"} \ No newline at end of file diff --git a/test/index.d.ts b/test/index.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..a1bf2cc --- /dev/null +++ b/test/index.js @@ -0,0 +1,142 @@ +"use strict"; +//This will not run on deno, we need a separate test runner for Deno (./mod.ts). +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __values = (this && this.__values) || function(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var child_process = __importStar(require("child_process")); +var path = __importStar(require("path")); +var Deferred_1 = require("evt/tools/Deferred"); +var names = ["withDefault", "flip", "objectKeys", "isPromiseLike", "assertIs", "exclude"]; +(function () { return __awaiter(void 0, void 0, void 0, function () { + var _loop_1, names_1, names_1_1, name_1, e_1_1; + var e_1, _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (!!process.env.FORK) { + process.once("unhandledRejection", function (error) { + throw error; + }); + require(process.env.FORK); + return [2 /*return*/]; + } + _loop_1 = function (name_1) { + var dExitCode, exitCode; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + console.log("Running: " + name_1); + dExitCode = new Deferred_1.Deferred(); + child_process + .fork(__filename, undefined, { + "env": { "FORK": path.join(__dirname, name_1) }, + }) + .on("message", console.log) + .once("exit", function (code) { return dExitCode.resolve(code !== null && code !== void 0 ? code : 1); }); + return [4 /*yield*/, dExitCode.pr]; + case 1: + exitCode = _c.sent(); + if (exitCode !== 0) { + console.log(name_1 + " exited with error code: " + exitCode); + process.exit(exitCode); + } + console.log("\n"); + return [2 /*return*/]; + } + }); + }; + _b.label = 1; + case 1: + _b.trys.push([1, 6, 7, 8]); + names_1 = __values(names), names_1_1 = names_1.next(); + _b.label = 2; + case 2: + if (!!names_1_1.done) return [3 /*break*/, 5]; + name_1 = names_1_1.value; + return [5 /*yield**/, _loop_1(name_1)]; + case 3: + _b.sent(); + _b.label = 4; + case 4: + names_1_1 = names_1.next(); + return [3 /*break*/, 2]; + case 5: return [3 /*break*/, 8]; + case 6: + e_1_1 = _b.sent(); + e_1 = { error: e_1_1 }; + return [3 /*break*/, 8]; + case 7: + try { + if (names_1_1 && !names_1_1.done && (_a = names_1.return)) _a.call(names_1); + } + finally { if (e_1) throw e_1.error; } + return [7 /*endfinally*/]; + case 8: return [2 /*return*/]; + } + }); +}); })(); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/test/index.js.map b/test/index.js.map new file mode 100644 index 0000000..06dd2e0 --- /dev/null +++ b/test/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/test/index.ts"],"names":[],"mappings":";AAAA,gFAAgF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEhF,2DAA+C;AAC/C,yCAA6B;AAC7B,+CAA8C;AAE9C,IAAM,KAAK,GAAG,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;AAE5F,CAAC;;;;;;gBACG,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE;oBACpB,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,UAAA,KAAK;wBACpC,MAAM,KAAK,CAAC;oBAChB,CAAC,CAAC,CAAC;oBAEH,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;oBAE1B,sBAAO;iBACV;oCAEU,MAAI;;;;;gCACX,OAAO,CAAC,GAAG,CAAC,cAAY,MAAM,CAAC,CAAC;gCAE1B,SAAS,GAAG,IAAI,mBAAQ,EAAU,CAAC;gCAEzC,aAAa;qCACR,IAAI,CAAC,UAAU,EAAE,SAAS,EAAE;oCACzB,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAI,CAAC,EAAE;iCAChD,CAAC;qCACD,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC;qCAC1B,IAAI,CAAC,MAAM,EAAE,UAAA,IAAI,IAAI,OAAA,SAAS,CAAC,OAAO,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,CAAC,CAAC,EAA5B,CAA4B,CAAC,CAAC;gCAEvC,qBAAM,SAAS,CAAC,EAAE,EAAA;;gCAA7B,QAAQ,GAAG,SAAkB;gCAEnC,IAAI,QAAQ,KAAK,CAAC,EAAE;oCAChB,OAAO,CAAC,GAAG,CAAI,MAAI,iCAA4B,QAAU,CAAC,CAAC;oCAC3D,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;iCAC1B;gCAED,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;;;;;;;;gBAnBH,UAAA,SAAA,KAAK,CAAA;;;;gBAAnB;8CAAM,MAAI;;;;;;;;;;;;;;;;;;;;;KAqBlB,CAAC,EAAE,CAAC"} \ No newline at end of file diff --git a/test/isPromiseLike.d.ts b/test/isPromiseLike.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/isPromiseLike.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/isPromiseLike.js b/test/isPromiseLike.js new file mode 100644 index 0000000..646c0ef --- /dev/null +++ b/test/isPromiseLike.js @@ -0,0 +1,106 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable @typescript-eslint/no-explicit-any */ +var isPromiseLike_1 = require("../isPromiseLike"); +var assert_1 = require("../assert"); +{ + var x = new Promise(function (resolve) { return setTimeout(function () { return resolve; }, 1000); }); + var got = (0, isPromiseLike_1.isPromiseLike)(x); + (0, assert_1.assert)(got === true); + console.log("PASS TEST 1"); +} +{ + var x = { + "then": function () { return null; }, + "a": 1, + "b": "foo", + "c": null, + }; + (0, assert_1.assert)((0, isPromiseLike_1.isPromiseLike)(x)); + console.log("PASS TEST 2"); +} +{ + var x = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, 1]; + }); + }); }; + (0, assert_1.assert)((0, isPromiseLike_1.isPromiseLike)(x())); + console.log("PASS TEST 3"); +} +{ + var x = function () { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, 1]; + }); + }); }; + (0, assert_1.assert)(!(0, isPromiseLike_1.isPromiseLike)(x)); + console.log("PASS TESt 4"); +} +{ + var x = { + "then": function () { return null; }, + }; + (0, assert_1.assert)((0, isPromiseLike_1.isPromiseLike)(x)); + console.log("PASS TEST 5"); +} +{ + var x = false; + (0, assert_1.assert)(!(0, isPromiseLike_1.isPromiseLike)(x)); + console.log("PASS TEST 6"); +} +{ + var X = /** @class */ (function () { + function X(then) { + this.then = then; + } + return X; + }()); + var x = new X(function () { return null; }); + (0, assert_1.assert)((0, isPromiseLike_1.isPromiseLike)(x)); + console.log("PASS TEST 7"); +} +{ + var x = { + "then": function () { return null; }, + }; + (0, assert_1.assert)((0, isPromiseLike_1.isPromiseLike)(x)); + console.log("PASS TEST 8"); +} +//# sourceMappingURL=isPromiseLike.js.map \ No newline at end of file diff --git a/test/isPromiseLike.js.map b/test/isPromiseLike.js.map new file mode 100644 index 0000000..5dae8ff --- /dev/null +++ b/test/isPromiseLike.js.map @@ -0,0 +1 @@ +{"version":3,"file":"isPromiseLike.js","sourceRoot":"","sources":["../src/test/isPromiseLike.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,kDAAiD;AACjD,oCAAmC;AAEnC;IACI,IAAM,CAAC,GAAG,IAAI,OAAO,CAAO,UAAA,OAAO,IAAI,OAAA,UAAU,CAAC,cAAM,OAAA,OAAO,EAAP,CAAO,EAAE,IAAI,CAAC,EAA/B,CAA+B,CAAC,CAAC;IAExE,IAAM,GAAG,GAAG,IAAA,6BAAa,EAAC,CAAC,CAAC,CAAC;IAE7B,IAAA,eAAM,EAAC,GAAG,KAAK,IAAI,CAAC,CAAC;IAErB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,CAAC,GAAG;QACN,MAAM,EAAE,cAAM,OAAA,IAAI,EAAJ,CAAI;QAClB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,KAAK;QACV,GAAG,EAAE,IAAI;KACZ,CAAC;IAEF,IAAA,eAAM,EAAC,IAAA,6BAAa,EAAC,CAAC,CAAC,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,CAAC,GAAG;;YACN,sBAAO,CAAC,EAAC;;SACZ,CAAC;IAEF,IAAA,eAAM,EAAC,IAAA,6BAAa,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAE3B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,CAAC,GAAG;;YACN,sBAAO,CAAC,EAAC;;SACZ,CAAC;IAEF,IAAA,eAAM,EAAC,CAAC,IAAA,6BAAa,EAAC,CAAC,CAAC,CAAC,CAAC;IAE1B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,CAAC,GAAwB;QAC3B,MAAM,EAAE,cAAM,OAAA,IAAW,EAAX,CAAW;KAC5B,CAAC;IAEF,IAAA,eAAM,EAAC,IAAA,6BAAa,EAAC,CAAC,CAAC,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,CAAC,GAAG,KAAK,CAAC;IAEhB,IAAA,eAAM,EAAC,CAAC,IAAA,6BAAa,EAAC,CAAC,CAAC,CAAC,CAAC;IAE1B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI;QAGI,WAAY,IAAgB;YACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACrB,CAAC;QACL,QAAC;IAAD,CAAC,AAND,IAMC;IAED,IAAM,CAAC,GAAG,IAAI,CAAC,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAC;IAE5B,IAAA,eAAM,EAAC,IAAA,6BAAa,EAAC,CAAC,CAAC,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IAKI,IAAM,CAAC,GAAM;QACT,MAAM,EAAE,cAAM,OAAA,IAAI,EAAJ,CAAI;KACrB,CAAC;IAEF,IAAA,eAAM,EAAC,IAAA,6BAAa,EAAC,CAAC,CAAC,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B"} \ No newline at end of file diff --git a/test/mod.d.ts b/test/mod.d.ts new file mode 100644 index 0000000..58baed9 --- /dev/null +++ b/test/mod.d.ts @@ -0,0 +1,5 @@ +import "./withDefault"; +import "./flip"; +import "./objectKeys"; +import "./isPromiseLike"; +import "./assertIs"; diff --git a/test/mod.js b/test/mod.js new file mode 100644 index 0000000..735f178 --- /dev/null +++ b/test/mod.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +require("./withDefault"); +require("./flip"); +require("./objectKeys"); +require("./isPromiseLike"); +require("./assertIs"); +//# sourceMappingURL=mod.js.map \ No newline at end of file diff --git a/test/mod.js.map b/test/mod.js.map new file mode 100644 index 0000000..54439db --- /dev/null +++ b/test/mod.js.map @@ -0,0 +1 @@ +{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/test/mod.ts"],"names":[],"mappings":";;AAAA,yBAAuB;AACvB,kBAAgB;AAChB,wBAAsB;AACtB,2BAAyB;AACzB,sBAAoB"} \ No newline at end of file diff --git a/test/objectEntries.types.d.ts b/test/objectEntries.types.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/objectEntries.types.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/objectEntries.types.js b/test/objectEntries.types.js new file mode 100644 index 0000000..eb78a97 --- /dev/null +++ b/test/objectEntries.types.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var objectEntries_1 = require("../objectEntries"); +var assert_1 = require("../assert"); +{ + var o = { + "a": "foo", + "b": 33, + "c": true, + }; + var entries = (0, objectEntries_1.objectEntries)(o); + (0, assert_1.assert)(); +} +{ + var o = { + "a": "foo", + "b": 33, + "c": true, + }; + var entries = (0, objectEntries_1.objectEntries)(o); + (0, assert_1.assert)(); +} +{ + (0, assert_1.assert)(); +} +//# sourceMappingURL=objectEntries.types.js.map \ No newline at end of file diff --git a/test/objectEntries.types.js.map b/test/objectEntries.types.js.map new file mode 100644 index 0000000..9b559a2 --- /dev/null +++ b/test/objectEntries.types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"objectEntries.types.js","sourceRoot":"","sources":["../src/test/objectEntries.types.ts"],"names":[],"mappings":";;AACA,kDAAiD;AACjD,oCAAmC;AAEnC;IACI,IAAM,CAAC,GAAG;QACN,GAAG,EAAE,KAAK;QACV,GAAG,EAAE,EAAE;QACP,GAAG,EAAE,IAAI;KACZ,CAAC;IAEF,IAAM,OAAO,GAAG,IAAA,6BAAa,EAAC,CAAC,CAAC,CAAC;IAEjC,IAAA,eAAM,GAA0E,CAAC;CACpF;AAED;IACI,IAAM,CAAC,GAAG;QACN,GAAG,EAAE,KAAK;QACV,GAAG,EAAE,EAAE;QACP,GAAG,EAAE,IAAI;KACH,CAAC;IAEX,IAAM,OAAO,GAAG,IAAA,6BAAa,EAAC,CAAC,CAAC,CAAC;IAEjC,IAAA,eAAM,GAAkE,CAAC;CAC5E;AAED;IAKI,IAAA,eAAM,GAAwC,CAAC;CAClD"} \ No newline at end of file diff --git a/test/objectFromEntries.types.d.ts b/test/objectFromEntries.types.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/objectFromEntries.types.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/objectFromEntries.types.js b/test/objectFromEntries.types.js new file mode 100644 index 0000000..90deb4c --- /dev/null +++ b/test/objectFromEntries.types.js @@ -0,0 +1,28 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var objectFromEntries_1 = require("../objectFromEntries"); +var assert_1 = require("../assert"); +var id_1 = require("../id"); +{ + var entries = [ + ["a", "foo"], + ["b", 33], + ["c", true], + ]; + var obj = (0, objectFromEntries_1.objectFromEntries)(entries); + Object.entries; + (0, assert_1.assert)(); +} +{ + var entries = [ + ["a", (0, id_1.id)("foo")], + ["b", (0, id_1.id)(33)], + ["c", (0, id_1.id)(true)], + ]; + var obj = (0, objectFromEntries_1.objectFromEntries)(entries); + (0, assert_1.assert)(); +} +{ + (0, assert_1.assert)(); +} +//# sourceMappingURL=objectFromEntries.types.js.map \ No newline at end of file diff --git a/test/objectFromEntries.types.js.map b/test/objectFromEntries.types.js.map new file mode 100644 index 0000000..6858e90 --- /dev/null +++ b/test/objectFromEntries.types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"objectFromEntries.types.js","sourceRoot":"","sources":["../src/test/objectFromEntries.types.ts"],"names":[],"mappings":";;AACA,0DAAyD;AACzD,oCAAmC;AACnC,4BAA2B;AAE3B;IACI,IAAM,OAAO,GAAG;QACZ,CAAC,GAAG,EAAE,KAAK,CAAC;QACZ,CAAC,GAAG,EAAE,EAAE,CAAC;QACT,CAAC,GAAG,EAAE,IAAI,CAAC;KACL,CAAC;IAEX,IAAM,GAAG,GAAG,IAAA,qCAAiB,EAAC,OAAO,CAAC,CAAC;IAEvC,MAAM,CAAC,OAAO,CAAC;IAEf,IAAA,eAAM,GASH,CAAC;CACP;AAED;IACI,IAAM,OAAO,GAAG;QACZ,CAAC,GAAG,EAAE,IAAA,OAAE,EAAS,KAAK,CAAC,CAAC;QACxB,CAAC,GAAG,EAAE,IAAA,OAAE,EAAS,EAAE,CAAC,CAAC;QACrB,CAAC,GAAG,EAAE,IAAA,OAAE,EAAU,IAAI,CAAC,CAAC;KAClB,CAAC;IAEX,IAAM,GAAG,GAAG,IAAA,qCAAiB,EAAC,OAAO,CAAC,CAAC;IAEvC,IAAA,eAAM,GASH,CAAC;CACP;AAED;IAKI,IAAA,eAAM,GAQH,CAAC;CACP"} \ No newline at end of file diff --git a/test/objectKeys.d.ts b/test/objectKeys.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/objectKeys.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/objectKeys.js b/test/objectKeys.js new file mode 100644 index 0000000..0a82a62 --- /dev/null +++ b/test/objectKeys.js @@ -0,0 +1,28 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var objectKeys_1 = require("../objectKeys"); +var assert_1 = require("../assert"); +var same_1 = require("evt/tools/inDepth/same"); +{ + var obj = { + "a": 1, + "b": 2, + "c": 3, + }; + var got = (0, objectKeys_1.objectKeys)(obj); + var expected = ["a", "b", "c"]; + (0, assert_1.assert)((0, same_1.same)(got, expected)); + console.log("PASS TEST 1"); +} +{ + var obj = { + "a": 1, + "b": 2, + "c": 3, + }; + var got = (0, objectKeys_1.objectKeys)(obj); + var expected = ["a", "b", "c"]; + (0, assert_1.assert)((0, same_1.same)(got, expected)); + console.log("PASS TEST 2"); +} +//# sourceMappingURL=objectKeys.js.map \ No newline at end of file diff --git a/test/objectKeys.js.map b/test/objectKeys.js.map new file mode 100644 index 0000000..f7d6451 --- /dev/null +++ b/test/objectKeys.js.map @@ -0,0 +1 @@ +{"version":3,"file":"objectKeys.js","sourceRoot":"","sources":["../src/test/objectKeys.ts"],"names":[],"mappings":";;AAAA,4CAA2C;AAC3C,oCAAmC;AACnC,+CAA8C;AAE9C;IAOI,IAAM,GAAG,GAAM;QACX,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;KACT,CAAC;IAEF,IAAM,GAAG,GAAG,IAAA,uBAAU,EAAC,GAAG,CAAC,CAAC;IAE5B,IAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAEjC,IAAA,eAAM,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,GAAG,GAAG;QACR,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;KACT,CAAC;IAEF,IAAM,GAAG,GAAG,IAAA,uBAAU,EAA2B,GAAG,CAAC,CAAC;IAEtD,IAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAEjC,IAAA,eAAM,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B"} \ No newline at end of file diff --git a/test/objectKeys.types.d.ts b/test/objectKeys.types.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/objectKeys.types.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/objectKeys.types.js b/test/objectKeys.types.js new file mode 100644 index 0000000..ae70630 --- /dev/null +++ b/test/objectKeys.types.js @@ -0,0 +1,67 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +var objectKeys_1 = require("../objectKeys"); +var assert_1 = require("../assert"); +{ + var obj = { + "a": 1, + "b": "ok", + "c": null, + }; + var x = (0, objectKeys_1.objectKeys)(obj); + (0, assert_1.assert)(); +} +{ + var obj = { + "a": 1, + "b": "ok", + "c": null, + }; + var x = (0, objectKeys_1.objectKeys)(obj); + (0, assert_1.assert)(); +} +{ + var obj = { + "a": 1, + "b": "ok", + "c": null, + }; + //@ts-expect-error + var x = (0, objectKeys_1.objectKeys)(obj); +} +{ + var A = /** @class */ (function () { + function A(a, b, c) { + this.a = a; + this.b = b; + this.c = c; + } + return A; + }()); + var obj = new A(1, "ok", null); + //@ts-expect-error + var x = (0, objectKeys_1.objectKeys)(obj); +} +{ + var obj = {}; + var x = (0, objectKeys_1.objectKeys)(obj); + (0, assert_1.assert)(); +} +{ + var x = "ok"; + //@ts-expect-error + var got = (0, objectKeys_1.objectKeys)(x); +} +{ + var x = 1; + //@ts-expect-error + var got = (0, objectKeys_1.objectKeys)(x); +} +{ + var x = true; + //@ts-expect-error + var got = (0, objectKeys_1.objectKeys)(x); +} +//# sourceMappingURL=objectKeys.types.js.map \ No newline at end of file diff --git a/test/objectKeys.types.js.map b/test/objectKeys.types.js.map new file mode 100644 index 0000000..1cdf5bd --- /dev/null +++ b/test/objectKeys.types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"objectKeys.types.js","sourceRoot":"","sources":["../src/test/objectKeys.types.ts"],"names":[],"mappings":";;AAAA,sDAAsD;AACtD,sDAAsD;AACtD,4CAA2C;AAC3C,oCAAmC;AAGnC;IACI,IAAM,GAAG,GAAG;QACR,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,IAAI;KACZ,CAAC;IAEF,IAAM,CAAC,GAAG,IAAA,uBAAU,EAAC,GAAG,CAAC,CAAC;IAM1B,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IAMI,IAAM,GAAG,GAAM;QACX,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,IAAI;KACZ,CAAC;IAEF,IAAM,CAAC,GAAG,IAAA,uBAAU,EAA2B,GAAG,CAAC,CAAC;IAMpD,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IAOI,IAAM,GAAG,GAAM;QACX,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,IAAI;KACZ,CAAC;IAEF,kBAAkB;IAClB,IAAM,CAAC,GAAG,IAAA,uBAAU,EAAC,GAAG,CAAC,CAAC;CAC7B;AAED;IACI;QAKI,WAAY,CAAS,EAAE,CAAS,EAAE,CAAO;YACrC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;QACL,QAAC;IAAD,CAAC,AAVD,IAUC;IAED,IAAM,GAAG,GAAM,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAEpC,kBAAkB;IAClB,IAAM,CAAC,GAAG,IAAA,uBAAU,EAAC,GAAG,CAAC,CAAC;CAC7B;AAED;IACI,IAAM,GAAG,GAAG,EAAE,CAAC;IAEf,IAAM,CAAC,GAAG,IAAA,uBAAU,EAAC,GAAG,CAAC,CAAC;IAM1B,IAAA,eAAM,GAAyB,CAAC;CACnC;AAED;IACI,IAAM,CAAC,GAAG,IAAI,CAAC;IAEf,kBAAkB;IAClB,IAAM,GAAG,GAAG,IAAA,uBAAU,EAAC,CAAC,CAAC,CAAC;CAC7B;AAED;IACI,IAAM,CAAC,GAAG,CAAC,CAAC;IAEZ,kBAAkB;IAClB,IAAM,GAAG,GAAG,IAAA,uBAAU,EAAC,CAAC,CAAC,CAAC;CAC7B;AAED;IACI,IAAM,CAAC,GAAG,IAAI,CAAC;IAEf,kBAAkB;IAClB,IAAM,GAAG,GAAG,IAAA,uBAAU,EAAC,CAAC,CAAC,CAAC;CAC7B"} \ No newline at end of file diff --git a/test/withDefault.d.ts b/test/withDefault.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/withDefault.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/withDefault.js b/test/withDefault.js new file mode 100644 index 0000000..798951b --- /dev/null +++ b/test/withDefault.js @@ -0,0 +1,89 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable @typescript-eslint/ban-ts-comment */ +var withDefaults_1 = require("../lab/withDefaults"); +var same_1 = require("evt/tools/inDepth/same"); +var assert_1 = require("../assert"); +{ + var f = function (params) { + var foo = params.foo, bar = params.bar; + return foo + " " + bar; + }; + var got = (0, withDefaults_1.withDefaults)(f, { "foo": "xxx" })({ "bar": 44 }); + var expected = "xxx 44"; + (0, assert_1.assert)(got === expected); + console.log("PASS TEST 1"); +} +{ + var f = function (params) { + return params; + }; + var got = (0, withDefaults_1.withDefaults)(f, { "a": 44 })({ "defaultsOverwrite": { "a": [33] }, "b": 22 }); + var expected = { + "a": 33, + "b": 22, + }; + (0, assert_1.assert)((0, same_1.same)(got, expected)); + console.log("PASS TEST 2"); +} +{ + var f = function (params) { + return params; + }; + var got = (0, withDefaults_1.withDefaults)(f, { "a": 44 })({}); + var expected = { + "a": 44, + "b": undefined, + }; + (0, assert_1.assert)((0, same_1.same)(got, expected)); + console.log("PASS TEST 3"); +} +{ + var f = function (params) { + var a = params.a, b = params.b; + return "" + a + b; + }; + var fWd = (0, withDefaults_1.withDefaults)(f, { "a": 44 }); + var got = fWd({ "b": 33 }) + fWd({ "b": 12 }); + var expected = "44334412"; + (0, assert_1.assert)(got === expected); + console.log("PASS TEST 4"); +} +{ + var f = function (params) { + var a = params.a, b = params.b; + return "" + a + b; + }; + var fWd = (0, withDefaults_1.withDefaults)(f, { "a": 44 }); + var got = fWd({ "defaultsOverwrite": { "a": undefined }, "b": 33 }); + var expected = "4433"; + (0, assert_1.assert)(got === expected); + console.log("PASS TEST 5"); +} +{ + var f = function (params) { + return params; + }; + var fWd = (0, withDefaults_1.withDefaults)(f, { "a": 33 }); + var got = fWd({ "b": 44, "defaultsOverwrite": { "a": [undefined] } }); + var expected = { + "a": undefined, + "b": 44, + }; + (0, assert_1.assert)((0, same_1.same)(got, expected)); + console.log("PASS TEST 6"); +} +{ + var f = function (params) { + return params; + }; + var fWd = (0, withDefaults_1.withDefaults)(f, { "a": 33 }); + var got = fWd({ "b": 44, "defaultsOverwrite": { "a": [undefined] } }); + var expected = { + "a": undefined, + "b": 44, + }; + (0, assert_1.assert)((0, same_1.same)(got, expected)); + console.log("PASS TEST 7"); +} +//# sourceMappingURL=withDefault.js.map \ No newline at end of file diff --git a/test/withDefault.js.map b/test/withDefault.js.map new file mode 100644 index 0000000..fd07dbb --- /dev/null +++ b/test/withDefault.js.map @@ -0,0 +1 @@ +{"version":3,"file":"withDefault.js","sourceRoot":"","sources":["../src/test/withDefault.ts"],"names":[],"mappings":";;AAAA,sDAAsD;AACtD,oDAAmD;AACnD,+CAA8C;AAC9C,oCAAmC;AAEnC;IACI,IAAM,CAAC,GAAG,UAAC,MAAoC;QACnC,IAAA,GAAG,GAAU,MAAM,IAAhB,EAAE,GAAG,GAAK,MAAM,IAAX,CAAY;QAC5B,OAAU,GAAG,SAAI,GAAK,CAAC;IAC3B,CAAC,CAAC;IAEF,IAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;IAE7D,IAAM,QAAQ,GAAG,QAAQ,CAAC;IAE1B,IAAA,eAAM,EAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,CAAC,GAAG,UAAC,MAAgC;QACvC,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;IAEF,IAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,mBAAmB,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IAE1F,IAAM,QAAQ,GAAG;QACb,GAAG,EAAE,EAAE;QACP,GAAG,EAAE,EAAE;KACV,CAAC;IAEF,IAAA,eAAM,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,CAAC,GAAG,UAAC,MAAkC;QACzC,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;IAEF,IAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7C,IAAM,QAAQ,GAAG;QACb,GAAG,EAAE,EAAE;QACP,GAAG,EAAE,SAAS;KACjB,CAAC;IAEF,IAAA,eAAM,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,CAAC,GAAG,UAAC,MAAgC;QAC/B,IAAA,CAAC,GAAQ,MAAM,EAAd,EAAE,CAAC,GAAK,MAAM,EAAX,CAAY;QACxB,OAAO,KAAG,CAAC,GAAG,CAAG,CAAC;IACtB,CAAC,CAAC;IAEF,IAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IAEzC,IAAM,GAAG,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IAEhD,IAAM,QAAQ,GAAG,UAAU,CAAC;IAE5B,IAAA,eAAM,EAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,CAAC,GAAG,UAAC,MAAgC;QAC/B,IAAA,CAAC,GAAQ,MAAM,EAAd,EAAE,CAAC,GAAK,MAAM,EAAX,CAAY;QACxB,OAAO,KAAG,CAAC,GAAG,CAAG,CAAC;IACtB,CAAC,CAAC;IAEF,IAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IACzC,IAAM,GAAG,GAAG,GAAG,CAAC,EAAE,mBAAmB,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IACtE,IAAM,QAAQ,GAAG,MAAM,CAAC;IAExB,IAAA,eAAM,EAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,CAAC,GAAG,UAAC,MAA4C;QACnD,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;IAEF,IAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IAEzC,IAAM,GAAG,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,mBAAmB,EAAE,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;IACxE,IAAM,QAAQ,GAAG;QACb,GAAG,EAAE,SAAS;QACd,GAAG,EAAE,EAAE;KACV,CAAC;IAEF,IAAA,eAAM,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED;IACI,IAAM,CAAC,GAAG,UAAC,MAAiC;QACxC,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;IAEF,IAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IAEzC,IAAM,GAAG,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,mBAAmB,EAAE,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;IACxE,IAAM,QAAQ,GAAG;QACb,GAAG,EAAE,SAAS;QACd,GAAG,EAAE,EAAE;KACV,CAAC;IAEF,IAAA,eAAM,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;CAC9B"} \ No newline at end of file diff --git a/test/withDefaults.types.d.ts b/test/withDefaults.types.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/test/withDefaults.types.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/withDefaults.types.js b/test/withDefaults.types.js new file mode 100644 index 0000000..c6614f8 --- /dev/null +++ b/test/withDefaults.types.js @@ -0,0 +1,64 @@ +"use strict"; +/* eslint-disable @typescript-eslint/ban-ts-comment */ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +var assert_1 = require("../assert"); +var withDefaults_1 = require("../lab/withDefaults"); +var x = null; +//@ts-ignore +function test() { + var f = x(); + var got = (0, withDefaults_1.withDefaults)(f, { "foo": x() }); + var expected = x(); + (0, assert_1.assert)(); +} +//@ts-ignore +function test() { + var f = x(); + var got = (0, withDefaults_1.withDefaults)(f, { "foo": x() }); + var expected = x(); + (0, assert_1.assert)(); +} +//@ts-ignore +function test() { + var f = x(); + var got = (0, withDefaults_1.withDefaults)(f, { "foo": x() }); + var expected = x(); + (0, assert_1.assert)(); +} +//@ts-ignore +function test() { + // eslint-disable-next-line @typescript-eslint/ban-types + var f = null; + //@ts-expect-error + (0, withDefaults_1.withDefaults)(f, { "foo": null }); +} +//@ts-ignore +function test() { + // eslint-disable-next-line @typescript-eslint/ban-types + var f = null; + //@ts-expect-error + (0, withDefaults_1.withDefaults)(f, { "foo": null }); +} +//@ts-ignore +function test() { + // eslint-disable-next-line @typescript-eslint/ban-types + var f = null; + (0, withDefaults_1.withDefaults)(f, {}); +} +//@ts-ignore +function test() { + // eslint-disable-next-line @typescript-eslint/ban-types + var f = null; + //@ts-expect-error + (0, withDefaults_1.withDefaults)(f, { "foo": null, "baz": "" }); +} +//@ts-ignore +function test() { + var f = x(); + var fWd = (0, withDefaults_1.withDefaults)(f, { "a": x() }); + //@ts-expect-error + var got = fWd({ "b": x(), "defaultsOverwrite": { "a": [undefined] } }); +} +//# sourceMappingURL=withDefaults.types.js.map \ No newline at end of file diff --git a/test/withDefaults.types.js.map b/test/withDefaults.types.js.map new file mode 100644 index 0000000..976b76d --- /dev/null +++ b/test/withDefaults.types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"withDefaults.types.js","sourceRoot":"","sources":["../src/test/withDefaults.types.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,sDAAsD;AACtD,uDAAuD;;AAEvD,oCAAmC;AACnC,oDAAmD;AAGnD,IAAM,CAAC,GAAe,IAAW,CAAC;AAElC,YAAY;AACZ,SAAS,IAAI;IACT,IAAM,CAAC,GAAkD,CAAC,EAAO,CAAC;IAClE,IAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAK,EAAE,CAAC,CAAC;IAE/C,IAAM,QAAQ,GAQL,CAAC,EAAO,CAAC;IAElB,IAAA,eAAM,GAAuC,CAAC;AAClD,CAAC;AAED,YAAY;AACZ,SAAS,IAAI;IACT,IAAM,CAAC,GAAsC,CAAC,EAAO,CAAC;IACtD,IAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAK,EAAE,CAAC,CAAC;IAE/C,IAAM,QAAQ,GAQL,CAAC,EAAO,CAAC;IAElB,IAAA,eAAM,GAAuC,CAAC;AAClD,CAAC;AAED,YAAY;AACZ,SAAS,IAAI;IACT,IAAM,CAAC,GAAuC,CAAC,EAAO,CAAC;IACvD,IAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAK,EAAE,CAAC,CAAC;IAE/C,IAAM,QAAQ,GAQL,CAAC,EAAO,CAAC;IAElB,IAAA,eAAM,GAAuC,CAAC;AAClD,CAAC;AAED,YAAY;AACZ,SAAS,IAAI;IACT,wDAAwD;IACxD,IAAM,CAAC,GAAsB,IAAW,CAAC;IAEzC,kBAAkB;IAClB,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,KAAK,EAAE,IAAW,EAAE,CAAC,CAAC;AAC5C,CAAC;AAED,YAAY;AACZ,SAAS,IAAI;IACT,wDAAwD;IACxD,IAAM,CAAC,GAAmC,IAAW,CAAC;IAEtD,kBAAkB;IAClB,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,KAAK,EAAE,IAAW,EAAE,CAAC,CAAC;AAC5C,CAAC;AAED,YAAY;AACZ,SAAS,IAAI;IACT,wDAAwD;IACxD,IAAM,CAAC,GAAsB,IAAW,CAAC;IAEzC,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACxB,CAAC;AAED,YAAY;AACZ,SAAS,IAAI;IACT,wDAAwD;IACxD,IAAM,CAAC,GAAgD,IAAW,CAAC;IAEnE,kBAAkB;IAClB,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,KAAK,EAAE,IAAW,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;AACvD,CAAC;AAED,YAAY;AACZ,SAAS,IAAI;IACT,IAAM,CAAC,GAAkC,CAAC,EAAO,CAAC;IAElD,IAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAO,EAAE,CAAC,CAAC;IAE/C,kBAAkB;IAClB,IAAM,GAAG,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,EAAO,EAAE,mBAAmB,EAAE,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;AAClF,CAAC"} \ No newline at end of file diff --git a/tools/Object.fromEntries.d.ts b/tools/Object.fromEntries.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tools/Object.fromEntries.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tools/Object.fromEntries.js b/tools/Object.fromEntries.js new file mode 100644 index 0000000..caf91f2 --- /dev/null +++ b/tools/Object.fromEntries.js @@ -0,0 +1,35 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +var __read = (this && this.__read) || function (o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +if (!Object.fromEntries) { + Object.defineProperty(Object, "fromEntries", { + "value": function (entries) { + if (!entries || !entries[Symbol.iterator]) { + throw new Error("Object.fromEntries() requires a single iterable argument"); + } + var o = {}; + Object.keys(entries).forEach(function (key) { + var _a = __read(entries[key], 2), k = _a[0], v = _a[1]; + o[k] = v; + }); + return o; + }, + }); +} +//# sourceMappingURL=Object.fromEntries.js.map \ No newline at end of file diff --git a/tools/Object.fromEntries.js.map b/tools/Object.fromEntries.js.map new file mode 100644 index 0000000..fe73689 --- /dev/null +++ b/tools/Object.fromEntries.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Object.fromEntries.js","sourceRoot":"","sources":["../src/tools/Object.fromEntries.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;;;;;;;;;;;;;;;;AAEvD,IAAI,CAAE,MAAc,CAAC,WAAW,EAAE;IAC9B,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE;QACzC,OAAO,EAAE,UAAU,OAAY;YAC3B,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;gBACvC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;aAC/E;YAED,IAAM,CAAC,GAAQ,EAAE,CAAC;YAElB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;gBACtB,IAAA,KAAA,OAAS,OAAO,CAAC,GAAG,CAAC,IAAA,EAApB,CAAC,QAAA,EAAE,CAAC,QAAgB,CAAC;gBAE5B,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACb,CAAC,CAAC,CAAC;YAEH,OAAO,CAAC,CAAC;QACb,CAAC;KACJ,CAAC,CAAC;CACN"} \ No newline at end of file diff --git a/tools/StrictEquals.d.ts b/tools/StrictEquals.d.ts new file mode 100644 index 0000000..95a37de --- /dev/null +++ b/tools/StrictEquals.d.ts @@ -0,0 +1 @@ +export declare type StrictEquals = (() => A extends A2 ? true : false) extends () => A extends A1 ? true : false ? true : false; diff --git a/tools/StrictEquals.js b/tools/StrictEquals.js new file mode 100644 index 0000000..1fb6ccc --- /dev/null +++ b/tools/StrictEquals.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=StrictEquals.js.map \ No newline at end of file diff --git a/tools/StrictEquals.js.map b/tools/StrictEquals.js.map new file mode 100644 index 0000000..842deab --- /dev/null +++ b/tools/StrictEquals.js.map @@ -0,0 +1 @@ +{"version":3,"file":"StrictEquals.js","sourceRoot":"","sources":["../src/tools/StrictEquals.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/tools/Unite.d.ts b/tools/Unite.d.ts new file mode 100644 index 0000000..7e52d72 --- /dev/null +++ b/tools/Unite.d.ts @@ -0,0 +1,3 @@ +export declare type Unite = T extends Record ? { + [Key in keyof T]: T[Key]; +} : T; diff --git a/tools/Unite.js b/tools/Unite.js new file mode 100644 index 0000000..85f5b5d --- /dev/null +++ b/tools/Unite.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=Unite.js.map \ No newline at end of file diff --git a/tools/Unite.js.map b/tools/Unite.js.map new file mode 100644 index 0000000..13e4c6f --- /dev/null +++ b/tools/Unite.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Unite.js","sourceRoot":"","sources":["../src/tools/Unite.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/tools/getProjectRoot.d.ts b/tools/getProjectRoot.d.ts new file mode 100644 index 0000000..7927ee7 --- /dev/null +++ b/tools/getProjectRoot.d.ts @@ -0,0 +1 @@ +export declare function getProjectRoot(): string; diff --git a/tools/getProjectRoot.js b/tools/getProjectRoot.js new file mode 100644 index 0000000..8cd6d00 --- /dev/null +++ b/tools/getProjectRoot.js @@ -0,0 +1,39 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getProjectRoot = void 0; +var fs = __importStar(require("fs")); +var path = __importStar(require("path")); +function getProjectRootRec(dirPath) { + if (fs.existsSync(path.join(dirPath, "package.json"))) { + return dirPath; + } + return getProjectRootRec(path.join(dirPath, "..")); +} +var result = undefined; +function getProjectRoot() { + if (result !== undefined) { + return result; + } + return (result = getProjectRootRec(__dirname)); +} +exports.getProjectRoot = getProjectRoot; +//# sourceMappingURL=getProjectRoot.js.map \ No newline at end of file diff --git a/tools/getProjectRoot.js.map b/tools/getProjectRoot.js.map new file mode 100644 index 0000000..36395a8 --- /dev/null +++ b/tools/getProjectRoot.js.map @@ -0,0 +1 @@ +{"version":3,"file":"getProjectRoot.js","sourceRoot":"","sources":["../src/tools/getProjectRoot.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AACzB,yCAA6B;AAE7B,SAAS,iBAAiB,CAAC,OAAe;IACtC,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,EAAE;QACnD,OAAO,OAAO,CAAC;KAClB;IACD,OAAO,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,IAAI,MAAM,GAAuB,SAAS,CAAC;AAE3C,SAAgB,cAAc;IAC1B,IAAI,MAAM,KAAK,SAAS,EAAE;QACtB,OAAO,MAAM,CAAC;KACjB;IAED,OAAO,CAAC,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC;AACnD,CAAC;AAND,wCAMC"} \ No newline at end of file diff --git a/tools/toUpperCase.d.ts b/tools/toUpperCase.d.ts new file mode 100644 index 0000000..c2dd61b --- /dev/null +++ b/tools/toUpperCase.d.ts @@ -0,0 +1 @@ +export declare function toUpperCase(str: string): string; diff --git a/tools/toUpperCase.js b/tools/toUpperCase.js new file mode 100644 index 0000000..0748db3 --- /dev/null +++ b/tools/toUpperCase.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.toUpperCase = void 0; +function toUpperCase(str) { + return str.toUpperCase(); +} +exports.toUpperCase = toUpperCase; +//# sourceMappingURL=toUpperCase.js.map \ No newline at end of file diff --git a/tools/toUpperCase.js.map b/tools/toUpperCase.js.map new file mode 100644 index 0000000..952af8d --- /dev/null +++ b/tools/toUpperCase.js.map @@ -0,0 +1 @@ +{"version":3,"file":"toUpperCase.js","sourceRoot":"","sources":["../src/tools/toUpperCase.ts"],"names":[],"mappings":";;;AAAA,SAAgB,WAAW,CAAC,GAAW;IACnC,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC;AAC7B,CAAC;AAFD,kCAEC"} \ No newline at end of file diff --git a/tsconfig.tsbuildinfo b/tsconfig.tsbuildinfo new file mode 100644 index 0000000..b277670 --- /dev/null +++ b/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"program":{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.esnext.intl.d.ts","../src/tools/Unite.ts","../src/tools/StrictEquals.ts","../src/Equals.ts","../src/Extends.ts","../src/MethodNames.ts","../src/Not.ts","../src/Parameters.ts","../src/Param0.ts","../src/PickOptionals.ts","../src/PickRequired.ts","../src/Reflect.ts","../src/ReturnType.ts","../src/UnpackPromise.ts","../src/id.ts","../src/zz_internal/assertIsRefWrapper.ts","../src/is.ts","../src/lab/overwriteReadonlyProp.ts","../src/assert.ts","../src/capitalize.ts","../src/exclude.ts","../src/flip.ts","../src/isPromiseLike.ts","../src/objectKeys.ts","../src/typeGuard.ts","../src/objectEntries.ts","../src/objectFromEntries.ts","../src/noUndefined.ts","../src/index.ts","../src/symToStr.ts","../src/lab/PromiseOrNot.ts","../src/lab/UnpackTypeGuard.ts","../src/lab/defineAccessors.ts","../src/tools/Object.fromEntries.ts","../src/lab/withDefaults.ts","../src/res/Equals_example1.ts","../src/res/Equals_example2.ts","../src/res/Equals_example3.ts","../src/res/Equals_example4.ts","../src/test/Equals.ts","../src/test/Extends.ts","../src/test/MethodNames.ts","../src/test/Parameters.ts","../src/test/Params0.ts","../src/test/PickOptionals.ts","../src/test/PickRequired.ts","../src/test/ReturnType.ts","../src/test/UnpackPromise.ts","../src/test/UnpackTypeGuard.ts","../src/test/assertIs.ts","../node_modules/minimal-polyfills/Object.is.d.ts","../node_modules/evt/tools/inDepth/same.d.ts","../src/test/exclude.ts","../src/test/exclude.types.ts","../src/test/flip.ts","../src/test/flip.type.ts","../src/tools/getProjectRoot.ts","../src/test/getProjectRoot.ts","../src/test/id.ts","../node_modules/evt/tools/Deferred.d.ts","../src/test/index.ts","../src/test/isPromiseLike.ts","../src/test/withDefault.ts","../src/test/objectKeys.ts","../src/test/mod.ts","../src/test/objectEntries.types.ts","../src/test/objectFromEntries.types.ts","../src/test/objectKeys.types.ts","../src/test/withDefaults.types.ts","../src/tools/toUpperCase.ts","../node_modules/@types/comment-json/index.d.ts","../node_modules/@types/json-schema/index.d.ts","../node_modules/@types/node/globals.d.ts","../node_modules/@types/node/async_hooks.d.ts","../node_modules/@types/node/buffer.d.ts","../node_modules/@types/node/child_process.d.ts","../node_modules/@types/node/cluster.d.ts","../node_modules/@types/node/console.d.ts","../node_modules/@types/node/constants.d.ts","../node_modules/@types/node/crypto.d.ts","../node_modules/@types/node/dgram.d.ts","../node_modules/@types/node/dns.d.ts","../node_modules/@types/node/domain.d.ts","../node_modules/@types/node/events.d.ts","../node_modules/@types/node/fs.d.ts","../node_modules/@types/node/http.d.ts","../node_modules/@types/node/http2.d.ts","../node_modules/@types/node/https.d.ts","../node_modules/@types/node/inspector.d.ts","../node_modules/@types/node/module.d.ts","../node_modules/@types/node/net.d.ts","../node_modules/@types/node/os.d.ts","../node_modules/@types/node/path.d.ts","../node_modules/@types/node/perf_hooks.d.ts","../node_modules/@types/node/process.d.ts","../node_modules/@types/node/punycode.d.ts","../node_modules/@types/node/querystring.d.ts","../node_modules/@types/node/readline.d.ts","../node_modules/@types/node/repl.d.ts","../node_modules/@types/node/stream.d.ts","../node_modules/@types/node/string_decoder.d.ts","../node_modules/@types/node/timers.d.ts","../node_modules/@types/node/tls.d.ts","../node_modules/@types/node/trace_events.d.ts","../node_modules/@types/node/tty.d.ts","../node_modules/@types/node/url.d.ts","../node_modules/@types/node/util.d.ts","../node_modules/@types/node/v8.d.ts","../node_modules/@types/node/vm.d.ts","../node_modules/@types/node/worker_threads.d.ts","../node_modules/@types/node/zlib.d.ts","../node_modules/@types/node/ts3.6/base.d.ts","../node_modules/@types/node/assert.d.ts","../node_modules/@types/node/base.d.ts","../node_modules/@types/node/index.d.ts","../node_modules/@types/parse-json/index.d.ts"],"fileInfos":[{"version":"aa9fb4c70f369237c2f45f9d969c9a59e0eae9a192962eb48581fe864aa609db","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06",{"version":"e54c8715a4954cfdc66cd69489f2b725c09ebf37492dbd91cff0a1688b1159e8","affectsGlobalScope":true},{"version":"51b8b27c21c066bf877646e320bf6a722b80d1ade65e686923cd9d4494aef1ca","affectsGlobalScope":true},{"version":"43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"2c8c5ee58f30e7c944e04ab1fb5506fdbb4dd507c9efa6972cf4b91cec90c503","affectsGlobalScope":true},{"version":"2bb4b3927299434052b37851a47bf5c39764f2ba88a888a107b32262e9292b7c","affectsGlobalScope":true},{"version":"810627a82ac06fb5166da5ada4159c4ec11978dfbb0805fe804c86406dab8357","affectsGlobalScope":true},{"version":"62d80405c46c3f4c527ee657ae9d43fda65a0bf582292429aea1e69144a522a6","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"df9c8a72ca8b0ed62f5470b41208a0587f0f73f0a7db28e5a1272cf92537518e","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"1b3fe904465430e030c93239a348f05e1be80640d91f2f004c3512c2c2c89f34","affectsGlobalScope":true},{"version":"4632665b87204bb1caa8b44d165bce0c50dfab177df5b561b345a567cabacf9a","affectsGlobalScope":true},"f6b19500d5de61452d537a4a495cfae224ff97de8b2afa9b156a14e261d9dc45","cee511e986619497af00106cfc033afa9cb907657eae7d216aa6685cfd91a7e4","110591d5497e1331afc9009322bce3fcd623d16ae896a989a450b303a6757f80","29e96dc0ba04e36087401b99fef170b27a23f2eee22d1b9b665282651a2f398c","a98f362ec9d130a8fee0ebe21a7ea2fcaef9fe9c8d49e228099a6e5bb1dc75b6","02da4f252835cd9cdc1049dc4f27a336f44fc3fb2b587e340d03de45a48830e4","ed39a06fcdec4146b81408cbeccb66829034033a05221ea6892177709c472abc","e841acd707c314fdbfc5cad43ed30b9ec19f0833447b0381c138009bfe2d794a","be2476a98a660ac0c6b14cb1bd09285f5d21e0fe5ba12b25adc2443db93421ce","454fa710bcf4ac32638e96b0c467e1344165c927d221733aa2e77037b3539078","aa2712d356ed12a0c72a7f154d0160ecab56f06da86c21540b2645c90f7248d7","ea83c0ddd554616cfbede4b11b59910f4fc93f8c8001dea25f7837f74fcf3cc7","37d5e328dceac953061ae95f6615f7ae4037f6ca53551c0fd246098e1142fe29","cb2b74bfed19553b90e37af353c58c53ee113af1406c580ab0b7a4b44aa9b022","f3af5f1e28a1bbdc6473af7d97fe8bd9981da9d5502e29e3ef0caba6d78c0286","f9dc8e82e88e8bf771edc42784f27e283266b81a1d4de21e5b83b209cec0e5eb","b3603893739a2eb1d0dbee833a63f9c16c04eb470ed4824f08c94d5c20c4b8d2","b23ca4d1c491666be207051641f719cfe0d9e9e0514f1c42ddf0fc48c346c7c8","9732a6f8fc1811d8a5e0a75f20ffe08f6f41e7019f71eab3f357caa25e164bd5","1731efeaa2199fbec2d277f13cd6876a0404eb34556bb615c3801d6915972b33","cfa42eee23927d15b60d467db75d4c9c48b1d08b3d6511e6386ff77e42f0ee40","e190c6b9806e815d3a096c9af16028a848edd13b70b6e3d9e44ce2507089f17a","2d04d4da6d9c7afae2559a9598ccebb3d1d4fd6b0b420cf7ca8f3c9f20c9a858","8012ea9591da5ff83fa43d1a42c9911736b0f841726bc88a07deb53ae717f41b","d16ed9788c5229cd742ba4cbfb8e54657c66657375e8a3ad1710e36d3f328fbb","b0e20c5407a5e79d50bb90a9b445f4889c7ef562438db770b395515170e9b5e9","112299f77f951fe6b8eb50821334f6aebcf574b5b7d89e2431b91fe1df55c7ab","09cc226b6b864164cbb1665a3d2f1185532dbf59333daa6bbdbd21f99915380e","473fa81dbb0ed81faf43b694897693537760cb2914c4c4716064b4eff0751d66","ab46309b639fb01d162488e25afc36bf4a8da3ab37f09a6dc70c733a5b9829ba","2f43d2ff5bc86c1612b2b8cc88095688d51107539a77c67a7d132814d482c06c","94e8eae7586e7b256cb3a0e266a0fb71d5307c542243963fad5f52c91ac40aa8","e260d3a5275e3b54fa5373f48ea39b3b4c876bbecfa09b0dc19d5dce2d311a2e","62e1bf47389b38255f5b77d5548e6983ee192a1bb2254bcd6c0333fc2ef13c34","c11b00aec2623a6ed840263042ee215ef75f652be7ca6e0cd54d818f19a6f902","1c96425529c6b2a466136cbcc023ccd37a226223df48ef96b60bb95ed8390acd","6f3ddd3225363db253634fbbcaf19aa01b84f4e3396b13fd277e003f7368c7f8","3ef72031c6fd8015034022fe73481112f5ae82adcd8a0874c752f9149e25d076","48932b2f414810c7f777d7243f8ec71de008c2eaa8fb0772acaebeddbee9faa7","4d4e2da4f4d948527f18307c13c045ef4aed8458e5947b24e8a68000552b9f23","8148e643aa695f617428a04332050a8a9d9d775489f057a1f31bea0b60519b6e","4c3dda5bda8473ef884047618fdbd10538bcf7bb348f1e8b3b1d3ece2bfb9567","98a67a7a585ee4be6c39fce190e7c8292cd98529bf623ac44edf6824b16f6b67","fb1410bf806be4356858f0f0cbd184746a4103bcd1693c88be6f17fc05601372","e0b5a2c0cc9aa809d08327e7643c7214cfa64a113cca1083b192046a0bc68031","e313fb7dd26f125ad04082d589c0db02db11ab8889e8856d31c116b8b2984eee","cf2483c1962c5e8612cd0d923511114042cac3489890a0e00b914ec192e3d42b","ac5f91a2718247ac42476c0e5f34f748788205cde9892196dd47fe87c7ea78bb","e874419687c48b604f85e37b46249c3c1371884fee4db62769cffe6584b63be0","8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881","7e062925029f9b753515d9f6e0169e0cecc986925ffe8702bf0f0d141b2dde90","cfff4a868c4616e4b2b5dbc85a561cdeb847af9e17920776f84148af62b7f58f","801e79902cd3198f596daafef0cd07b37916c834d71e3dc0978c83b484875285","854bc45a2e4885ab9eac4ebdab2980ed1a61318465e86b2e9790d63eecdab7b4","40fb5e86ac61631d96d5ea8b0180a4c8780c801a675fe6e3916f6a216896e798","3e6239b7b45d4c78f745b459e3a8493af4be6a5fc078cbc6c471d5db77902a06","b68345c83adff2fb505ed5a627a4d7205be489277ff55a339bf3a60f319bd23f","24f06773909f32ae226ec3ec00f714b6b2cb1904af70f02a4203c3d9fbf15ba9","fc633779ce49c0ea733d4a282d99462bb6c672c37db33584bafe130e792d55d6","40132ea40ba8ee9c99225323d53f269c860b5b24c92a6a677a03c46596f338ba","7cfd6eb508986e0f29e36459fac92d6a6a8f205fe10e4d72c14aafb997065a46","e5200571f6b4f1f064d76510fd11d1b010cc37e01bbc344d69876cc6117d274f","d474c029d8749bdcf9a3cc0d5344affb5c4c8a07d28dbc6b555e04d4b56aba3e","c4556181a264480a8a08eb14f3c1883489000a65b243e7dd1e13e704b02bb3b2","c58143aec525866f3fbc551a7bf3eb1930b4a0e7841de35f1542057df47d4970","141f9489fd2efc5d27a2356704a55fd650c535de852f111eb3fc730f6c08c5b3","50475ed08c3945a4a7d6bf19cb7227fc6c136f5944b393d8392af2b6b517f237","717733d1ec283448981592c7b692295662ce5540ade5f82a6df3d1ecba6bb2e6","0f2ac3e73064d6a8ec7f3ef8c726ecc9bd2cc34045cf18b2ec8142790d75bbe7","c401118ea6c6daa9f196013b0622c602d4faec565bb1cc6ca751d2a8fc295498","0359682c54e487c4cab2b53b2b4d35cc8dea4d9914bc6abcdb5701f8b8e745a4",{"version":"fb928b21f5a16a1d64a8e2e74a3f389ace89da74820f070f893221213c50aa3c","affectsGlobalScope":true},"5cd9c902b221c5aca739cbc3fb4339c3c5115198808d4f5d7610a674e4b9c66d","fe892fea1e75a442fffb4a604d7eeb451e858787a9f2f01c4e83bf12a3b5048d","d5c80b931928fbd06f967ce4bdca24fbb37523773ac2c7c87458a689154351fb","fcd718b2feb2820a9844536a1a2fbc77a3da90820e02894d40f879a789f46560","525c8fc510d9632d2a0a9de2d41c3ac1cdd79ff44d3b45c6d81cacabb683528d","ece75b9bfc916f9ccc4e8a9ddee1dda5c987804fbe3b60a01fc120fae731c2ce","4e146a0b69c893ae1538aff8b76f4e8796755bdd45050a83099348d59863437e","a1dc9cfe8be39cbcef62692510b450ab35553ef39382715c88763d0c477704a9","05e732266b5a36789fd9eb846b1f45fec1b6e318b740e3f20fc22fd95f9ebf31","985c3d1b62a4a4f563e3ca3e3a47717cff7d82c81883d62ecf08d8417eb477c4","8059976d7f408e08be353de1833172139bbaa70fc33d01b98249f7226c122119","1733741cf2adc5926ac58c66004268cdc3d34b2ff6250f5114db14253ea02ce1","df18df925483862e8ff216d7b17e50b7311a3add2fb7feb128d321ec099352ca","b6b09f944889a23f19eba6e0f112030e55160c5e1a225012ab2349c582ba5595","152af7c23ec219f632afa2d861abc65993f56cd39a4f3a4018515dbc05950a74","3a0bdc4c5b6f84a1abb5356d7a7fa1f96ac6c5b5646eec3ef2b33c1ed095e155","03394bf8deb8781b490ae9266a843fbdf00647947d79e25fcbf1d89a9e9c8a66","56a15cc211894d79aa44cbb46c276bfd3f10458a61bff2dec99114db8a7e71e3","1a5366b0d4d0153955fd85777c72d35979dabc0537649da6eade09007c0d080a","61c84c3b0eb6e60196d15ae5e21793a1d4241c547f0bdd0529ffae838d1a073c","272522db288a7e03f14ff930407b776357082efce20369ea42239a57af9c7f81","3a8848a9c307429b861402cc69bc472ffe0c05b86474fc158723169161e16389","3f6a1fd73c9dc3bd7f4b79bc075297ca6527904df69b0f2c2c94e4c4c7d9a32c","8969e0b4d22ca77ad011c8fc4a25ec5d515bdfae4ecbd22608ed0d5c38829c1e","b2fe368abdc803b82d27bd27f168d106804422ade198c3c085e2519b195ebd26","93acebcaa2e94903a83cebf3f109eb2917acab902045ee8c3d8f69f29baafa68","8e2f9031210a8fc27af8844bf69f964307d6013c90336bea9fb5d6ba43248c78","17e157df6125098a1a34eb4d201ee4ac03bbe97e471ab5627bb2c40fce555948","b40652bf8ce4a18133b31349086523b219724dca8df3448c1a0742528e7ad5b9","4bdb7b15b3f9a3ee0b856c7b991d0e522f8ce92f7b66ae8ac00e61d1269dd10a","978aecd2e6bc2ac094e9a35eda98ff8586713857b3655e7c98ca5ed8f7d50662","a185b8e0d7a4ae078a79339d63e98177813aac39256f69f788eaf5c360aa756f","c6b71a0585467900820167370738cfc256e9635471725a7ba1d24a3a262984e5","8bf10278b5c28698a73f800fde911bcc33d405a15f7bddab1c4ade637b69a822","e880a08fbb0d9ee2f733f9183f4d1bdb75bc9e0e64060a8a1fc30540791fcded","b0b4974c11712db7a362ae6fa8ea0f0042a7c34da5f0c80302650ffe921e3d87","69fc4a10650eff3416ba5c2f7ce71744734928a7135ebe5a63c61d2d03ca3ec3","13918848c4e07d1094164112bd7fd151d61cbb949ceef340a2a4595cd609afb6","9af6a9de7bd818e68c4236f20027ff4b19387c2269a6952945d1a716c177cc4d","3497438242251378cf232f36a7fabac70e7bd8229d68dac8955534e63ffc8ff4","e61a21e9418f279bc480394a94d1581b2dee73747adcbdef999b6737e34d721b","e033253e77794e1595f01372623b631d986e04dcb47d08948301fd2652886a83","2b8264b2fefd7367e0f20e2c04eed5d3038831fe00f5efbc110ff0131aab899b"],"options":{"declaration":true,"downlevelIteration":true,"esModuleInterop":true,"jsx":4,"module":1,"newLine":1,"noFallthroughCasesInSwitch":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","sourceMap":true,"strict":true,"target":1},"fileIdsList":[[140,141],[112,119,128],[104,112,119],[128],[110,112,119],[112],[112,128,134],[112,119,128,134],[112,113,114,119,128,131,134],[112,114,131,134],[140,142],[110,112,128],[102],[112,128],[126,135,137],[108,110,119,128],[101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139],[119],[125],[79],[30,31],[31],[36],[38],[44,46],[32,34,35,36,37,38,40,41,42,43,45,47,49,50,51,52,53,54,55,56],[44],[45,47],[62],[47,57],[30,31,32,47],[32,33,47],[32,34,47],[32,36,47],[32,37,47],[32,38,47],[32,39,47],[32,41,47],[32,42,47],[32,47,60],[32,45,47],[47,49,80],[32,47,49],[47,50],[50],[85],[43],[88,104,121],[47,51],[78,83,90,91,92],[47,54,57],[43,47,55,57],[47,52,80],[32,47,52],[47,63,80],[32,47,63],[113,121]],"referencedMap":[[142,1],[104,2],[105,3],[108,4],[109,5],[111,6],[112,6],[113,7],[114,8],[115,9],[116,10],[143,11],[117,6],[119,12],[122,13],[126,14],[127,15],[128,6],[131,16],[140,17],[133,18],[134,19],[138,14],[139,4],[80,20],[32,21],[33,22],[37,23],[39,24],[47,25],[57,26],[45,27],[46,28],[63,29],[64,30],[65,30],[66,30],[67,30],[68,31],[69,32],[70,33],[71,34],[72,35],[73,36],[74,37],[75,38],[76,39],[77,40],[78,41],[81,42],[82,43],[83,44],[84,45],[86,46],[87,47],[89,48],[90,49],[93,50],[94,51],[95,52],[92,53],[96,54],[91,55],[97,56],[85,57],[44,47]],"exportedModulesMap":[[142,1],[104,2],[105,3],[108,4],[109,5],[111,6],[112,6],[113,7],[114,8],[115,9],[116,10],[143,11],[117,6],[119,12],[122,13],[126,14],[127,15],[128,6],[131,16],[140,17],[133,18],[134,19],[138,14],[139,4],[80,20],[32,21],[33,22],[37,23],[39,24],[47,25],[57,26],[45,27],[46,28],[63,29],[64,30],[65,30],[66,30],[67,30],[68,31],[69,32],[70,33],[71,34],[72,35],[73,36],[74,37],[75,38],[76,39],[77,40],[78,41],[81,42],[82,43],[83,44],[84,45],[86,46],[87,47],[89,48],[90,49],[93,50],[94,51],[95,52],[92,53],[96,54],[91,55],[97,56],[85,57],[44,47]],"semanticDiagnosticsPerFile":[99,100,141,102,142,103,104,105,106,107,108,109,110,111,112,113,101,114,115,116,143,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,140,133,134,135,136,137,138,139,144,88,80,79,6,8,7,2,9,10,11,12,13,14,15,16,3,4,20,17,18,19,21,22,23,5,24,25,26,27,28,1,29,32,33,34,35,37,36,38,39,40,41,42,47,48,49,50,43,57,45,51,59,60,61,46,63,56,54,55,52,64,65,66,67,58,68,69,70,71,72,73,74,75,76,77,78,81,82,83,84,86,87,89,90,93,94,95,92,96,91,97,62,31,30,85,98,53,44]},"version":"4.4.3"} \ No newline at end of file diff --git a/typeGuard.d.ts b/typeGuard.d.ts new file mode 100644 index 0000000..e5924e2 --- /dev/null +++ b/typeGuard.d.ts @@ -0,0 +1,2 @@ +/** https://docs.tsafe.dev/typeguard */ +export declare function typeGuard(_value: any, isMatched: boolean): _value is T; diff --git a/typeGuard.js b/typeGuard.js new file mode 100644 index 0000000..f791f45 --- /dev/null +++ b/typeGuard.js @@ -0,0 +1,11 @@ +"use strict"; +/* eslint-disable @typescript-eslint/no-namespace */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.typeGuard = void 0; +/** https://docs.tsafe.dev/typeguard */ +function typeGuard(_value, isMatched) { + return isMatched; +} +exports.typeGuard = typeGuard; +//# sourceMappingURL=typeGuard.js.map \ No newline at end of file diff --git a/typeGuard.js.map b/typeGuard.js.map new file mode 100644 index 0000000..7cca5b8 --- /dev/null +++ b/typeGuard.js.map @@ -0,0 +1 @@ +{"version":3,"file":"typeGuard.js","sourceRoot":"","sources":["src/typeGuard.ts"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,uDAAuD;;;AAEvD,uCAAuC;AACvC,SAAgB,SAAS,CAAI,MAAW,EAAE,SAAkB;IACxD,OAAO,SAAS,CAAC;AACrB,CAAC;AAFD,8BAEC"} \ No newline at end of file diff --git a/zz_internal/assertIsRefWrapper.d.ts b/zz_internal/assertIsRefWrapper.d.ts new file mode 100644 index 0000000..443d0e1 --- /dev/null +++ b/zz_internal/assertIsRefWrapper.d.ts @@ -0,0 +1,3 @@ +export declare const assertIsRefWrapper: { + ref: Record | undefined; +}; diff --git a/zz_internal/assertIsRefWrapper.js b/zz_internal/assertIsRefWrapper.js new file mode 100644 index 0000000..3db8e05 --- /dev/null +++ b/zz_internal/assertIsRefWrapper.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.assertIsRefWrapper = void 0; +var id_1 = require("../id"); +exports.assertIsRefWrapper = { + "ref": (0, id_1.id)(undefined), +}; +//# sourceMappingURL=assertIsRefWrapper.js.map \ No newline at end of file diff --git a/zz_internal/assertIsRefWrapper.js.map b/zz_internal/assertIsRefWrapper.js.map new file mode 100644 index 0000000..7e3e5c5 --- /dev/null +++ b/zz_internal/assertIsRefWrapper.js.map @@ -0,0 +1 @@ +{"version":3,"file":"assertIsRefWrapper.js","sourceRoot":"","sources":["../src/zz_internal/assertIsRefWrapper.ts"],"names":[],"mappings":";;;AAAA,4BAA2B;AAEd,QAAA,kBAAkB,GAAG;IAC9B,KAAK,EAAE,IAAA,OAAE,EAAoC,SAAS,CAAC;CAC1D,CAAC"} \ No newline at end of file