Repository: millsp/ts-toolbelt Branch: master Commit: b8a49285e3ed Files: 293 Total size: 382.9 KB Directory structure: gitextract_d0x81m7m/ ├── .commitlintrc.json ├── .eslintrc.json ├── .github/ │ ├── CODEOWNERS │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE/ │ │ ├── ---bug-report.md │ │ └── ---feature-request.md │ ├── pull_request_template.md │ └── stale.yml ├── .gitignore ├── .huskyrc.json ├── .travis.yml ├── .versionrc.json ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── package.json ├── scripts/ │ ├── build/ │ │ ├── clean.sh │ │ ├── code.sh │ │ ├── docs.sh │ │ └── types.sh │ ├── ci/ │ │ ├── branch/ │ │ │ ├── ad.sh │ │ │ └── bd.sh │ │ ├── master/ │ │ │ ├── ad.sh │ │ │ └── bd.sh │ │ └── test/ │ │ ├── ad.sh │ │ └── bd.sh │ ├── release.sh │ ├── test/ │ │ ├── all.sh │ │ ├── code.sh │ │ ├── lint.sh │ │ └── types.sh │ └── tools/ │ ├── check-deploy.sh │ ├── dt-update-version.ts │ ├── package-test-version.ts │ └── regex-update-file.ts ├── sources/ │ ├── Any/ │ │ ├── At.ts │ │ ├── Await.ts │ │ ├── Cast.ts │ │ ├── Compute.ts │ │ ├── Contains.ts │ │ ├── Equals.ts │ │ ├── Extends.ts │ │ ├── If.ts │ │ ├── Is.ts │ │ ├── Key.ts │ │ ├── Keys.ts │ │ ├── KnownKeys.ts │ │ ├── Promise.ts │ │ ├── Try.ts │ │ ├── Type.ts │ │ ├── _Internal.ts │ │ ├── _api.ts │ │ └── x.ts │ ├── Boolean/ │ │ ├── And.ts │ │ ├── Not.ts │ │ ├── Or.ts │ │ ├── Xor.ts │ │ ├── _Internal.ts │ │ └── _api.ts │ ├── Class/ │ │ ├── Class.ts │ │ ├── Instance.ts │ │ ├── Parameters.ts │ │ └── _api.ts │ ├── Community/ │ │ ├── IncludesDeep.ts │ │ ├── IsLiteral.ts │ │ └── _api.ts │ ├── Function/ │ │ ├── AutoPath.ts │ │ ├── Compose/ │ │ │ ├── List/ │ │ │ │ ├── Async.ts │ │ │ │ └── Sync.ts │ │ │ └── Multi/ │ │ │ ├── Async.ts │ │ │ └── Sync.ts │ │ ├── Compose.ts │ │ ├── Curry.ts │ │ ├── Exact.ts │ │ ├── Function.ts │ │ ├── Length.ts │ │ ├── Narrow.ts │ │ ├── NoInfer.ts │ │ ├── Parameters.ts │ │ ├── Pipe/ │ │ │ ├── List/ │ │ │ │ ├── Async.ts │ │ │ │ └── Sync.ts │ │ │ └── Multi/ │ │ │ ├── Async.ts │ │ │ └── Sync.ts │ │ ├── Pipe.ts │ │ ├── Promisify.ts │ │ ├── Return.ts │ │ ├── UnCurry.ts │ │ ├── ValidPath.ts │ │ ├── _Internal.ts │ │ └── _api.ts │ ├── Iteration/ │ │ ├── Iteration.ts │ │ ├── IterationOf.ts │ │ ├── Key.ts │ │ ├── Next.ts │ │ ├── Pos.ts │ │ ├── Prev.ts │ │ ├── _Internal.ts │ │ └── _api.ts │ ├── List/ │ │ ├── Append.ts │ │ ├── Assign.ts │ │ ├── AtLeast.ts │ │ ├── Compulsory.ts │ │ ├── CompulsoryKeys.ts │ │ ├── Concat.ts │ │ ├── Diff.ts │ │ ├── Drop.ts │ │ ├── Either.ts │ │ ├── Exclude.ts │ │ ├── ExcludeKeys.ts │ │ ├── Extract.ts │ │ ├── Filter.ts │ │ ├── FilterKeys.ts │ │ ├── Flatten.ts │ │ ├── Group.ts │ │ ├── Has.ts │ │ ├── HasPath.ts │ │ ├── Head.ts │ │ ├── Includes.ts │ │ ├── Intersect.ts │ │ ├── IntersectKeys.ts │ │ ├── KeySet.ts │ │ ├── Last.ts │ │ ├── LastKey.ts │ │ ├── Length.ts │ │ ├── List.ts │ │ ├── Longest.ts │ │ ├── Merge.ts │ │ ├── MergeAll.ts │ │ ├── Modify.ts │ │ ├── NonNullable.ts │ │ ├── NonNullableKeys.ts │ │ ├── Nullable.ts │ │ ├── NullableKeys.ts │ │ ├── ObjectOf.ts │ │ ├── Omit.ts │ │ ├── Optional.ts │ │ ├── OptionalKeys.ts │ │ ├── Overwrite.ts │ │ ├── Partial.ts │ │ ├── Patch.ts │ │ ├── PatchAll.ts │ │ ├── Path.ts │ │ ├── Paths.ts │ │ ├── Pick.ts │ │ ├── Pop.ts │ │ ├── Prepend.ts │ │ ├── Readonly.ts │ │ ├── ReadonlyKeys.ts │ │ ├── Remove.ts │ │ ├── Repeat.ts │ │ ├── Replace.ts │ │ ├── Required.ts │ │ ├── RequiredKeys.ts │ │ ├── Reverse.ts │ │ ├── Select.ts │ │ ├── SelectKeys.ts │ │ ├── Shortest.ts │ │ ├── Tail.ts │ │ ├── Take.ts │ │ ├── UnNest.ts │ │ ├── Undefinable.ts │ │ ├── UndefinableKeys.ts │ │ ├── UnionOf.ts │ │ ├── Unionize.ts │ │ ├── Update.ts │ │ ├── Writable.ts │ │ ├── WritableKeys.ts │ │ ├── Zip.ts │ │ ├── ZipObj.ts │ │ ├── _Internal.ts │ │ └── _api.ts │ ├── Misc/ │ │ ├── BuiltIn.ts │ │ ├── JSON/ │ │ │ ├── Array.ts │ │ │ ├── Object.ts │ │ │ ├── Primitive.ts │ │ │ ├── Value.ts │ │ │ └── _api.ts │ │ ├── Primitive.ts │ │ └── _api.ts │ ├── Number/ │ │ ├── Absolute.ts │ │ ├── Add.ts │ │ ├── Greater.ts │ │ ├── GreaterEq.ts │ │ ├── IsNegative.ts │ │ ├── IsPositive.ts │ │ ├── IsZero.ts │ │ ├── Lower.ts │ │ ├── LowerEq.ts │ │ ├── Negate.ts │ │ ├── Range.ts │ │ ├── Sub.ts │ │ └── _api.ts │ ├── Object/ │ │ ├── Assign.ts │ │ ├── AtLeast.ts │ │ ├── Compulsory.ts │ │ ├── CompulsoryKeys.ts │ │ ├── Diff.ts │ │ ├── Either.ts │ │ ├── Exclude.ts │ │ ├── ExcludeKeys.ts │ │ ├── Filter.ts │ │ ├── FilterKeys.ts │ │ ├── Has.ts │ │ ├── HasPath.ts │ │ ├── Includes.ts │ │ ├── Intersect.ts │ │ ├── IntersectKeys.ts │ │ ├── Invert.ts │ │ ├── ListOf.ts │ │ ├── Merge.ts │ │ ├── MergeAll.ts │ │ ├── Modify.ts │ │ ├── NonNullable.ts │ │ ├── NonNullableKeys.ts │ │ ├── Nullable.ts │ │ ├── NullableKeys.ts │ │ ├── Object.ts │ │ ├── Omit.ts │ │ ├── Optional.ts │ │ ├── OptionalKeys.ts │ │ ├── Overwrite.ts │ │ ├── P/ │ │ │ ├── Merge.ts │ │ │ ├── Omit.ts │ │ │ ├── Pick.ts │ │ │ ├── Readonly.ts │ │ │ ├── Record.ts │ │ │ ├── Update.ts │ │ │ ├── _Internal.ts │ │ │ └── _api.ts │ │ ├── Partial.ts │ │ ├── Patch.ts │ │ ├── PatchAll.ts │ │ ├── Path.ts │ │ ├── Paths.ts │ │ ├── Pick.ts │ │ ├── Readonly.ts │ │ ├── ReadonlyKeys.ts │ │ ├── Record.ts │ │ ├── Replace.ts │ │ ├── Required.ts │ │ ├── RequiredKeys.ts │ │ ├── Select.ts │ │ ├── SelectKeys.ts │ │ ├── Undefinable.ts │ │ ├── UndefinableKeys.ts │ │ ├── UnionOf.ts │ │ ├── Unionize.ts │ │ ├── Update.ts │ │ ├── Writable.ts │ │ ├── WritableKeys.ts │ │ ├── _Internal.ts │ │ └── _api.ts │ ├── String/ │ │ ├── At.ts │ │ ├── Join.ts │ │ ├── Length.ts │ │ ├── Replace.ts │ │ ├── Split.ts │ │ ├── _Internal.ts │ │ └── _api.ts │ ├── Test.ts │ ├── Union/ │ │ ├── Diff.ts │ │ ├── Exclude.ts │ │ ├── Filter.ts │ │ ├── Has.ts │ │ ├── Intersect.ts │ │ ├── IntersectOf.ts │ │ ├── Last.ts │ │ ├── ListOf.ts │ │ ├── Merge.ts │ │ ├── NonNullable.ts │ │ ├── Nullable.ts │ │ ├── Pop.ts │ │ ├── Replace.ts │ │ ├── Select.ts │ │ ├── Strict.ts │ │ └── _api.ts │ └── index.ts ├── tests/ │ ├── Any.ts │ ├── Boolean.ts │ ├── Class.ts │ ├── Community.ts │ ├── Function.ts │ ├── Iteration.ts │ ├── List.ts │ ├── Misc.ts │ ├── Number.ts │ ├── Object.ts │ ├── String.ts │ └── Union.ts └── tsconfig.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .commitlintrc.json ================================================ { "extends": ["@commitlint/config-conventional"] } ================================================ FILE: .eslintrc.json ================================================ { // https://github.com/Microsoft/vscode-eslint/issues/284 "parser": "@typescript-eslint/parser", "extends": ["eslint:recommended"], "plugins": ["react", "fp"], "env": { "browser": true, "es6": true, "commonjs": true }, "globals": { "__dirname": false }, "parserOptions": { "jsx": true, "ecmaFeatures": { "jsx": true }, "ecmaVersion": 2018, "sourceType": "module" }, "rules": { // code features "array-callback-return" : ["error"], "arrow-parens" : ["error"], "arrow-spacing" : ["error"], "curly" : ["error", "multi-or-nest"], "default-case" : ["error"], "dot-location" : ["error"], "eqeqeq" : ["warn"], "generator-star-spacing" : ["error"], "no-caller" : ["error"], "no-console" : ["off"], "no-div-regex" : ["error"], "no-else-return" : ["error"], "no-extend-native" : ["error"], "no-floating-decimal" : ["error"], // "no-implicit-coercion" : ["error"], "no-implicit-globals" : ["error"], "no-implied-eval" : ["error"], "no-invalid-this" : ["error"], "no-labels" : ["error"], "no-new-wrappers" : ["error"], "no-proto" : ["error"], "no-return-assign" : ["error"], "no-return-await" : ["error"], "no-self-compare" : ["error"], "no-sequences" : ["error"], "no-unmodified-loop-condition": ["warn"], "no-undef" : ["off"], "no-unused-vars" : ["off"], "no-useless-call" : ["error"], "no-useless-catch" : ["error"], "no-useless-concat" : ["error"], "no-useless-return" : ["error"], "no-var" : ["error"], "no-with" : ["error"], // "object-shorthand" : ["warn"], "prefer-arrow-callback" : ["error"], "prefer-rest-params" : ["error"], "prefer-spread" : ["error"], "prefer-template" : ["error"], "require-await" : ["warn"], "require-unicode-regexp" : ["error"], "rest-spread-spacing" : ["error"], "symbol-description" : ["error"], "template-curly-spacing" : ["error"], "yield-star-spacing" : ["error", "before"], "yoda" : ["error"], // code style "array-bracket-newline" : ["error", "consistent"], "array-bracket-spacing" : ["error"], "block-spacing" : ["error", "never"], "brace-style" : ["error", "1tbs", {"allowSingleLine": true}], "comma-dangle" : ["error", "always-multiline"], "comma-spacing" : ["error", {"before": false, "after": true}], "computed-property-spacing" : ["error"], "eol-last" : ["error"], "func-call-spacing" : ["error"], "indent" : ["error", 4, {"MemberExpression": 0}], "key-spacing" : ["error", {"align": "colon"}], "keyword-spacing" : ["error"], "linebreak-style" : ["error"], "new-cap" : ["error", {"capIsNew": false}], "no-array-constructor" : ["error"], "no-multi-assign" : ["error"], "no-nested-ternary" : ["error"], "no-whitespace-before-property": ["error"], "object-curly-newline" : ["error"], "object-curly-spacing" : ["error"], "prefer-object-spread" : ["error"], "quotes" : ["error", "single"], "semi" : ["error", "never"], "no-trailing-spaces" : ["error"] // "multiline-comment-style" : ["error", "starred-block"] } } ================================================ FILE: .github/CODEOWNERS ================================================ * @millsp ================================================ FILE: .github/FUNDING.yml ================================================ github: millsp custom: https://www.buymeacoffee.com/millsp patreon: millsp ================================================ FILE: .github/ISSUE_TEMPLATE/---bug-report.md ================================================ --- name: "🐞 Bug Report" about: "Something isn't working well 💔" --- ## 🐞 Bug Report #### Describe the bug #### Reproduce the bug ```ts // REPL or a link to your repository if applicable. // A *self-contained* demonstration of the problem. ``` #### Expected behavior #### Possible Solution #### Screenshots #### Additional context ================================================ FILE: .github/ISSUE_TEMPLATE/---feature-request.md ================================================ --- name: "🍩 Feature Request" about: "Suggest an idea for this project 💡" --- ## 🍩 Feature Request #### Is your feature request related to a problem? #### Describe the solution you'd like #### Describe alternatives you've considered #### Teachability, Documentation, Adoption, Migration Strategy ================================================ FILE: .github/pull_request_template.md ================================================ ## 🎁 Pull Request * [ ] Used a clear / meaningful title for this pull request * [ ] Tested the changes in your own code (on your projects) * [ ] Added / Edited tests to reflect changes (`tests` folder) * [ ] Have read the **Contributing** part of the **Readme** * [ ] Passed `npm test` #### Fixes #### Why have you made changes? #### What changes have you made? * changed this to achieve this * changed that to achieve this * ... #### What tests have you updated? * tested this in `tests/...` * tested that in `tests/...` * ... #### Is there any breaking changes? * [ ] Yes, I changed the public API & documented it * [ ] Yes, I changed existing tests * [ ] No, I added to the public API & documented it * [ ] No, I added to the existing tests * [ ] I don't know #### Anything else worth mentioning? ================================================ FILE: .github/stale.yml ================================================ # Number of days of inactivity before an issue becomes stale daysUntilStale: 60 # Number of days of inactivity before a stale issue is closed daysUntilClose: 7 # Issues with these labels will never be considered stale exemptLabels: - pinned #todo - security # Label to use when marking an issue as stale staleLabel: wontfix # Comment to post when marking an issue as stale. Set to `false` to disable markComment: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. # Comment to post when closing a stale issue. Set to `false` to disable closeComment: false ================================================ FILE: .gitignore ================================================ package-lock.json node_modules .vscode *.tgz docs out dt ================================================ FILE: .huskyrc.json ================================================ { "hooks": { "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } } ================================================ FILE: .travis.yml ================================================ # https://docs.travis-ci.com/user/job-lifecycle language: node_js node_js: - '12.0' git: depth: 5 install: - npm install --only=dev env: - DEPLOY=true stages: - test - deploy:master - deploy:branch - deploy:docs jobs: include: - stage: test if: tag IS blank # filter double build with tags script: - npm run test deploy: edge: true provider: npm email: $NPM_EMAIL api_key: $NPM_TOKEN skip_cleanup: true tag: test on: all_branches: true before_deploy: # https://github.com/travis-ci/travis-ci/issues/1574#issuecomment-451787844 - if ! npm run ci:test:bd; then travis_terminate 1; fi after_deploy: # the above link explains how to make the build fail if something went wrong - if ! npm run ci:test:ad; then travis_terminate 1; fi - stage: deploy:master if: tag IS blank AND branch = master AND fork = false AND env(DEPLOY) = true deploy: edge: true provider: npm email: $NPM_EMAIL api_key: $NPM_TOKEN tag: latest skip_cleanup: true on: all_branches: true before_deploy: - if ! npm run ci:master:bd; then travis_terminate 1; fi after_deploy: - if ! npm run ci:master:ad; then travis_terminate 1; fi - stage: deploy:branch if: tag IS blank AND branch != master AND fork = false AND env(DEPLOY) = true deploy: edge: true provider: npm email: $NPM_EMAIL api_key: $NPM_TOKEN tag: $TRAVIS_BRANCH skip_cleanup: true on: all_branches: true before_deploy: - if ! npm run ci:branch:bd; then travis_terminate 1; fi after_deploy: - if ! npm run ci:branch:ad; then travis_terminate 1; fi - stage: deploy:docs #deploys doc to gh-pages branch if: tag IS blank AND branch = master AND fork = false AND env(DEPLOY) = true deploy: edge: true provider: pages skip_cleanup: true github_token: $GH_TOKEN local_dir: "docs" keep_history: true on: all_branches: true before_deploy: - if ! npm run ci:docs:bd; then travis_terminate 1; fi after_deploy: - if ! npm run ci:docs:ad; then travis_terminate 1; fi ================================================ FILE: .versionrc.json ================================================ { "types": [ {"type": "feat", "section": "Features"}, {"type": "fix", "section": "Bug Fixes"}, {"type": "build", "section": "Others"}, {"type": "ci", "section": "Others"}, {"type": "chore", "section": "Others"}, {"type": "docs", "section": "Others"}, {"type": "perf", "section": "Others"}, {"type": "refactor", "section": "Others"}, {"type": "revert", "section": "Others"}, {"type": "style", "section": "Others"}, {"type": "test", "section": "Others"} ] } ================================================ FILE: CHANGELOG.md ================================================ # Changelog All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. ## [9.6.0](https://github.com/millsp/ts-toolbelt/compare/v9.5.1...v9.6.0) (2021-03-10) ### Features * **paths:** parameter for AutoPath delimiter ([6d5bbdc](https://github.com/millsp/ts-toolbelt/commit/6d5bbdc834ce15dd3339d101c828457b1a34cce4)) ### Bug Fixes * **f.autopath:** distribute ([29eddd9](https://github.com/millsp/ts-toolbelt/commit/29eddd99c6826696941c50681ce4858243786110)) * **f.autopath:** do not show primitive props ([1ad2638](https://github.com/millsp/ts-toolbelt/commit/1ad26389aa6a9a795d19d90d2724c73ae2bd51d9)) * **f.autopath:** no primitve paths ([2bdb477](https://github.com/millsp/ts-toolbelt/commit/2bdb4778325288154c8f71c0a5ae4a1b7e2b217f)) * **f.narrow:** fix variance and array inference ([4c7618d](https://github.com/millsp/ts-toolbelt/commit/4c7618d77b07d6b8c6dfd5087aa85a073bf57db3)) * **f.narrow:** higher order function support ([dad05ee](https://github.com/millsp/ts-toolbelt/commit/dad05eec6e6710ea4f63063658a3dee4d9c0ca28)) * **f.narrow:** preserve fns and better display ([a0d62d8](https://github.com/millsp/ts-toolbelt/commit/a0d62d8cfcd28eab7132c225ba187556ca749b4d)) * **f.narrow:** preserve functions ([c34f1b9](https://github.com/millsp/ts-toolbelt/commit/c34f1b95d0e0855203104eb696cfcb8221a65374)) * **f.narrow:** revert variance fixes ([12e014a](https://github.com/millsp/ts-toolbelt/commit/12e014a3f3d34047a3722486a73493f857a3697a)) * **f.narrow:** variance ([866ecd7](https://github.com/millsp/ts-toolbelt/commit/866ecd76744fc38244d85e7ef7b4bb90105cf7eb)) * **fn:** allow for curried in compose ([2bc5604](https://github.com/millsp/ts-toolbelt/commit/2bc560446916b423977c25e396b4f1f310b6c03f)) * **o.paths:** dive within arrays and deeper ([626beb6](https://github.com/millsp/ts-toolbelt/commit/626beb61b3100c5e4fd699c946e0e2fed7e24cb6)) ### Others * **list:** more flexible keys ([d9415b2](https://github.com/millsp/ts-toolbelt/commit/d9415b2f85633c7c74a815c9909899114faf530c)) * **o.p:** re-implement ([0f44362](https://github.com/millsp/ts-toolbelt/commit/0f443626dc3b114b6784d2053510a1e0c2f7f839)) * **release:** 9.5.10 ([1f3928a](https://github.com/millsp/ts-toolbelt/commit/1f3928a70ff2a7e903a5398b53295c9c9997b42c)) * **release:** 9.5.11 ([bde9210](https://github.com/millsp/ts-toolbelt/commit/bde9210d0a361ddb1e03920a0c2bd42dad17ee30)) * **release:** 9.5.12 ([80579e1](https://github.com/millsp/ts-toolbelt/commit/80579e1eaa17b2d1c61bd7881d0ea6ff94753141)) * **release:** 9.5.13 ([277a6e2](https://github.com/millsp/ts-toolbelt/commit/277a6e2ac5ca8be2bbcd7593d987aaac3ea9bb75)) * **release:** 9.5.2 ([ec4a953](https://github.com/millsp/ts-toolbelt/commit/ec4a953cabe6c4d704c0dca5f37d1dc630de047b)) * **release:** 9.5.3 ([0836f6e](https://github.com/millsp/ts-toolbelt/commit/0836f6e8187287a0c86f249e4e552d68a44e4f60)) * **release:** 9.5.4 ([855855e](https://github.com/millsp/ts-toolbelt/commit/855855e520ed4a04059f9d61884d2045dd0d751b)) * **release:** 9.5.5 ([e28bddf](https://github.com/millsp/ts-toolbelt/commit/e28bddf33066850a764e2ba344883ff84da561b9)) * **release:** 9.5.6 ([b8e0d0a](https://github.com/millsp/ts-toolbelt/commit/b8e0d0a83228baf666e00f4fdb0d99ca936c133f)) * **release:** 9.5.7 ([5646455](https://github.com/millsp/ts-toolbelt/commit/564645547862c7d698f4a03b15ccb7a5ffb5fc29)) * **release:** 9.5.8 ([bceb8be](https://github.com/millsp/ts-toolbelt/commit/bceb8be67701f9c7aba9608aed851567e8118ca5)) * **release:** 9.5.9 ([533a6ac](https://github.com/millsp/ts-toolbelt/commit/533a6ac0f7b713933c94f0962166c7a0245b055e)) * **release:** 9.6.0 ([5e6d008](https://github.com/millsp/ts-toolbelt/commit/5e6d008888c1705e41bf752b3a308323a5c563fe)) * **string:** instantiation limiters ([9a678d8](https://github.com/millsp/ts-toolbelt/commit/9a678d8a400c97436d428dad05405abb154af958)) * **update:** remove dirty code ([9d0ff64](https://github.com/millsp/ts-toolbelt/commit/9d0ff6441518c2c9a01cea7726c08acd19eb37d9)) * cleanup ([6f23f2e](https://github.com/millsp/ts-toolbelt/commit/6f23f2ec79145a0545eb45d15d50d0363a119b12)) ================================================ FILE: CODE_OF_CONDUCT.md ================================================ # Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies within all project spaces, and it also applies when an individual is representing the project or its community in public spaces. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [gitter.im/millsp](https://gitter.im/millsp). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq ================================================ FILE: CONTRIBUTING.md ================================================ Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. There are many ways to contribute to the project: ### Community * [Help the community with answers on Gitter](https://gitter.im/ts-toolbelt/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link) * [Reporting bugs or requesting new features](https://github.com/millsp/ts-toolbelt/issues/new/choose) ### Codebase * Improving existing documentation * Adding new types to the collection * [Getting involved with things to do](#-whats-next) ### Pull Requests 1. [Read the tutorial](https://medium.com/free-code-camp/typescript-curry-ramda-types-f747e99744ab) 2. Fork the project 3. Clone your fork 4. Create a pr/**feature** branch ```sh git checkout -b pr/CoolFeature ``` 5. Commit your changes You **must** follow the [conventional commit](https://conventionalcommits.org) to be able to commit ```sh git commit -m "feat(name): Added this CoolFeature" ``` 6. [Run the tests](#-running-tests) 7. Push your changes ```sh npm run release -- --no-tags ``` 8. Open a pull request ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2019 Pierre-Antoine Mills Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================

banner

TypeScript's largest utility library

📖 Documentation · 📣 Announcements · 🐞 Report Bug · 🍩 Request Feature · 🤔 Ask Questions

## About **ts-toolbelt** is the largest, and most tested type library available right now, featuring **+200 utilities**. Our type collection packages some of the most advanced mapped types, conditional types, and recursive types on the market. **Spend less time, build stronger**. Benefit from a wide range of generic type functions to achieve better type safety. We work just like lodash, or ramda, but applied to the type system. Our mission is to provide you with simple ways to compute, change, and create types. We abstract all those complex type checks away for you. We provide a simple, reusable, and standard API to help you get more done with TypeScript. **ts-toolbelt** is a well organized package that can help you perform advanced operations on object types, union types, as well as function, and literal types. It is carefully and coherently designed for building robust, flexible, and type-safe software.

demo

We are a community and a knowledge base. Everyone is welcome to ask questions about types. If you are stuck or you misunderstand something, you came to the right place!. We welcome beginners and advanced developers to come take part. **Welcome!** ## Getting Started ### Prerequisites ```sh npm install typescript@^4.1.0 --save-dev ``` For best results, add this to your `tsconfig.json` ```ts { "compilerOptions": { // highly recommended (required by few utilities) "strictNullChecks": true, // this is optional, but enable whenever possible "strict": true, // this is the lowest supported standard library "lib": ["es2015"], } } ``` ### Installation ```sh npm install ts-toolbelt --save ``` ### Hello World ```ts import {Object} from "ts-toolbelt" // Check the docs below for more // Merge two `object` together type merge = Object.Merge<{name: string}, {age?: number}> // {name: string, age?: number} // Make a field of an `object` optional type optional = Object.Optional<{id: number, name: string}, "name"> // {id: number, name?: string} ``` You can [**level-up, and re-code this library from scratch**](https://medium.com/free-code-camp/typescript-curry-ramda-types-f747e99744ab). ## [Documentation ⤢](https://millsp.github.io/ts-toolbelt/) ### Imports The project is organized around TypeScript's main concepts: | **Any** | **Boolean** | **Class** | **Function** | **Iteration** | **List** | |------------|-------------|--------------|--------------|---------------|----------| | **Number** | **Object** | **Object.P** | **String** | **Union** | **Test** | > **`TIP`** How to choose categories? Match your type with them. There are many ways to import the types into your project: * **Explicit** ```ts import {Any, Boolean, Class, Function, Iteration, List, Number, Object, String, Union} from "ts-toolbelt" ``` * **Compact** ```ts import {A, B, C, F, I, L, N, O, S, U} from "ts-toolbelt" ``` * **Portable** ```ts import tb from "ts-toolbelt" ``` You can also import our non-official API from the community: ```ts import {Community} from "ts-toolbelt" ``` > **`TIP`** The community API is for our community to publish useful types that > don't see fit in the standard API. ### Utility Index |ANY|OBJECT|LIST|FUNCTION|STRING|UNION|CLASS|BOOLEAN|NUMBER|OBJECT.P|ITERATION| |---|---|---|---|---|---|---|---|---|---|---| |[Await](https://millsp.github.io/ts-toolbelt/modules/any_await.html)|[Assign](https://millsp.github.io/ts-toolbelt/modules/object_assign.html)|[Append](https://millsp.github.io/ts-toolbelt/modules/list_append.html)|[AutoPath](https://millsp.github.io/ts-toolbelt/modules/function_autopath.html)|[At](https://millsp.github.io/ts-toolbelt/modules/string_at.html)|[Diff](https://millsp.github.io/ts-toolbelt/modules/union_diff.html)|[Class](https://millsp.github.io/ts-toolbelt/modules/class_class.html)|[And](https://millsp.github.io/ts-toolbelt/modules/boolean_and.html)|[Absolute](https://millsp.github.io/ts-toolbelt/modules/number_absolute.html)|[Merge](https://millsp.github.io/ts-toolbelt/modules/object_p_merge.html)|[Iteration](https://millsp.github.io/ts-toolbelt/modules/iteration_iteration.html)| |[At](https://millsp.github.io/ts-toolbelt/modules/any_at.html)|[AtLeast](https://millsp.github.io/ts-toolbelt/modules/object_atleast.html)|[Assign](https://millsp.github.io/ts-toolbelt/modules/list_assign.html)|[Compose](https://millsp.github.io/ts-toolbelt/modules/function_compose.html)|[Join](https://millsp.github.io/ts-toolbelt/modules/string_join.html)|[Exclude](https://millsp.github.io/ts-toolbelt/modules/union_exclude.html)|[Instance](https://millsp.github.io/ts-toolbelt/modules/class_instance.html)|[Not](https://millsp.github.io/ts-toolbelt/modules/boolean_not.html)|[Add](https://millsp.github.io/ts-toolbelt/modules/number_add.html)|[Omit](https://millsp.github.io/ts-toolbelt/modules/object_p_omit.html)|[IterationOf](https://millsp.github.io/ts-toolbelt/modules/iteration_iterationof.html)| |[Cast](https://millsp.github.io/ts-toolbelt/modules/any_cast.html)|[Compulsory](https://millsp.github.io/ts-toolbelt/modules/object_compulsory.html)|[AtLeast](https://millsp.github.io/ts-toolbelt/modules/list_atleast.html)|[Curry](https://millsp.github.io/ts-toolbelt/modules/function_curry.html)|[Length](https://millsp.github.io/ts-toolbelt/modules/string_length.html)|[Filter](https://millsp.github.io/ts-toolbelt/modules/union_filter.html)|[Parameters](https://millsp.github.io/ts-toolbelt/modules/class_parameters.html)|[Or](https://millsp.github.io/ts-toolbelt/modules/boolean_or.html)|[Greater](https://millsp.github.io/ts-toolbelt/modules/number_greater.html)|[Pick](https://millsp.github.io/ts-toolbelt/modules/object_p_pick.html)|[Key](https://millsp.github.io/ts-toolbelt/modules/iteration_key.html)| |[Compute](https://millsp.github.io/ts-toolbelt/modules/any_compute.html)|[CompulsoryKeys](https://millsp.github.io/ts-toolbelt/modules/object_compulsorykeys.html)|[Compulsory](https://millsp.github.io/ts-toolbelt/modules/list_compulsory.html)|[Exact](https://millsp.github.io/ts-toolbelt/modules/function_exact.html)|[Replace](https://millsp.github.io/ts-toolbelt/modules/string_replace.html)|[Has](https://millsp.github.io/ts-toolbelt/modules/union_has.html)||[Xor](https://millsp.github.io/ts-toolbelt/modules/boolean_xor.html)|[GreaterEq](https://millsp.github.io/ts-toolbelt/modules/number_greatereq.html)|[Readonly](https://millsp.github.io/ts-toolbelt/modules/object_p_readonly.html)|[Next](https://millsp.github.io/ts-toolbelt/modules/iteration_next.html)| |[Contains](https://millsp.github.io/ts-toolbelt/modules/any_contains.html)|[Diff](https://millsp.github.io/ts-toolbelt/modules/object_diff.html)|[CompulsoryKeys](https://millsp.github.io/ts-toolbelt/modules/list_compulsorykeys.html)|[Function](https://millsp.github.io/ts-toolbelt/modules/function_function.html)|[Split](https://millsp.github.io/ts-toolbelt/modules/string_split.html)|[IntersectOf](https://millsp.github.io/ts-toolbelt/modules/union_intersectof.html)|||[IsNegative](https://millsp.github.io/ts-toolbelt/modules/number_isnegative.html)|[Update](https://millsp.github.io/ts-toolbelt/modules/object_p_update.html)|[Pos](https://millsp.github.io/ts-toolbelt/modules/iteration_pos.html)| |[Equals](https://millsp.github.io/ts-toolbelt/modules/any_equals.html)|[Either](https://millsp.github.io/ts-toolbelt/modules/object_either.html)|[Concat](https://millsp.github.io/ts-toolbelt/modules/list_concat.html)|[Length](https://millsp.github.io/ts-toolbelt/modules/function_length.html)||[Last](https://millsp.github.io/ts-toolbelt/modules/union_last.html)|||[IsPositive](https://millsp.github.io/ts-toolbelt/modules/number_ispositive.html)|[Record](https://millsp.github.io/ts-toolbelt/modules/object_p_record.html)|[Prev](https://millsp.github.io/ts-toolbelt/modules/iteration_prev.html)| |[Extends](https://millsp.github.io/ts-toolbelt/modules/any_extends.html)|[Exclude](https://millsp.github.io/ts-toolbelt/modules/object_exclude.html)|[Diff](https://millsp.github.io/ts-toolbelt/modules/list_diff.html)|[Narrow](https://millsp.github.io/ts-toolbelt/modules/function_narrow.html)||[Merge](https://millsp.github.io/ts-toolbelt/modules/union_merge.html)|||[IsZero](https://millsp.github.io/ts-toolbelt/modules/number_iszero.html)||| |[Key](https://millsp.github.io/ts-toolbelt/modules/any_key.html)|[ExcludeKeys](https://millsp.github.io/ts-toolbelt/modules/object_excludekeys.html)|[Drop](https://millsp.github.io/ts-toolbelt/modules/list_drop.html)|[NoInfer](https://millsp.github.io/ts-toolbelt/modules/function_noinfer.html)||[NonNullable](https://millsp.github.io/ts-toolbelt/modules/union_nonnullable.html)|||[Lower](https://millsp.github.io/ts-toolbelt/modules/number_lower.html)||| |[Keys](https://millsp.github.io/ts-toolbelt/modules/any_keys.html)|[Filter](https://millsp.github.io/ts-toolbelt/modules/object_filter.html)|[Either](https://millsp.github.io/ts-toolbelt/modules/list_either.html)|[Parameters](https://millsp.github.io/ts-toolbelt/modules/function_parameters.html)||[Nullable](https://millsp.github.io/ts-toolbelt/modules/union_nullable.html)|||[LowerEq](https://millsp.github.io/ts-toolbelt/modules/number_lowereq.html)||| |[KnownKeys](https://millsp.github.io/ts-toolbelt/modules/any_knownkeys.html)|[FilterKeys](https://millsp.github.io/ts-toolbelt/modules/object_filterkeys.html)|[Exclude](https://millsp.github.io/ts-toolbelt/modules/list_exclude.html)|[Pipe](https://millsp.github.io/ts-toolbelt/modules/function_pipe.html)||[Pop](https://millsp.github.io/ts-toolbelt/modules/union_pop.html)|||[Negate](https://millsp.github.io/ts-toolbelt/modules/number_negate.html)||| |[Is](https://millsp.github.io/ts-toolbelt/modules/any_is.html)|[Has](https://millsp.github.io/ts-toolbelt/modules/object_has.html)|[ExcludeKeys](https://millsp.github.io/ts-toolbelt/modules/list_excludekeys.html)|[Promisify](https://millsp.github.io/ts-toolbelt/modules/function_promisify.html)||[Replace](https://millsp.github.io/ts-toolbelt/modules/union_replace.html)|||[Range](https://millsp.github.io/ts-toolbelt/modules/number_range.html)||| |[Promise](https://millsp.github.io/ts-toolbelt/modules/any_promise.html)|[HasPath](https://millsp.github.io/ts-toolbelt/modules/object_haspath.html)|[Extract](https://millsp.github.io/ts-toolbelt/modules/list_extract.html)|[Return](https://millsp.github.io/ts-toolbelt/modules/function_return.html)||[Select](https://millsp.github.io/ts-toolbelt/modules/union_select.html)|||[Sub](https://millsp.github.io/ts-toolbelt/modules/number_sub.html)||| |[Try](https://millsp.github.io/ts-toolbelt/modules/any_try.html)|[Includes](https://millsp.github.io/ts-toolbelt/modules/object_includes.html)|[Filter](https://millsp.github.io/ts-toolbelt/modules/list_filter.html)|[UnCurry](https://millsp.github.io/ts-toolbelt/modules/function_uncurry.html)||[Strict](https://millsp.github.io/ts-toolbelt/modules/union_strict.html)|||||| |[Type](https://millsp.github.io/ts-toolbelt/modules/any_type.html)|[Intersect](https://millsp.github.io/ts-toolbelt/modules/object_intersect.html)|[FilterKeys](https://millsp.github.io/ts-toolbelt/modules/list_filterkeys.html)|[ValidPath](https://millsp.github.io/ts-toolbelt/modules/function_validpath.html)||[ListOf](https://millsp.github.io/ts-toolbelt/modules/union_listof.html)|||||| |[x](https://millsp.github.io/ts-toolbelt/modules/any_x.html)|[IntersectKeys](https://millsp.github.io/ts-toolbelt/modules/object_intersectkeys.html)|[Flatten](https://millsp.github.io/ts-toolbelt/modules/list_flatten.html)||||||||| ||[Invert](https://millsp.github.io/ts-toolbelt/modules/object_invert.html)|[Group](https://millsp.github.io/ts-toolbelt/modules/list_group.html)||||||||| ||[ListOf](https://millsp.github.io/ts-toolbelt/modules/object_listof.html)|[Has](https://millsp.github.io/ts-toolbelt/modules/list_has.html)||||||||| ||[Merge](https://millsp.github.io/ts-toolbelt/modules/object_merge.html)|[HasPath](https://millsp.github.io/ts-toolbelt/modules/list_haspath.html)||||||||| ||[MergeAll](https://millsp.github.io/ts-toolbelt/modules/object_mergeall.html)|[Head](https://millsp.github.io/ts-toolbelt/modules/list_head.html)||||||||| ||[Modify](https://millsp.github.io/ts-toolbelt/modules/object_modify.html)|[Includes](https://millsp.github.io/ts-toolbelt/modules/list_includes.html)||||||||| ||[NonNullable](https://millsp.github.io/ts-toolbelt/modules/object_nonnullable.html)|[Intersect](https://millsp.github.io/ts-toolbelt/modules/list_intersect.html)||||||||| ||[NonNullableKeys](https://millsp.github.io/ts-toolbelt/modules/object_nonnullablekeys.html)|[IntersectKeys](https://millsp.github.io/ts-toolbelt/modules/list_intersectkeys.html)||||||||| ||[Nullable](https://millsp.github.io/ts-toolbelt/modules/object_nullable.html)|[KeySet](https://millsp.github.io/ts-toolbelt/modules/list_keyset.html)||||||||| ||[NullableKeys](https://millsp.github.io/ts-toolbelt/modules/object_nullablekeys.html)|[Last](https://millsp.github.io/ts-toolbelt/modules/list_last.html)||||||||| ||[Object](https://millsp.github.io/ts-toolbelt/modules/object_object.html)|[LastKey](https://millsp.github.io/ts-toolbelt/modules/list_lastkey.html)||||||||| ||[Omit](https://millsp.github.io/ts-toolbelt/modules/object_omit.html)|[Length](https://millsp.github.io/ts-toolbelt/modules/list_length.html)||||||||| ||[Optional](https://millsp.github.io/ts-toolbelt/modules/object_optional.html)|[List](https://millsp.github.io/ts-toolbelt/modules/list_list.html)||||||||| ||[OptionalKeys](https://millsp.github.io/ts-toolbelt/modules/object_optionalkeys.html)|[Longest](https://millsp.github.io/ts-toolbelt/modules/list_longest.html)||||||||| ||[Overwrite](https://millsp.github.io/ts-toolbelt/modules/object_overwrite.html)|[Merge](https://millsp.github.io/ts-toolbelt/modules/list_merge.html)||||||||| ||[Partial](https://millsp.github.io/ts-toolbelt/modules/object_partial.html)|[MergeAll](https://millsp.github.io/ts-toolbelt/modules/list_mergeall.html)||||||||| ||[Patch](https://millsp.github.io/ts-toolbelt/modules/object_patch.html)|[Modify](https://millsp.github.io/ts-toolbelt/modules/list_modify.html)||||||||| ||[PatchAll](https://millsp.github.io/ts-toolbelt/modules/object_patchall.html)|[NonNullable](https://millsp.github.io/ts-toolbelt/modules/list_nonnullable.html)||||||||| ||[Path](https://millsp.github.io/ts-toolbelt/modules/object_path.html)|[NonNullableKeys](https://millsp.github.io/ts-toolbelt/modules/list_nonnullablekeys.html)||||||||| ||[Paths](https://millsp.github.io/ts-toolbelt/modules/object_paths.html)|[Nullable](https://millsp.github.io/ts-toolbelt/modules/list_nullable.html)||||||||| ||[Pick](https://millsp.github.io/ts-toolbelt/modules/object_pick.html)|[NullableKeys](https://millsp.github.io/ts-toolbelt/modules/list_nullablekeys.html)||||||||| ||[Readonly](https://millsp.github.io/ts-toolbelt/modules/object_readonly.html)|[ObjectOf](https://millsp.github.io/ts-toolbelt/modules/list_objectof.html)||||||||| ||[ReadonlyKeys](https://millsp.github.io/ts-toolbelt/modules/object_readonlykeys.html)|[Omit](https://millsp.github.io/ts-toolbelt/modules/list_omit.html)||||||||| ||[Record](https://millsp.github.io/ts-toolbelt/modules/object_record.html)|[Optional](https://millsp.github.io/ts-toolbelt/modules/list_optional.html)||||||||| ||[Replace](https://millsp.github.io/ts-toolbelt/modules/object_replace.html)|[OptionalKeys](https://millsp.github.io/ts-toolbelt/modules/list_optionalkeys.html)||||||||| ||[Required](https://millsp.github.io/ts-toolbelt/modules/object_required.html)|[Overwrite](https://millsp.github.io/ts-toolbelt/modules/list_overwrite.html)||||||||| ||[RequiredKeys](https://millsp.github.io/ts-toolbelt/modules/object_requiredkeys.html)|[Partial](https://millsp.github.io/ts-toolbelt/modules/list_partial.html)||||||||| ||[Select](https://millsp.github.io/ts-toolbelt/modules/object_select.html)|[Patch](https://millsp.github.io/ts-toolbelt/modules/list_patch.html)||||||||| ||[SelectKeys](https://millsp.github.io/ts-toolbelt/modules/object_selectkeys.html)|[PatchAll](https://millsp.github.io/ts-toolbelt/modules/list_patchall.html)||||||||| ||[Undefinable](https://millsp.github.io/ts-toolbelt/modules/object_undefinable.html)|[Path](https://millsp.github.io/ts-toolbelt/modules/list_path.html)||||||||| ||[UndefinableKeys](https://millsp.github.io/ts-toolbelt/modules/object_undefinablekeys.html)|[Paths](https://millsp.github.io/ts-toolbelt/modules/list_paths.html)||||||||| ||[Unionize](https://millsp.github.io/ts-toolbelt/modules/object_unionize.html)|[Pick](https://millsp.github.io/ts-toolbelt/modules/list_pick.html)||||||||| ||[UnionOf](https://millsp.github.io/ts-toolbelt/modules/object_unionof.html)|[Pop](https://millsp.github.io/ts-toolbelt/modules/list_pop.html)||||||||| ||[Update](https://millsp.github.io/ts-toolbelt/modules/object_update.html)|[Prepend](https://millsp.github.io/ts-toolbelt/modules/list_prepend.html)||||||||| ||[Writable](https://millsp.github.io/ts-toolbelt/modules/object_writable.html)|[Readonly](https://millsp.github.io/ts-toolbelt/modules/list_readonly.html)||||||||| ||[WritableKeys](https://millsp.github.io/ts-toolbelt/modules/object_writablekeys.html)|[ReadonlyKeys](https://millsp.github.io/ts-toolbelt/modules/list_readonlykeys.html)||||||||| |||[Remove](https://millsp.github.io/ts-toolbelt/modules/list_remove.html)||||||||| |||[Repeat](https://millsp.github.io/ts-toolbelt/modules/list_repeat.html)||||||||| |||[Replace](https://millsp.github.io/ts-toolbelt/modules/list_replace.html)||||||||| |||[Required](https://millsp.github.io/ts-toolbelt/modules/list_required.html)||||||||| |||[RequiredKeys](https://millsp.github.io/ts-toolbelt/modules/list_requiredkeys.html)||||||||| |||[Reverse](https://millsp.github.io/ts-toolbelt/modules/list_reverse.html)||||||||| |||[Select](https://millsp.github.io/ts-toolbelt/modules/list_select.html)||||||||| |||[SelectKeys](https://millsp.github.io/ts-toolbelt/modules/list_selectkeys.html)||||||||| |||[Shortest](https://millsp.github.io/ts-toolbelt/modules/list_shortest.html)||||||||| |||[Tail](https://millsp.github.io/ts-toolbelt/modules/list_tail.html)||||||||| |||[Take](https://millsp.github.io/ts-toolbelt/modules/list_take.html)||||||||| |||[Undefinable](https://millsp.github.io/ts-toolbelt/modules/list_undefinable.html)||||||||| |||[UndefinableKeys](https://millsp.github.io/ts-toolbelt/modules/list_undefinablekeys.html)||||||||| |||[Unionize](https://millsp.github.io/ts-toolbelt/modules/list_unionize.html)||||||||| |||[UnionOf](https://millsp.github.io/ts-toolbelt/modules/list_unionof.html)||||||||| |||[UnNest](https://millsp.github.io/ts-toolbelt/modules/list_unnest.html)||||||||| |||[Update](https://millsp.github.io/ts-toolbelt/modules/list_update.html)||||||||| |||[Writable](https://millsp.github.io/ts-toolbelt/modules/list_writable.html)||||||||| |||[WritableKeys](https://millsp.github.io/ts-toolbelt/modules/list_writablekeys.html)||||||||| |||[Zip](https://millsp.github.io/ts-toolbelt/modules/list_zip.html)||||||||| |||[ZipObj](https://millsp.github.io/ts-toolbelt/modules/list_zipobj.html)||||||||| ### [Archives ⤢](https://github.com/millsp/ts-toolbelt/tree/gh-pages) > **`EXAMPLE`** https://millsp.github.io/ts-toolbelt/4.2.1/ ## [Good to Know ⤢](https://github.com/millsp/ts-toolbelt/discussions/categories/q-a) In this wiki, you will find some extra resources for your learning, and understanding. **Are you missing something?** Participate to the open-wiki by [posting your questions](https://github.com/millsp/ts-toolbelt/discussions/new). ## Running tests ### For this project To run the `lint` & `type` tests, simply run: ```sh npm test ``` ### For your project Want to test your own types? Let's get started: ```ts import {Number, Test} from "ts-toolbelt" const {checks, check} = Test checks([ check, 31, Test.Pass>(), check, 2, Test.Pass>(), ]) ``` > **`TIP`** Place it in a file that won't be executed, it's just for TypeScript > to test types. ### Continuous Integration The releases are done with Travis CI in stages & whenever a branch or PR is pushed: - Tests are run with `npm test` - Tests against [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/) - Releases to npm@[branch-name] ## Compatibility The project is maintained to adapt to the constant [changes of TypeScript](https://github.com/Microsoft/TypeScript/wiki/Roadmap): | ts-toolbelt | typescript | |-------------|------------| | 9.x.x | ^4.1.x | Major version numbers will upgrade whenever TypeScript had breaking changes. Otherwise, the release versions will naturally follow the semantic versioning. ## What's next * Automated performance tests ```sh # performance is checked manually with npx tsc --noEmit --extendedDiagnostics ``` * Need to write more examples ## License [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fpirix-gh%2Fts-toolbelt.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fpirix-gh%2Fts-toolbelt?ref=badge_large) ================================================ FILE: SECURITY.md ================================================ If you have discovered a security vulnerability, please report it via [Tidelift](https://tidelift.com/security). ================================================ FILE: package.json ================================================ { "name": "ts-toolbelt", "version": "9.6.0", "description": "TypeScript's largest utility library", "keywords": [ "safe", "tools", "types", "typesafe", "typescript" ], "homepage": "https://github.com/millsp/ts-toolbelt", "repository": { "type": "git", "url": "https://github.com/millsp/ts-toolbelt" }, "license": "Apache-2.0", "author": { "name": "Pierre-Antoine Mills", "url": "https://github.com/millsp" }, "main": "out/index.js", "types": "out/index.d.ts", "files": [ "out" ], "scripts": { "build:clean": "bash scripts/build/clean.sh", "build:code": "bash scripts/build/code.sh", "build:docs": "bash scripts/build/docs.sh", "build:types": "bash scripts/build/types.sh", "ci:branch:ad": "bash scripts/ci/branch/ad.sh", "ci:branch:bd": "bash scripts/ci/branch/bd.sh", "ci:docs:ad": "bash scripts/ci/docs/ad.sh", "ci:docs:bd": "bash scripts/ci/docs/bd.sh", "ci:master:ad": "bash scripts/ci/master/ad.sh", "ci:master:bd": "bash scripts/ci/master/bd.sh", "ci:test:ad": "bash scripts/ci/test/ad.sh", "ci:test:bd": "bash scripts/ci/test/bd.sh", "release": "bash scripts/release.sh", "test": "bash scripts/test/all.sh", "test:code": "bash scripts/test/code.sh", "test:lint": "bash scripts/test/lint.sh", "test:types": "bash scripts/test/types.sh" }, "dependencies": {}, "devDependencies": { "@commitlint/cli": "^11.0.0", "@commitlint/config-conventional": "^11.0.0", "@typescript-eslint/parser": "^4.14.0", "eledoc": "^0.2.0", "eslint": "^7.18.0", "eslint-plugin-fp": "^2.3.0", "eslint-plugin-react": "^7.22.0", "husky": "^4.3.0", "npx": "^10.2.0", "sort-package-json": "^1.48.0", "standard-version": "^9.1.0", "ts-node": "^9.1.0", "tslib": "^2.1.0", "typedoc": "^0.20.0", "typescript": "latest" } } ================================================ FILE: scripts/build/clean.sh ================================================ #!/bin/bash rm -fr out rm -fr docs ================================================ FILE: scripts/build/code.sh ================================================ #!/bin/bash mkdir -p out touch out/index.js ================================================ FILE: scripts/build/docs.sh ================================================ #!/bin/bash # creates folder if it doesn't exist yet mkdir -p docs # get the current version of the package DOCS_VERSION=$(node -p "require('./package.json').version") # force typedoc to use higher ts version rm -rf node_modules/typedoc/node_modules/typescript # !\ can cause bugs, be vigilent with it # generate docs their own version folder npx typedoc --out "docs/${DOCS_VERSION}" sources --theme node_modules/eledoc/bin/default/ && # & for github to display them correctly touch "docs/${DOCS_VERSION}/.nojekyll" ================================================ FILE: scripts/build/types.sh ================================================ #!/bin/bash mkdir -p out npx tsc sources/index.ts -d --emitDeclarationOnly --outDir out ================================================ FILE: scripts/ci/branch/ad.sh ================================================ #!/bin/bash bash ./scripts/tools/check-deploy.sh ================================================ FILE: scripts/ci/branch/bd.sh ================================================ #!/bin/bash npm run build:clean npm run build:code && npm run build:types ================================================ FILE: scripts/ci/master/ad.sh ================================================ #!/bin/bash bash ./scripts/tools/check-deploy.sh ================================================ FILE: scripts/ci/master/bd.sh ================================================ #!/bin/bash npm run build:clean npm run build:code && npm run build:types ================================================ FILE: scripts/ci/test/ad.sh ================================================ #!/bin/bash # rm -fr dt # git clone --depth=1 https://github.com/DefinitelyTyped/DefinitelyTyped.git dt && # npx ts-node scripts/tools/dt-update-version.ts && # cd dt && # git commit -am "dependents testing" && # npm i && # npm test ================================================ FILE: scripts/ci/test/bd.sh ================================================ #!/bin/bash npm run build:clean npx ts-node scripts/tools/package-test-version.ts && npm run build:code && npm run build:types ================================================ FILE: scripts/release.sh ================================================ #!/bin/bash # Make sure that we passed all tests npm run test && # Get the name of the current branch BRANCH=`git rev-parse --symbolic-full-name --abbrev-ref HEAD` && # Sort package.json, keeps neat npx sort-package-json && # check if we have to do a release RELEASE=$(node -p "require('./package.json').version.split('.')[2] === '0'") && # Publish the current branch origin if [ "$BRANCH" != "master" ]; then npx standard-version --skip.tag && # skip changelog git push origin $BRANCH # not a release else if [ "$RELEASE" = "false" ]; then npx standard-version --skip.tag && # gen changelog git push origin $BRANCH else npx standard-version && # gen changelog git push origin $BRANCH --follow-tags # only releases fi; fi; ================================================ FILE: scripts/test/all.sh ================================================ #!/bin/bash npm run test:code && npm run test:lint && npm run test:types ================================================ FILE: scripts/test/code.sh ================================================ #!/bin/bash ================================================ FILE: scripts/test/lint.sh ================================================ #!/bin/bash npx eslint 'sources/**' ================================================ FILE: scripts/test/types.sh ================================================ #!/bin/bash npx tsc --noEmit --diagnostics ================================================ FILE: scripts/tools/check-deploy.sh ================================================ #!/bin/bash sleep 60s # we'll just wait a little for it to get propagated # we replace the travis branch name with "latest" if "master" PKG_VERSTAG=$(echo ${TRAVIS_BRANCH//master/latest}) # we need to compare the current push and published versions PKG_VERSION=$(node -p "require('./package.json').version") PUB_VERSION=$(npm info .@${PKG_VERSTAG} version) if [ $PKG_VERSION != $PUB_VERSION ]; then echo exit 1 # travis has just failed the build, force to fail fi exit 0 ================================================ FILE: scripts/tools/dt-update-version.ts ================================================ import replace from './regex-update-file' replace('./dt/types', '"ts-toolbelt": ".*"', '"ts-toolbelt": "test"', [ '?.*/package.json', ], [], ) ================================================ FILE: scripts/tools/package-test-version.ts ================================================ import replace from './regex-update-file' replace('.', '"version": "(?.*)"', `"version": "-test.${Date.now()}"`, [ 'package.json', ], [], ) ================================================ FILE: scripts/tools/regex-update-file.ts ================================================ // @ts-ignore import * as fs from 'fs' // @ts-ignore import * as rl from 'readline' // regex-update-file // regex-find-file const updateMatchTo = (line: string, match: RegExp, to: string) => { const result = match.exec(line) || {groups: {}} const groups = result.groups // if user is not using groups just do if (!groups) return line.replace(match, to) Object.keys(groups).forEach((key) => { const groupMatch = new RegExp(`<${key}>`, 'gu') to = to.replace(groupMatch, groups[key]) line = line.replace(match, to) }) return line } const replaceInFile = ( file : string, path : string, match: RegExp, to : string, ) => { let content = '' let didMatch = false const filePath = `${path}/${file}` const streamFD = fs.createReadStream(filePath) rl.createInterface(streamFD). on('line', (line: string) => { if (line.match(match)) { line = updateMatchTo(line, match, to) didMatch = true } content += `${line}\n` }). on('close', () => { if (didMatch) { fs.writeFileSync(filePath, content) console.info(`wrote: ${filePath}`) } streamFD.close() }) } const isPathIncluded = ( path: string, include: string[], exclude: string[], ) => { // reduces down to `true` if a regex is a match const isExcluded = exclude.reduce((acc, val) => { return !!path.match(new RegExp(val, 'u')) || acc }, false) if (isExcluded) return false // reduces down to `true` if a regex is a match const isIncluded = include.reduce((acc, val) => { return !!path.match(new RegExp(val, 'u')) || acc }, false) return isIncluded } const replaceInDir = ( path : string, match : RegExp, replc : string, include: string[], exclude: string[], ) => fs.readdir(path, 'utf8', (error: Error, docs: string[]) => { if (error) console.error(error) else { docs.forEach((doc) => { const docPath = `${path}/${doc}` if (fs.statSync(docPath).isDirectory()) { // it is important to add `/` for the regex matching if (isPathIncluded(`${docPath}/`, include, exclude)) replaceInDir(docPath, match, replc, include, exclude) } if (fs.statSync(docPath).isFile()) { if (isPathIncluded(docPath, include, exclude)) replaceInFile(doc, path, match, replc) } }) } }) const pathToRegExp = (root: string) => (path: string) => { path = `^${root}/${path}` // // prepare insertion of different regexps // path = path.replace(/\*\*/gu, '[rec]') // .* // path = path.replace(/\*/gu, '[any]') // [\\w\\.]+ // // we do this because we can't replace '*' // // insert the regexps at their positions // path = path.replace(/\[rec\]/gu, '.*') // path = path.replace(/\[any\]/gu, '[\\w\\.]*') return `${path}$` } const paths = (paths: string[]) => { let possibilities: string[] = [] paths.forEach((path) => { possibilities = [ ...possibilities, // merge previous ...path.split('/'). // split the path // @ts-ignore map((path, index, array) => { // get combination return array.slice(0, index + 1) }). // got combinations map((splitPath, index, splitPaths) => { // put it back as path if (index < splitPaths.length - 1) // add regex `$` for all return `${splitPath.join('/')}/$` // merge string back return splitPath.join('/') // but not the last one }), ] }) return possibilities } const replace = ( path: string, match: string, replc: string, include: string[], exclude: string[], ) => { // change/map paths to string regexps include = include.map(pathToRegExp(path)) exclude = exclude.map(pathToRegExp(path)) // only the end directory is included // so the algo can't follow by default // let's include all the possible paths const pathsInclude = paths(include) const pathsExclude = paths(exclude) include = include.concat(pathsInclude) exclude = exclude.concat(pathsExclude) // console.log(include) return replaceInDir(path, new RegExp(match, 'u'), replc, include, exclude) } export default replace ================================================ FILE: sources/Any/At.ts ================================================ import {Key} from './Key' import {List} from '../List/List' /** * Get in `O` the type of a field of key `K` * @param O to extract from * @param K to extract at * @returns [[Any]] * @example * ```ts * import {O} from 'ts-toolbelt' * * type User = { * info: { * name: string * age: number * payment: {} * } * id: number * } * * type test0 = O.At // number * ``` */ export type At = A extends List ? number extends A['length'] ? K extends number | `${number}` ? A[never] | undefined : undefined : K extends keyof A ? A[K] : undefined : unknown extends A ? unknown : K extends keyof A ? A[K] : undefined; ================================================ FILE: sources/Any/Await.ts ================================================ /** * Get the result type of a `Promise` * @param P A promise * @returns [[Any]] * @example * ```ts * import {C} from 'ts-toolbelt' * * const promise = new Promise((res, rej) => res('x')) * * type test0 = C.Await // string * type test1 = C.Await> // number * ``` */ export type Await

= P extends Promise ? A : P ================================================ FILE: sources/Any/Cast.ts ================================================ /** * Ask TS to re-check that `A1` extends `A2`. * And if it fails, `A2` will be enforced anyway. * Can also be used to add constraints on parameters. * @param A1 to check against * @param A2 to cast to * @returns `A1 | A2` * @example * ```ts * import {A} from 'ts-toolbelt' * * type test0 = A.Cast<'42', string> // '42' * type test1 = A.Cast<'42', number> // number * ``` */ export type Cast = A1 extends A2 ? A1 : A2 ================================================ FILE: sources/Any/Compute.ts ================================================ import {Depth} from '../Object/_Internal' import {BuiltIn} from '../Misc/BuiltIn' import {Has} from '../Union/Has' import {If} from './If' import {Key} from './Key' /** * @hidden */ export type ComputeRaw = A extends Function ? A : {[K in keyof A]: A[K]} & unknown /** * @hidden */ type ComputeFlat = A extends BuiltIn ? A : A extends Array ? A extends Array> ? Array<{[K in keyof A[number]]: A[number][K]} & unknown> : A : A extends ReadonlyArray ? A extends ReadonlyArray> ? ReadonlyArray<{[K in keyof A[number]]: A[number][K]} & unknown> : A : {[K in keyof A]: A[K]} & unknown; /** * @hidden */ type ComputeDeep = A extends BuiltIn ? A : If, A, ( A extends Array ? A extends Array> ? Array<{[K in keyof A[number]]: ComputeDeep} & unknown> : A : A extends ReadonlyArray ? A extends ReadonlyArray> ? ReadonlyArray<{[K in keyof A[number]]: ComputeDeep} & unknown> : A : {[K in keyof A]: ComputeDeep} & unknown )>; /** * Force TS to load a type that has not been computed (to resolve composed * types that TS haven't fully resolved, for display purposes mostly). * @param A to compute * @returns `A` * @example * ```ts * import {A} from 'ts-toolbelt' * * type test0 = A.Compute<{x: 'x'} & {y: 'y'}> // {x: 'x', y: 'y'} * ``` */ export type Compute = { 'flat': ComputeFlat 'deep': ComputeDeep }[depth] ================================================ FILE: sources/Any/Contains.ts ================================================ import {Extends} from './Extends' /** * Check whether `A1` is part of `A2` or not. It works like * [[Extends]] but [[Boolean]] results are narrowed to [[False]]. * @param A1 * @param A2 * @returns [[Boolean]] * @example * ```ts * type test0 = A.Contains<'a' | 'b', 'b'> // False * type test1 = A.Contains<'a', 'a' | 'b'> // True * * type test2 = A.Contains<{a: string}, {a: string, b: number}> // False * type test3 = A.Contains<{a: string, b: number}, {a: string}> // True * * type test4 = A.Contains // False * /// Nothing cannot contain nothing, use `A.Equals` * ``` */ export type Contains = Extends extends 1 ? 1 : 0 ================================================ FILE: sources/Any/Equals.ts ================================================ /** * Check whether `A1` is equal to `A2` or not. * @param A1 * @param A2 * @returns [[Boolean]] * @example * ```ts * import {A} from 'ts-toolbelt' * * type test0 = A.Equals<42 | 0, 42 | 0> // true * type test1 = A.Equals<{a: string}, {b: string}> // false * type test3 = A.Equals<{a: string}, {readonly a: string}> // false * ``` */ export type Equals = (() => A extends A2 ? 1 : 0) extends (() => A extends A1 ? 1 : 0) ? 1 : 0 // Credit https://stackoverflow.com/a/52473108/3570903 ================================================ FILE: sources/Any/Extends.ts ================================================ /** * Check whether `A1` is part of `A2` or not. The difference with * `extends` is that it forces a [[Boolean]] return. * @param A1 * @param A2 * @returns [[Boolean]] * @example * ```ts * import {A} from 'ts-toolbelt' * * type test0 = A.Extends<'a' | 'b', 'b'> // Boolean * type test1 = A.Extends<'a', 'a' | 'b'> // True * * type test2 = A.Extends<{a: string}, {a: any}> // True * type test3 = A.Extends<{a: any}, {a: any, b: any}> // False * * type test4 = A.Extends // False * /// Nothing cannot extend nothing, use `A.Equals` * ``` */ export type Extends = [A1] extends [never] ? 0 : A1 extends A2 ? 1 : 0 /* * Comes from the fact that `never` is a fall-through type that we want to * narrow down to `0`. So it means that `Extends` is false */ ================================================ FILE: sources/Any/If.ts ================================================ import {Boolean} from '../Boolean/_Internal' export type If = B extends 1 ? Then : Else ================================================ FILE: sources/Any/Is.ts ================================================ import {Match} from './_Internal' import {Extends} from './Extends' import {Equals} from './Equals' import {Contains} from './Contains' /** * Check whether `A` is similar to `A1` or not. In other words, it is a compact * type that bundles [[Equals]], [[Extends]], [[Contains]], comparison types. * @param A to be compared * @param A1 to compare to * @param match (?=`'default'`) to change precision * @returns [[Boolean]] * @example * ```ts * import {A} from 'ts-toolbelt' * * type test0 = A.Is<'a', 'a' | 'b', 'extends->'> // True * type test1 = A.Is<'a' | 'b', 'a', 'extends->'> // Boolean * * type test2 = A.Is<'a', 'a' | 'b', '<-extends'> // Boolean * type test3 = A.Is<'a' | 'b', 'a', '<-extends'> // True * * type test4 = A.Is<'a', 'a' | 'b', 'contains->'> // True * type test5 = A.Is<'a' | 'b', 'a', 'contains->'> // False * * type test6 = A.Is<'a', 'a' | 'b', '<-contains'> // False * type test7 = A.Is<'a' | 'b', 'a', '<-contains'> // True * * type test8 = A.Is<'a', 'a' | 'b', 'equals'> // False * type test9 = A.Is<'b' |'a', 'a' | 'b', 'equals'> // True * ``` */ export type Is = { 'default' : Extends 'contains->': Contains 'extends->' : Extends '<-contains': Contains '<-extends' : Extends 'equals' : Equals }[match] ================================================ FILE: sources/Any/Key.ts ================================================ /** * Describes index keys for any type */ export type Key = string | number | symbol ================================================ FILE: sources/Any/Keys.ts ================================================ import {List} from '../List/List' /** * Get the keys of `A` * @param A * @returns [[Key]] * @example * ```ts * ``` */ export type Keys = A extends List ? Exclude | number : keyof A ================================================ FILE: sources/Any/KnownKeys.ts ================================================ import {Keys} from './Keys' /** * Get the known keys of an [[Object]] * @param O * @returns [[Key]] * @example * ```ts * ``` */ export type KnownKeys = { [K in keyof O]: string extends K ? never : number extends K ? never : K } extends { [K in keyof O]: infer U } ? U & Keys : never; ================================================ FILE: sources/Any/Promise.ts ================================================ /** * Create an asynchronous operation like the original `Promise` type but this * one prevents promises to be wrapped within more promises (not possible). * @param A * @example * ```ts * import {A} from 'ts-toolbelt' * * type test0 = A.Promise> // Promise * type test1 = Promise> // Promise> * ``` */ export type Promise = globalThis.Promise< A extends globalThis.Promise ? X : A > ================================================ FILE: sources/Any/Try.ts ================================================ /** * Similar to [[Cast]] but with a custom fallback `Catch`. If it fails, * it will enforce `Catch` instead of `A2`. * @param A1 to check against * @param A2 to try/test with * @param Catch to fallback to if the test failed * @returns `A1 | Catch` * @example * ```ts * import {A} from 'ts-toolbelt' * * type test0 = A.Try<'42', string> // '42' * type test1 = A.Try<'42', number> // never * type test1 = A.Try<'42', number, 'tried'> // 'tried' * ``` */ export type Try = A1 extends A2 ? A1 : Catch ================================================ FILE: sources/Any/Type.ts ================================================ import {Key} from './Key' declare const id: unique symbol /** * Create your own opaque sub-type from a type `A` * @param A to be personalized * @param Id to name the sub-type * @returns A new type `Type` * @example * ```ts * import {A} from 'ts-toolbelt' * * type EUR = A.Type * type USD = A.Type * * let eurWallet = 10 as EUR * let usdWallet = 15 as USD * * eurWallet = usdWallet // error * ``` */ export type Type = { [id]: Id } & A ================================================ FILE: sources/Any/_Internal.ts ================================================ /** * Describes the match strategy when matching types * * `default` : `extends->` * * `contains->` : X contains Y ([[Contains]]) * * `extends->` : X extends Y ([[Extends]]) * * `<-contains` : Y contains X ([[Contains]]) * * `<-extends` : Y extends X ([[Extends]]) * * `equals` : X equals Y (([[Equals]])) */ export type Match = | 'default' | 'contains->' | 'extends->' | '<-contains' | '<-extends' | 'equals' ================================================ FILE: sources/Any/_api.ts ================================================ /** @ignore *//** */ export {Await} from './Await' export {At} from './At' export {Cast} from './Cast' export {Compute} from './Compute' export {Contains} from './Contains' export {Equals} from './Equals' export {Extends} from './Extends' export {Key} from './Key' export {Keys} from './Keys' export {KnownKeys} from './KnownKeys' export {Is} from './Is' export {Promise} from './Promise' export {Try} from './Try' export {Type} from './Type' export {x} from './x' ================================================ FILE: sources/Any/x.ts ================================================ const _ = Symbol('x') /** * A placeholder that is used in various ways */ export type x = typeof _ & {} ================================================ FILE: sources/Boolean/And.ts ================================================ import {Boolean} from './_Internal' /** * Logical `&&` operator (behaves like the JS one) * @param B1 Left-hand side * @param B2 Right-hand side * @returns [[Boolean]] * @example * ```ts * import {B} from 'ts-toolbelt' * * type test0 = B.And // False * type test1 = B.And // True * type test2 = B.And // Boolean * ``` */ export type And = { 0: { 0: 0 1: 0 } 1: { 0: 0 1: 1 } }[B1][B2] ================================================ FILE: sources/Boolean/Not.ts ================================================ import {Boolean} from './_Internal' /** * Logical `!` operator (behaves like the JS one) * @param B to negate * @returns [[Boolean]] * @example * ```ts * import {B} from 'ts-toolbelt' * * type test0 = B.Not // False * type test1 = B.Not // True * ``` */ export type Not = { 0: 1 1: 0 }[B] ================================================ FILE: sources/Boolean/Or.ts ================================================ import {Boolean} from './_Internal' /** * Logical `||` operator (behaves like the JS one) * @param B1 Left-hand side * @param B2 Right-hand side * @returns [[Boolean]] * @example * ```ts * import {B} from 'ts-toolbelt' * * type test0 = B.Or // True * type test1 = B.Or // True * type test2 = B.Or // Boolean * ``` */ export type Or = { 0: { 0: 0 1: 1 } 1: { 0: 1 1: 1 } }[B1][B2] ================================================ FILE: sources/Boolean/Xor.ts ================================================ import {Boolean} from './_Internal' /** * Logical `^` operator (behaves like the JS one) * @param B1 Left-hand side * @param B2 Right-hand side * @returns [[Boolean]] * @example * ```ts * import {B} from 'ts-toolbelt' * * type test0 = B.Xor // False * type test1 = B.Xor // True * type test2 = B.Xor // Boolean * ``` */ export type Xor = { 0: { 0: 0 1: 1 } 1: { 0: 1 1: 0 } }[B1][B2] ================================================ FILE: sources/Boolean/_Internal.ts ================================================ export type Boolean = 0 | 1 ================================================ FILE: sources/Boolean/_api.ts ================================================ /** @ignore *//** */ export {And} from './And' export {Not} from './Not' export {Or} from './Or' export {Xor} from './Xor' ================================================ FILE: sources/Class/Class.ts ================================================ import {List} from '../List/List' /** * Alias to create/describe a `class` * @param P its constructor parameters * @param R the object it constructs * @returns `class` * @example * ```ts * import {C} from 'ts-toolbelt' * * type test0 = C.Class<[string, number], {a: string, b: number}> * * declare const SomeClass: test0 * * const obj = new SomeClass('foo', 42) // {a: string, b: number} * ``` */ export type Class

= { new (...args: P): R } ================================================ FILE: sources/Class/Instance.ts ================================================ import {Class} from './Class' /** * Get the instance type of a `class` from a class object * @param C * *typeof** class * @returns [[Object]] * @example * ```ts * import {C} from 'ts-toolbelt' * * /// `create` takes an instance constructor and creates an instance of it * declare function create any)>(c: C): C.InstanceOf * * class A {} * class B {} * * let a = create(A) // A * let b = create(B) // B * ``` */ export type Instance = C extends Class ? R : any ================================================ FILE: sources/Class/Parameters.ts ================================================ import {Class} from './Class' /** * Get the parameters of a class constructor * @param C **typeof** class * @returns [[List]] * @example * ```ts * import {C} from 'ts-toolbelt' * * type User = C.Class<[string, string], {firstname: string, lastname: string}> * * type test0 = C.Parameters // [string, string] * ``` */ export type Parameters = C extends Class ? P : never ================================================ FILE: sources/Class/_api.ts ================================================ /** @ignore *//** */ export {Class} from './Class' export {Instance} from './Instance' export {Parameters} from './Parameters' ================================================ FILE: sources/Community/IncludesDeep.ts ================================================ import {Match} from '../Any/_Internal' import {UnionOf} from '../Object/UnionOf' import {Next} from '../Iteration/Next' import {Prev} from '../Iteration/Prev' import {Iteration} from '../Iteration/Iteration' import {IterationOf} from '../Iteration/IterationOf' import {Is} from '../Any/Is' import {Boolean} from '../Boolean/_Internal' import {Cast} from '../Any/Cast' import {Pos} from '../Iteration/Pos' /** * @hidden */ type _IncludesDeep> = { 0: _IncludesDeep : O, M, match, limit, Next> 1: 1 2: 0 }[ Pos> extends limit // if we go past the limit ? 2 // end the loop here : Is // if 0 => continue, if 1 => end ] /** * Check whether `O`, or its sub-objects have fields that match `M` * where the maximum allowed depth is set with `limit`. * * @param O to be inspected * @param M to check field type * @param match (?=`'default'`) to change precision * @param limit (?=`'10'`) to change the check depth * @returns [[Boolean]] * @example * ```ts * ``` * @author millsp, ctrlplusb */ export type IncludesDeep = _IncludesDeep extends infer X ? Cast : never ================================================ FILE: sources/Community/IsLiteral.ts ================================================ import {And} from '../Boolean/And' import {Or} from '../Boolean/Or' import {Extends} from '../Any/Extends' /** * @hidden */ export type IsStringLiteral = A extends string ? string extends A ? 0 : 1 : 0 /** * @hidden */ export type IsNumberLiteral = A extends number ? number extends A ? 0 : 1 : 0 /** * Literal to restrict against */ export type Kind = string | number /** * Determine whether `A` is literal or not * @param A to be checked * @param kind (?=`'string' | 'number'`) to restrict * @example * ```ts * import {A} from 'ts-toolbelt' * * type test0 = A.IsLiteral<1 | 2> // 1 * type test1 = A.IsLiteral<1 | 2, string> // 0 * type test2 = A.IsLiteral<1 | '2', string> // 0 | 1 * type test3 = A.IsLiteral // 0 * ``` */ export type IsLiteral = And, IsNumberLiteral>, Extends> ================================================ FILE: sources/Community/_api.ts ================================================ /** @ignore *//** */ export {IncludesDeep} from './IncludesDeep' export {IsLiteral} from './IsLiteral' ================================================ FILE: sources/Function/AutoPath.ts ================================================ import {Key} from '../Any/Key' import {Head} from '../List/Head' import {List} from '../List/List' import {Pop} from '../List/Pop' import {Tail} from '../List/Tail' import {Path} from '../Object/Path' import {UnionOf} from '../Object/UnionOf' import {Select} from '../Union/Select' import {Join} from '../String/Join' import {Split} from '../String/Split' /** * @ignore */ type Index = number | string; /** * @ignore */ type KeyToIndex> = number extends K ? Head : K & Index; /** * @ignore */ type MetaPath = [], P extends List = []> = { [K in keyof O]: | MetaPath, [...P, KeyToIndex]> | Join<[...P, KeyToIndex], D>; }; /** * @ignore */ type NextPath = // the next paths after property `K` are on sub objects // O[K] === K | {x: '${K}.x' | {y: '${K}.x.y' ...}} // So we access O[K] then we only keep the next paths // To do this, we can just exclude `string` out of it: // O[K] === {x: '${K}.x' | {y: '${K}.x.y' ...}} // To do this, we create a union of what we just got // This will yield a union of paths and meta paths // We exclude the next paths (meta) paths by excluding // `object`. Then we are left with the direct next path Select & {}>, string>; /** * @ignore */ type ExecPath, Delimiter extends string> = // We go in the `MetaPath` of `O` to get the prop at `SP` // So we query what is going the `NextPath` at `O[...SP]` NextPath, SP>>; /** * @ignore */ type HintPath, Exec extends string, D extends string> = [Exec] extends [never] // if has not found paths ? ExecPath, D> // display previous paths : Exec | P; // display current + next /** * @ignore */ type _AutoPath = Split> = HintPath, D>; /** * Auto-complete, validate, and query the string path of an object `O` * @param O to work on * @param P path of `O` * @param D (?=`'.'`) delimiter for path * * ```ts * declare function get( * object: O, path: AutoPath * ): Path> * * declare const user: User * * type User = { * name: string * friends: User[] * } * * // works * const friendName = get(user, 'friends.40.name') * const friendFriendName = get(user, 'friends.40.friends.12.name') * * // errors * const friendNames = get(user, 'friends.40.names') * const friendFriendNames = get(user, 'friends.40.friends.12.names') * ``` */ export type AutoPath = _AutoPath; ================================================ FILE: sources/Function/Compose/List/Async.ts ================================================ /** @ignore *//** */ import {Function} from '../../Function' import {Await} from '../../../Any/Await' import {Curry} from '../../Curry' /** *@hidden */ export type ComposeListAsync = { < R0, P extends any[], >(fns: [ Function | Curry>, ]): Function>> < R0, R1, P extends any[], >(fns: [ Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, P extends any[], >(fns: [ Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, P extends any[], >(fns: [ Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, R4, P extends any[], >(fns: [ Function<[Await], R4> | Curry], R4>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, R4, R5, P extends any[], >(fns: [ Function<[Await], R5> | Curry], R5>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, P extends any[], >(fns: [ Function<[Await], R6> | Curry], R6>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, R7, P extends any[], >(fns: [ Function<[Await], R7> | Curry], R7>>, Function<[Await], R6> | Curry], R6>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, R7, R8, P extends any[], >(fns: [ Function<[Await], R8> | Curry], R8>>, Function<[Await], R7> | Curry], R7>>, Function<[Await], R6> | Curry], R6>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, P extends any[], >(fns: [ Function<[Await], R9> | Curry], R9>>, Function<[Await], R8> | Curry], R8>>, Function<[Await], R7> | Curry], R7>>, Function<[Await], R6> | Curry], R6>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> } ================================================ FILE: sources/Function/Compose/List/Sync.ts ================================================ /** @ignore *//** */ import {Curry} from '../../Curry' import {Function} from '../../Function' /** *@hidden */ export type ComposeListSync = { < R0, P extends any[], >(fns: [ Function | Curry>, ]): Function < R0, R1, P extends any[], >(fns: [ Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, P extends any[], >(fns: [ Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, P extends any[], >(fns: [ Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, R4, P extends any[], >(fns: [ Function<[R3], R4> | Curry>, Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, P extends any[], >(fns: [ Function<[R4], R5> | Curry>, Function<[R3], R4> | Curry>, Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, P extends any[], >(fns: [ Function<[R5], R6> | Curry>, Function<[R4], R5> | Curry>, Function<[R3], R4> | Curry>, Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, R7, P extends any[], >(fns: [ Function<[R6], R7> | Curry>, Function<[R5], R6> | Curry>, Function<[R4], R5> | Curry>, Function<[R3], R4> | Curry>, Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, R7, R8, P extends any[], >(fns: [ Function<[R7], R8> | Curry>, Function<[R6], R7> | Curry>, Function<[R5], R6> | Curry>, Function<[R4], R5> | Curry>, Function<[R3], R4> | Curry>, Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, P extends any[], >(fns: [ Function<[R8], R9> | Curry>, Function<[R7], R8> | Curry>, Function<[R6], R7> | Curry>, Function<[R5], R6> | Curry>, Function<[R4], R5> | Curry>, Function<[R3], R4> | Curry>, Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function } ================================================ FILE: sources/Function/Compose/Multi/Async.ts ================================================ /** @ignore *//** */ import {Function} from '../../Function' import {Await} from '../../../Any/Await' import {Curry} from '../../Curry' /** *@hidden */ export type ComposeMultiAsync = { < R0, P extends any[], >(...fns: [ Function | Curry>, ]): Function>> < R0, R1, P extends any[], >(...fns: [ Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, P extends any[], >(...fns: [ Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, P extends any[], >(...fns: [ Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, R4, P extends any[], >(...fns: [ Function<[Await], R4> | Curry], R4>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, R4, R5, P extends any[], >(...fns: [ Function<[Await], R5> | Curry], R5>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, P extends any[], >(...fns: [ Function<[Await], R6> | Curry], R6>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, R7, P extends any[], >(...fns: [ Function<[Await], R7> | Curry], R7>>, Function<[Await], R6> | Curry], R6>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, R7, R8, P extends any[], >(...fns: [ Function<[Await], R8> | Curry], R8>>, Function<[Await], R7> | Curry], R7>>, Function<[Await], R6> | Curry], R6>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, P extends any[], >(...fns: [ Function<[Await], R9> | Curry], R9>>, Function<[Await], R8> | Curry], R8>>, Function<[Await], R7> | Curry], R7>>, Function<[Await], R6> | Curry], R6>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R1> | Curry], R1>>, Function | Curry>, ]): Function>> } ================================================ FILE: sources/Function/Compose/Multi/Sync.ts ================================================ /** @ignore *//** */ import {Curry} from '../../Curry' import {Function} from '../../Function' /** *@hidden */ export type ComposeMultiSync = { < R0, P extends any[], >(...fns: [ Function | Curry>, ]): Function < R0, R1, P extends any[], >(...fns: [ Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, P extends any[], >(...fns: [ Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, P extends any[], >(...fns: [ Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, R4, P extends any[], >(...fns: [ Function<[R3], R4> | Curry>, Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, P extends any[], >(...fns: [ Function<[R4], R5> | Curry>, Function<[R3], R4> | Curry>, Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, P extends any[], >(...fns: [ Function<[R5], R6> | Curry>, Function<[R4], R5> | Curry>, Function<[R3], R4> | Curry>, Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, R7, P extends any[], >(...fns: [ Function<[R6], R7> | Curry>, Function<[R5], R6> | Curry>, Function<[R4], R5> | Curry>, Function<[R3], R4> | Curry>, Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, R7, R8, P extends any[], >(...fns: [ Function<[R7], R8> | Curry>, Function<[R6], R7> | Curry>, Function<[R5], R6> | Curry>, Function<[R4], R5> | Curry>, Function<[R3], R4> | Curry>, Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, P extends any[], >(...fns: [ Function<[R8], R9> | Curry>, Function<[R7], R8> | Curry>, Function<[R6], R7> | Curry>, Function<[R5], R6> | Curry>, Function<[R4], R5> | Curry>, Function<[R3], R4> | Curry>, Function<[R2], R3> | Curry>, Function<[R1], R2> | Curry>, Function<[R0], R1> | Curry>, Function | Curry>, ]): Function } ================================================ FILE: sources/Function/Compose.ts ================================================ import {IntersectOf} from '../Union/IntersectOf' import {ComposeListAsync} from './Compose/List/Async' import {ComposeListSync} from './Compose/List/Sync' import {ComposeMultiAsync} from './Compose/Multi/Async' import {ComposeMultiSync} from './Compose/Multi/Sync' import {Input, Mode} from './_Internal' /** * Compose [[Function]]s together * @param mode (?=`'sync'`) sync/async (this depends on your implementation) * @param input (?=`'multi'`) whether you want it to take a list or parameters * @example * ```ts * import {F} from 'ts-toolbelt' * * /// If you are looking for creating types for `compose` * /// `Composer` will check for input & `Compose` the output * declare const compose: F.Compose * * const a = (a1: number) => `${a1}` * const c = (c1: string[]) => [c1] * const b = (b1: string) => [b1] * * compose(c, b, a)(42) * * /// And if you are looking for an async `compose` type * declare const compose: F.Compose<'async'> * * const a = async (a1: number) => `${a1}` * const b = async (b1: string) => [b1] * const c = async (c1: string[]) => [c1] * * await compose(c, b, a)(42) */ export type Compose = IntersectOf<{ 'sync' : { 'multi': ComposeMultiSync 'list' : ComposeListSync } 'async': { 'multi': ComposeMultiAsync 'list' : ComposeListAsync } }[mode][input]> // `IntersectOf` in case of unions ================================================ FILE: sources/Function/Curry.ts ================================================ import {Pos} from '../Iteration/Pos' import {Concat} from '../List/Concat' import {Length} from '../List/Length' import {Next} from '../Iteration/Next' import {Cast} from '../Any/Cast' import {Parameters} from './Parameters' import {Return} from './Return' import {IterationOf} from '../Iteration/IterationOf' import {Iteration} from '../Iteration/Iteration' import {NonNullableFlat} from '../Object/NonNullable' import {x} from '../Any/x' import {List} from '../List/List' import {Function} from './Function' import {Extends} from '../Any/Extends' import {Tail} from '../List/Tail' import {RequiredKeys} from '../List/RequiredKeys' /** * @hidden */ type _SplitParams

> = { 0: P extends [...infer A, ...PRest] ? _SplitParams, [...PSplit, A], Tail> : never 1: PSplit 2: P[number][][] }[ number extends Length

? 2 : P extends [] ? 1 : 0 ] /** * Splits tuples to preserve their labels * @hidden */ type SplitParams

= _SplitParams

extends infer X ? Cast : never /** * @hidden */ type _JoinParams = { 0: _JoinParams, [...L, ...PSplit[0]]> 1: L 2: PSplit[number][] }[ number extends Length ? 2 : PSplit extends [] ? 1 : 0 ] /** * Undoes the job of [[SplitParams]] * @hidden */ type JoinParams

= _JoinParams

extends infer X ? Cast : never /** * @hidden */ type GapOf = L1[Pos] extends x ? Concat]> : LN /** * @hidden */ type _GapsOf> = { 0: _GapsOf, Tail, Next> 1: Concat> }[Extends, Length>] /** * @hidden */ type GapsOf = _GapsOf> extends infer X ? Cast : never /** * @hidden */ type Gaps = Cast, List> /** * Curry a [[Function]] * @param F to curry * @returns [[Function]] * @example * ```ts * import {F} from 'ts-toolbelt' * * /// If you are looking for creating types for `curry` * /// It handles placeholders and variable arguments * declare function curry(fn: Fn): F.Curry * ``` */ export type Curry = < P extends Gaps>, G extends List = GapsOf>, R extends any = Return >(...p: Gaps> | P) => // handles optional parameters RequiredKeys extends never ? R : Curry<(...p: G) => R> ================================================ FILE: sources/Function/Exact.ts ================================================ import {Narrowable} from './_Internal' /** * Force `A` to comply with `W`. `A` must be a shape of `W`. In other words, `A` * must extend `W` and have the same properties - no more, no less. * @param A * @param W */ type Exact = W extends unknown ? A extends W ? A extends Narrowable ? A : { [K in keyof A]: K extends keyof W ? Exact : never } : W : never; export {Exact} ================================================ FILE: sources/Function/Function.ts ================================================ import {List} from '../List/List' /** * Alias to create a [[Function]] * @param P parameters * @param R return type * @returns [[Function]] * @example * ```ts * import {F} from 'ts-toolbelt' * * type test0 = F.Function<[string, number], boolean> * /// (args_0: string, args_1: number) => boolean * ``` */ export type Function

= (...args: P) => R ================================================ FILE: sources/Function/Length.ts ================================================ import {Function} from './Function' import {Parameters} from './Parameters' import {Length as LLength} from '../List/Length' /** * Extract arguments' length from a [[Function]] * @param F to extract from * @returns [[String]] or `number` * @example * ```ts * import {F} from 'ts-toolbelt' * * const fn = (a1: any, a2: any) => {} * * type test0 = F.LengthOf // 2 * * type test1 = F.LengthOf<(a1?: any) => any> // 0 | 1 * * type test2 = F.LengthOf<(...a: any[]) => any> // number * ``` */ export type Length = LLength> ================================================ FILE: sources/Function/Narrow.ts ================================================ import {Try} from '../Any/Try' import {Narrowable} from './_Internal' /** * @hidden */ type NarrowRaw = | (A extends [] ? [] : never) | (A extends Narrowable ? A : never) | ({[K in keyof A]: A[K] extends Function ? A[K] : NarrowRaw}); /** * Prevent type widening on generic function parameters * @param A to narrow * @returns `A` * @example * ```ts * import {F} from 'ts-toolbelt' * * declare function foo(x: F.Narrow): A; * declare function bar(x: F.Narrow): A; * * const test0 = foo(['e', 2, true, {f: ['g', ['h']]}]) * // `A` inferred : ['e', 2, true, {f: ['g']}] * * const test1 = bar({a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]}) * // `A` inferred : {a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]} * ``` */ type Narrow = Try> export {Narrow} ================================================ FILE: sources/Function/NoInfer.ts ================================================ /** * Explain to TS which function parameter has priority for generic inference * @param A to de-prioritize * @returns `A` * @example * ```ts * import {F} from 'ts-toolbelt' * * const fn0 = (a0: A, a1: F.NoInfer): A => { * return {} as unknown as A // just for the example * } * * const fn1 = (a0: F.NoInfer, a1: A): A => { * return {} as unknown as A // just for the example * } * * const fn2 = (a0: F.NoInfer, a1: F.NoInfer): A => { * return {} as unknown as A // just for the example * } * * const test0 = fn0('b', 'a') // error: infer priority is `a0` * const test1 = fn1('b', 'a') // error: infer priority is `a1` * const test2 = fn2('b', 'a') // works: infer priority is `a0` | `a1` * ``` * @see https://stackoverflow.com/questions/56687668 */ export type NoInfer = [A][A extends any ? 0 : never] /* * https://github.com/microsoft/TypeScript/issues/14829#issuecomment-322267089 * https://stackoverflow.com/questions/56687668 */ ================================================ FILE: sources/Function/Parameters.ts ================================================ import {Function} from './Function' /** * Extract parameters from a [[Function]] * @param F to extract from * @returns [[List]] * @example * ```ts * import {F} from 'ts-toolbelt' * * const fn = (name: string, age: number) => {} * * type test0 = F.ParamsOf // [string, number] * * type test1 = F.ParamsOf<(name: string, age: number) => {}> // [string, number] * ``` */ export type Parameters = F extends ((...args: infer L) => any) ? L : never ================================================ FILE: sources/Function/Pipe/List/Async.ts ================================================ /** @ignore *//** */ import {Function} from '../../Function' import {Await} from '../../../Any/Await' import {Curry} from '../../Curry' /** *@hidden */ export type PipeListAsync = { < R0, P extends any[], >(fns: [ Function | Curry>, ]): Function>> < R0, R1, P extends any[], >(fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, ]): Function>> < R0, R1, R2, P extends any[], >(fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, ]): Function>> < R0, R1, R2, R3, P extends any[], >(fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, ]): Function>> < R0, R1, R2, R3, R4, P extends any[], >(fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R4> | Curry], R4>>, ]): Function>> < R0, R1, R2, R3, R4, R5, P extends any[], >(fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R5> | Curry], R5>>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, P extends any[], >(fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R6> | Curry], R6>>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, R7, P extends any[], >(fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R6> | Curry], R6>>, Function<[Await], R7> | Curry], R7>>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, R7, R8, P extends any[], >(fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R6> | Curry], R6>>, Function<[Await], R7> | Curry], R7>>, Function<[Await], R8> | Curry], R8>>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, P extends any[], >(fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R6> | Curry], R6>>, Function<[Await], R7> | Curry], R7>>, Function<[Await], R8> | Curry], R8>>, Function<[Await], R9> | Curry], R9>>, ]): Function>> } ================================================ FILE: sources/Function/Pipe/List/Sync.ts ================================================ /** @ignore *//** */ import {Curry} from '../../Curry' import {Function} from '../../Function' /** *@hidden */ export type PipeListSync = { < R0, P extends any[], >(fns: [ Function | Curry>, ]): Function < R0, R1, P extends any[], >(fns: [ Function | Curry>, Function<[R0], R1> | Curry>, ]): Function < R0, R1, R2, P extends any[], >(fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, ]): Function < R0, R1, R2, R3, P extends any[], >(fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, ]): Function < R0, R1, R2, R3, R4, P extends any[], >(fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, Function<[R3], R4> | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, P extends any[], >(fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, Function<[R3], R4> | Curry>, Function<[R4], R5> | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, P extends any[], >(fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, Function<[R3], R4> | Curry>, Function<[R4], R5> | Curry>, Function<[R5], R6> | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, R7, P extends any[], >(fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, Function<[R3], R4> | Curry>, Function<[R4], R5> | Curry>, Function<[R5], R6> | Curry>, Function<[R6], R7> | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, R7, R8, P extends any[], >(fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, Function<[R3], R4> | Curry>, Function<[R4], R5> | Curry>, Function<[R5], R6> | Curry>, Function<[R6], R7> | Curry>, Function<[R7], R8> | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, P extends any[], >(fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, Function<[R3], R4> | Curry>, Function<[R4], R5> | Curry>, Function<[R5], R6> | Curry>, Function<[R6], R7> | Curry>, Function<[R7], R8> | Curry>, Function<[R8], R9> | Curry>, ]): Function } ================================================ FILE: sources/Function/Pipe/Multi/Async.ts ================================================ /** @ignore *//** */ import {Function} from '../../Function' import {Await} from '../../../Any/Await' import {Curry} from '../../Curry' /** *@hidden */ export type PipeMultiAsync = { < R0, P extends any[], >(...fns: [ Function | Curry>, ]): Function>> < R0, R1, P extends any[], >(...fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, ]): Function>> < R0, R1, R2, P extends any[], >(...fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, ]): Function>> < R0, R1, R2, R3, P extends any[], >(...fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, ]): Function>> < R0, R1, R2, R3, R4, P extends any[], >(...fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R4> | Curry], R4>>, ]): Function>> < R0, R1, R2, R3, R4, R5, P extends any[], >(...fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R5> | Curry], R5>>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, P extends any[], >(...fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R6> | Curry], R6>>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, R7, P extends any[], >(...fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R6> | Curry], R6>>, Function<[Await], R7> | Curry], R7>>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, R7, R8, P extends any[], >(...fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R6> | Curry], R6>>, Function<[Await], R7> | Curry], R7>>, Function<[Await], R8> | Curry], R8>>, ]): Function>> < R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, P extends any[], >(...fns: [ Function | Curry>, Function<[Await], R1> | Curry], R1>>, Function<[Await], R2> | Curry], R2>>, Function<[Await], R3> | Curry], R3>>, Function<[Await], R4> | Curry], R4>>, Function<[Await], R5> | Curry], R5>>, Function<[Await], R6> | Curry], R6>>, Function<[Await], R7> | Curry], R7>>, Function<[Await], R8> | Curry], R8>>, Function<[Await], R9> | Curry], R9>>, ]): Function>> } ================================================ FILE: sources/Function/Pipe/Multi/Sync.ts ================================================ /** @ignore *//** */ import {Curry} from '../../Curry' import {Function} from '../../Function' /** *@hidden */ export type PipeMultiSync = { < R0, P extends any[], >(...fns: [ Function | Curry>, ]): Function < R0, R1, P extends any[], >(...fns: [ Function | Curry>, Function<[R0], R1> | Curry>, ]): Function < R0, R1, R2, P extends any[], >(...fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, ]): Function < R0, R1, R2, R3, P extends any[], >(...fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, ]): Function < R0, R1, R2, R3, R4, P extends any[], >(...fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, Function<[R3], R4> | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, P extends any[], >(...fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, Function<[R3], R4> | Curry>, Function<[R4], R5> | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, P extends any[], >(...fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, Function<[R3], R4> | Curry>, Function<[R4], R5> | Curry>, Function<[R5], R6> | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, R7, P extends any[], >(...fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, Function<[R3], R4> | Curry>, Function<[R4], R5> | Curry>, Function<[R5], R6> | Curry>, Function<[R6], R7> | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, R7, R8, P extends any[], >(...fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, Function<[R3], R4> | Curry>, Function<[R4], R5> | Curry>, Function<[R5], R6> | Curry>, Function<[R6], R7> | Curry>, Function<[R7], R8> | Curry>, ]): Function < R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, P extends any[], >(...fns: [ Function | Curry>, Function<[R0], R1> | Curry>, Function<[R1], R2> | Curry>, Function<[R2], R3> | Curry>, Function<[R3], R4> | Curry>, Function<[R4], R5> | Curry>, Function<[R5], R6> | Curry>, Function<[R6], R7> | Curry>, Function<[R7], R8> | Curry>, Function<[R8], R9> | Curry>, ]): Function } ================================================ FILE: sources/Function/Pipe.ts ================================================ import {IntersectOf} from '../Union/IntersectOf' import {PipeListAsync} from './Pipe/List/Async' import {PipeListSync} from './Pipe/List/Sync' import {PipeMultiAsync} from './Pipe/Multi/Async' import {PipeMultiSync} from './Pipe/Multi/Sync' import {Input, Mode} from './_Internal' /** * Pipe [[Function]]s together * @param mode (?=`'sync'`) sync/async (this depends on your implementation) * @param input (?=`'multi'`) whether you want to take a list or multiple parameters * @returns [[Function]] * @example * ```ts * import {F} from 'ts-toolbelt' * * /// If you are looking for creating types for `pipe`: * declare const pipe: F.Pipe * * const a = (a1: number) => `${a1}` * const b = (b1: string) => [b1] * const c = (c1: string[]) => [c1] * * pipe(a, b, c)(42) * * /// And if you are looking for an async `pipe` type: * declare const pipe: F.Pipe<'async'> * * const a = async (a1: number) => `${a1}` * const b = async (b1: string) => [b1] * const c = async (c1: string[]) => [c1] * * await pipe(a, b, c)(42) * ``` */ export type Pipe = IntersectOf<{ 'sync' : { 'multi': PipeMultiSync 'list' : PipeListSync } 'async': { 'multi': PipeMultiAsync 'list' : PipeListAsync } }[mode][input]> // `IntersectOf` in case of unions ================================================ FILE: sources/Function/Promisify.ts ================================================ import {Function} from './Function' import {Parameters} from './Parameters' import {Return} from './Return' import {Promise} from '../Any/Promise' /** * Creates a promisified version of a `Function` `F` * @param F to promisify * @returns async F * @example * ```ts * import {F} from 'ts-toolbelt' * * type test0 = F.Promisify<(a: number) => number> // (a: number) => Promise * ``` */ export type Promisify = (...args: Parameters) => Promise> ================================================ FILE: sources/Function/Return.ts ================================================ import {Function} from './Function' import {List} from '../List/List' /** * Extract the return type of a [[Function]] * @param F to extract from * @returns [[Any]] * @example * ```ts * import {F} from 'ts-toolbelt' * * const fn = () => true * * type test0 = F.ReturnOf // boolean * * type test1 = F.ReturnOf<() => true> // true * ``` */ export type Return = F extends ((...args: List) => infer R) ? R : never ================================================ FILE: sources/Function/UnCurry.ts ================================================ import {Curry} from './Curry' /** * Undoes the work that was done by [[Curry]] * @param F to uncurry * @returns [[Function]] * @example * ```ts * import {F} from 'ts-toolbelt' * * type test0 = F.Curry<(a: string, b: number) => boolean> * declare const foo: test0 * const res0 = foo('a') // F.Curry<(b: number) => boolean> & ((b: number) => boolean) * * type test1 = F.UnCurry // (a: string, b: number) => boolean * declare const bar: test1 * const res1 = bar('a') // TS2554: Expected 2 arguments, but got 1. * ``` * @ignore */ export type UnCurry> = F extends Curry ? UF : never ================================================ FILE: sources/Function/ValidPath.ts ================================================ import {IterationOf} from '../Iteration/IterationOf' import {Iteration} from '../Iteration/Iteration' import {Next} from '../Iteration/Next' import {Pos} from '../Iteration/Pos' import {At} from '../Any/At' import {Cast} from '../Any/Cast' import {NonNullable} from '../Union/NonNullable' import {Update} from '../List/Update' import {Key} from '../Iteration/Key' import {Key as AKey} from '../Any/Key' import {List} from '../List/List' import {Length} from '../List/Length' import {Extends} from '../Any/Extends' /** * @hidden */ type ValidatePath, I extends Iteration> = Update< Path, Key, [At]>] extends [never] ? keyof O : Path[Pos] > /** * @hidden */ type __ValidPath, I extends Iteration = IterationOf<0>> = { 0: __ValidPath]>>, ValidatePath, Next> 1: Path }[Extends, Length>] /** * @hidden */ export type _ValidPath> = __ValidPath extends infer X ? Cast> : never /** * Replaces invalid parts of a path with `never` * @param O to be inspected * @param Path to be validated * @returns [[Index]][] * @example * ```ts * import {A, L, O} from 'ts-toolbelt' * * // Get a property in an object `o` at any depth with `path` * // `A.Cast>` makes sure `path` is valid * const getAt = < * O extends object, * P extends L.List * >(o: O, path: A.Cast>): O.Path => { * let valueAt = o * * for (const p of path) * valueAt = valueAt[p] * * return valueAt as any * } * * const test0 = getAt({a: {b: {c: 1}}}, ['a', 'b'] as const) // {c: number} * const test1 = getAt({a: {b: {c: 1}}} as const, ['a', 'b'] as const) // {c: 1} * const test2 = getAt({a: {b: {c: 1}}}, ['x'] as const) // error * ``` */ export type ValidPath> = O extends unknown ? Path extends unknown ? _ValidPath : never : never ================================================ FILE: sources/Function/_Internal.ts ================================================ /** * Describes function modes * `sync` : Normal function * `async`: Promised result */ export type Mode = 'sync' | 'async' /** * Describes function parameter input * `multi`: ( a, b, c ... n ) => X * `list` : ([a, b, c ... n]) => X */ export type Input = 'multi' | 'list' /** * Describes types that can be narrowed */ export type Narrowable = | string | number | bigint | boolean ================================================ FILE: sources/Function/_api.ts ================================================ /** @ignore *//** */ export {AutoPath} from './AutoPath' export {Compose} from './Compose' export {Exact} from './Exact' export {Curry} from './Curry' export {Function} from './Function' export {Narrow} from './Narrow' export {Length} from './Length' export {NoInfer} from './NoInfer' export {Parameters} from './Parameters' export {Pipe} from './Pipe' export {Promisify} from './Promisify' export {Return} from './Return' export {UnCurry} from './UnCurry' export {ValidPath} from './ValidPath' ================================================ FILE: sources/Iteration/Iteration.ts ================================================ /** * An entry of `IterationMap` */ export type Iteration = [ value: number, sign: '-' | '0' | '+', prev: keyof IterationMap, next: keyof IterationMap, oppo: keyof IterationMap, ] export type IterationMap = { '__': [number, '-' | '0' | '+', '__', '__', '__'], '-100': [-100, '-', '__', '-99', '100'], '-99': [-99, '-', '-100', '-98', '99'], '-98': [-98, '-', '-99', '-97', '98'], '-97': [-97, '-', '-98', '-96', '97'], '-96': [-96, '-', '-97', '-95', '96'], '-95': [-95, '-', '-96', '-94', '95'], '-94': [-94, '-', '-95', '-93', '94'], '-93': [-93, '-', '-94', '-92', '93'], '-92': [-92, '-', '-93', '-91', '92'], '-91': [-91, '-', '-92', '-90', '91'], '-90': [-90, '-', '-91', '-89', '90'], '-89': [-89, '-', '-90', '-88', '89'], '-88': [-88, '-', '-89', '-87', '88'], '-87': [-87, '-', '-88', '-86', '87'], '-86': [-86, '-', '-87', '-85', '86'], '-85': [-85, '-', '-86', '-84', '85'], '-84': [-84, '-', '-85', '-83', '84'], '-83': [-83, '-', '-84', '-82', '83'], '-82': [-82, '-', '-83', '-81', '82'], '-81': [-81, '-', '-82', '-80', '81'], '-80': [-80, '-', '-81', '-79', '80'], '-79': [-79, '-', '-80', '-78', '79'], '-78': [-78, '-', '-79', '-77', '78'], '-77': [-77, '-', '-78', '-76', '77'], '-76': [-76, '-', '-77', '-75', '76'], '-75': [-75, '-', '-76', '-74', '75'], '-74': [-74, '-', '-75', '-73', '74'], '-73': [-73, '-', '-74', '-72', '73'], '-72': [-72, '-', '-73', '-71', '72'], '-71': [-71, '-', '-72', '-70', '71'], '-70': [-70, '-', '-71', '-69', '70'], '-69': [-69, '-', '-70', '-68', '69'], '-68': [-68, '-', '-69', '-67', '68'], '-67': [-67, '-', '-68', '-66', '67'], '-66': [-66, '-', '-67', '-65', '66'], '-65': [-65, '-', '-66', '-64', '65'], '-64': [-64, '-', '-65', '-63', '64'], '-63': [-63, '-', '-64', '-62', '63'], '-62': [-62, '-', '-63', '-61', '62'], '-61': [-61, '-', '-62', '-60', '61'], '-60': [-60, '-', '-61', '-59', '60'], '-59': [-59, '-', '-60', '-58', '59'], '-58': [-58, '-', '-59', '-57', '58'], '-57': [-57, '-', '-58', '-56', '57'], '-56': [-56, '-', '-57', '-55', '56'], '-55': [-55, '-', '-56', '-54', '55'], '-54': [-54, '-', '-55', '-53', '54'], '-53': [-53, '-', '-54', '-52', '53'], '-52': [-52, '-', '-53', '-51', '52'], '-51': [-51, '-', '-52', '-50', '51'], '-50': [-50, '-', '-51', '-49', '50'], '-49': [-49, '-', '-50', '-48', '49'], '-48': [-48, '-', '-49', '-47', '48'], '-47': [-47, '-', '-48', '-46', '47'], '-46': [-46, '-', '-47', '-45', '46'], '-45': [-45, '-', '-46', '-44', '45'], '-44': [-44, '-', '-45', '-43', '44'], '-43': [-43, '-', '-44', '-42', '43'], '-42': [-42, '-', '-43', '-41', '42'], '-41': [-41, '-', '-42', '-40', '41'], '-40': [-40, '-', '-41', '-39', '40'], '-39': [-39, '-', '-40', '-38', '39'], '-38': [-38, '-', '-39', '-37', '38'], '-37': [-37, '-', '-38', '-36', '37'], '-36': [-36, '-', '-37', '-35', '36'], '-35': [-35, '-', '-36', '-34', '35'], '-34': [-34, '-', '-35', '-33', '34'], '-33': [-33, '-', '-34', '-32', '33'], '-32': [-32, '-', '-33', '-31', '32'], '-31': [-31, '-', '-32', '-30', '31'], '-30': [-30, '-', '-31', '-29', '30'], '-29': [-29, '-', '-30', '-28', '29'], '-28': [-28, '-', '-29', '-27', '28'], '-27': [-27, '-', '-28', '-26', '27'], '-26': [-26, '-', '-27', '-25', '26'], '-25': [-25, '-', '-26', '-24', '25'], '-24': [-24, '-', '-25', '-23', '24'], '-23': [-23, '-', '-24', '-22', '23'], '-22': [-22, '-', '-23', '-21', '22'], '-21': [-21, '-', '-22', '-20', '21'], '-20': [-20, '-', '-21', '-19', '20'], '-19': [-19, '-', '-20', '-18', '19'], '-18': [-18, '-', '-19', '-17', '18'], '-17': [-17, '-', '-18', '-16', '17'], '-16': [-16, '-', '-17', '-15', '16'], '-15': [-15, '-', '-16', '-14', '15'], '-14': [-14, '-', '-15', '-13', '14'], '-13': [-13, '-', '-14', '-12', '13'], '-12': [-12, '-', '-13', '-11', '12'], '-11': [-11, '-', '-12', '-10', '11'], '-10': [-10, '-', '-11', '-9', '10'], '-9': [-9, '-', '-10', '-8', '9'], '-8': [-8, '-', '-9', '-7', '8'], '-7': [-7, '-', '-8', '-6', '7'], '-6': [-6, '-', '-7', '-5', '6'], '-5': [-5, '-', '-6', '-4', '5'], '-4': [-4, '-', '-5', '-3', '4'], '-3': [-3, '-', '-4', '-2', '3'], '-2': [-2, '-', '-3', '-1', '2'], '-1': [-1, '-', '-2', '0', '1'], '0': [0, '0', '-1', '1', '0'], '1': [1, '+', '0', '2', '-1'], '2': [2, '+', '1', '3', '-2'], '3': [3, '+', '2', '4', '-3'], '4': [4, '+', '3', '5', '-4'], '5': [5, '+', '4', '6', '-5'], '6': [6, '+', '5', '7', '-6'], '7': [7, '+', '6', '8', '-7'], '8': [8, '+', '7', '9', '-8'], '9': [9, '+', '8', '10', '-9'], '10': [10, '+', '9', '11', '-10'], '11': [11, '+', '10', '12', '-11'], '12': [12, '+', '11', '13', '-12'], '13': [13, '+', '12', '14', '-13'], '14': [14, '+', '13', '15', '-14'], '15': [15, '+', '14', '16', '-15'], '16': [16, '+', '15', '17', '-16'], '17': [17, '+', '16', '18', '-17'], '18': [18, '+', '17', '19', '-18'], '19': [19, '+', '18', '20', '-19'], '20': [20, '+', '19', '21', '-20'], '21': [21, '+', '20', '22', '-21'], '22': [22, '+', '21', '23', '-22'], '23': [23, '+', '22', '24', '-23'], '24': [24, '+', '23', '25', '-24'], '25': [25, '+', '24', '26', '-25'], '26': [26, '+', '25', '27', '-26'], '27': [27, '+', '26', '28', '-27'], '28': [28, '+', '27', '29', '-28'], '29': [29, '+', '28', '30', '-29'], '30': [30, '+', '29', '31', '-30'], '31': [31, '+', '30', '32', '-31'], '32': [32, '+', '31', '33', '-32'], '33': [33, '+', '32', '34', '-33'], '34': [34, '+', '33', '35', '-34'], '35': [35, '+', '34', '36', '-35'], '36': [36, '+', '35', '37', '-36'], '37': [37, '+', '36', '38', '-37'], '38': [38, '+', '37', '39', '-38'], '39': [39, '+', '38', '40', '-39'], '40': [40, '+', '39', '41', '-40'], '41': [41, '+', '40', '42', '-41'], '42': [42, '+', '41', '43', '-42'], '43': [43, '+', '42', '44', '-43'], '44': [44, '+', '43', '45', '-44'], '45': [45, '+', '44', '46', '-45'], '46': [46, '+', '45', '47', '-46'], '47': [47, '+', '46', '48', '-47'], '48': [48, '+', '47', '49', '-48'], '49': [49, '+', '48', '50', '-49'], '50': [50, '+', '49', '51', '-50'], '51': [51, '+', '50', '52', '-51'], '52': [52, '+', '51', '53', '-52'], '53': [53, '+', '52', '54', '-53'], '54': [54, '+', '53', '55', '-54'], '55': [55, '+', '54', '56', '-55'], '56': [56, '+', '55', '57', '-56'], '57': [57, '+', '56', '58', '-57'], '58': [58, '+', '57', '59', '-58'], '59': [59, '+', '58', '60', '-59'], '60': [60, '+', '59', '61', '-60'], '61': [61, '+', '60', '62', '-61'], '62': [62, '+', '61', '63', '-62'], '63': [63, '+', '62', '64', '-63'], '64': [64, '+', '63', '65', '-64'], '65': [65, '+', '64', '66', '-65'], '66': [66, '+', '65', '67', '-66'], '67': [67, '+', '66', '68', '-67'], '68': [68, '+', '67', '69', '-68'], '69': [69, '+', '68', '70', '-69'], '70': [70, '+', '69', '71', '-70'], '71': [71, '+', '70', '72', '-71'], '72': [72, '+', '71', '73', '-72'], '73': [73, '+', '72', '74', '-73'], '74': [74, '+', '73', '75', '-74'], '75': [75, '+', '74', '76', '-75'], '76': [76, '+', '75', '77', '-76'], '77': [77, '+', '76', '78', '-77'], '78': [78, '+', '77', '79', '-78'], '79': [79, '+', '78', '80', '-79'], '80': [80, '+', '79', '81', '-80'], '81': [81, '+', '80', '82', '-81'], '82': [82, '+', '81', '83', '-82'], '83': [83, '+', '82', '84', '-83'], '84': [84, '+', '83', '85', '-84'], '85': [85, '+', '84', '86', '-85'], '86': [86, '+', '85', '87', '-86'], '87': [87, '+', '86', '88', '-87'], '88': [88, '+', '87', '89', '-88'], '89': [89, '+', '88', '90', '-89'], '90': [90, '+', '89', '91', '-90'], '91': [91, '+', '90', '92', '-91'], '92': [92, '+', '91', '93', '-92'], '93': [93, '+', '92', '94', '-93'], '94': [94, '+', '93', '95', '-94'], '95': [95, '+', '94', '96', '-95'], '96': [96, '+', '95', '97', '-96'], '97': [97, '+', '96', '98', '-97'], '98': [98, '+', '97', '99', '-98'], '99': [99, '+', '98', '100', '-99'], '100': [100, '+', '99', '__', '-100'], } ================================================ FILE: sources/Iteration/IterationOf.ts ================================================ import {IterationMap} from './Iteration' /** * Transform a number into an [[Iteration]] * (to use [[Prev]], [[Next]], & [[Pos]]) * @param N to transform * @returns [[Iteration]] * @example * ```ts * import {I} from 'ts-toolbelt' * * type i = I.IterationOf<0> // ["-1", "1", "0", 0, "0"] * * type next = I.Next // ["0", "2", "1", 1, "+"] * type prev = I.Prev // ["-2", "0", "-1", -1, "-"] * * type nnext = I.Pos // +1 * type nprev = I.Pos // -1 * ``` */ export type IterationOf = `${N}` extends keyof IterationMap ? IterationMap[`${N}`] : IterationMap['__'] ================================================ FILE: sources/Iteration/Key.ts ================================================ import {Iteration} from './Iteration' /** * Get the position of `I` (**string**) * @param I to query * @returns [[String]] * @example * ```ts * import {I} from 'ts-toolbelt' * * type i = I.IterationOf<'20'> * * type test0 = I.Key // '20' * type test1 = I.Key> // '21' * ``` */ export type Key = `${I[0]}` ================================================ FILE: sources/Iteration/Next.ts ================================================ import {Iteration, IterationMap} from './Iteration' /** * Move `I`'s position forward * @param I to move * @returns [[Iteration]] * @example * ```ts * import {I} from 'ts-toolbelt' * * type i = I.IterationOf<'20'> * * type test0 = I.Pos // 20 * type test1 = I.Pos> // 21 * ``` */ export type Next = IterationMap[I[3]] ================================================ FILE: sources/Iteration/Pos.ts ================================================ import {Iteration} from './Iteration' /** * Get the position of `I` (**number**) * @param I to query * @returns `number` * @example * ```ts * import {I} from 'ts-toolbelt' * * type i = I.IterationOf<'20'> * * type test0 = I.Pos // 20 * type test1 = I.Pos> // 21 * ``` */ export type Pos = I[0] ================================================ FILE: sources/Iteration/Prev.ts ================================================ import {Iteration, IterationMap} from './Iteration' /** * Move `I`'s position backwards * @param I to move * @returns [[Iteration]] * @example * ```ts * import {I} from 'ts-toolbelt' * * type i = I.IterationOf<'20'> * * type test0 = I.Pos // 20 * type test1 = I.Pos> // 19 * ``` */ export type Prev = IterationMap[I[2]] // continues iterating ================================================ FILE: sources/Iteration/_Internal.ts ================================================ /** * Describes how to perform iterations */ export type Way = '->' | '<-' // --------------------------------------------------------------------------------------- /** * Generate the [[IterationOf]] type * @param min -40 * @param max +40 */ const IterationOfGenerator = (min: number, max: number) => { // eslint-disable-next-line no-nested-ternary const sign = (i: number) => `"${i > 0 ? '+' : i < 0 ? '-' : '0'}"` const prev = (i: number) => `"${i === min ? '__' : i - 1}"` const next = (i: number) => `"${i === max ? '__' : i + 1}"` const oppo = (i: number) => `"${i * -1}"` const entry = (i: number) => `"${i}": [${i}, ${sign(i)}, ${prev(i)}, ${next(i)}, ${oppo(i)}],` console.log(`{${entry(min)}`) for (let i = min + 1, k = 1; i <= max - 1; i++, k++) console.log(entry(i)) console.log(`${entry(max)}}`) } IterationOfGenerator(-100, +100) ================================================ FILE: sources/Iteration/_api.ts ================================================ /** @ignore *//** */ export {Iteration} from './Iteration' export {IterationOf} from './IterationOf' export {Key} from './Key' export {Next} from './Next' export {Pos} from './Pos' export {Prev} from './Prev' ================================================ FILE: sources/List/Append.ts ================================================ import {List} from './List' /** * Add an element `A` at the end of `L`. * @param L to append to * @param A to be added to * @returns [[List]] * @example * ```ts * import {L} from 'ts-toolbelt' * * type test0 = L.Append<[1, 2, 3], 4> // [1, 2, 3, 4] * type test1 = L.Append<[], 'a'> // ['a'] * type test2 = L.Append // ['a', 'b', 'c'] * type test3 = L.Append<[1, 2], [3, 4]> // [1, 2, [3, 4]] * ``` */ export type Append = [...L, A] ================================================ FILE: sources/List/Assign.ts ================================================ import {Assign as OAssign} from '../Object/Assign' import {List} from './List' import {Depth} from '../Object/_Internal' import {BuiltIn} from '../Misc/BuiltIn' import {Cast} from '../Any/Cast' /** * Assign a list of [[List]] into `L` with [[Merge]]. Merges from left to * right, first items get overridden by the next ones (last-in overrides). * @param L to assign to * @param Ls to assign * @param depth (?=`'flat'`) 'deep' to do it deeply * @param ignore (?=`BuiltIn`) types not to merge * @param fill (?=`undefined`) types of `O` to be replaced with ones of `O1` * @returns [[Object]] * @example * ```ts * import {L} from 'ts-toolbelt' * * type test0 = Assign<[1, 2, 3], [[2, 1]]> // [2, 1, 3] * type test1 = Assign<[], [[1, 2, 3, 4], [2, 4, 6]]> // [2, 4, 6, 4] * type test2 = Assign<[0, 0, 0, 0, 0], [[0, 1], [0, 2, 0, 4?]]> // [0, 2, 0, 0 | 4, 0] * ``` */ export type Assign, depth extends Depth = 'flat', ignore extends object = BuiltIn, fill extends any = never> = Cast, List> ================================================ FILE: sources/List/AtLeast.ts ================================================ import {Key} from './_Internal' import {AtLeast as OAtLeast} from '../Object/AtLeast' import {ObjectOf} from './ObjectOf' import {_ListOf} from '../Object/ListOf' import {List} from './List' import {Keys} from '../Any/Keys' /** * Make that at least one of the keys `K` are required in `L` at a time. * @param L to make required * @param K (?=`keyof L`) to choose fields * @returns [[List]] [[Union]] * @example * ```ts * import {L} from 'ts-toolbelt' * * type test0 = L.AtLeast<[1, 2, 3], 0> // [1, 2 | undefined, 3 | undefined] * type test1 = L.AtLeast<[1, 2, 3], 0 | 1> // [1, 2 | undefined, 3 | undefined] | [1 | undefined, 2, 3 | undefined] * type test2 = L.AtLeast<[1, 2, 3]> * // | [1, 2, 3] * // | [1, 2 | undefined, 3 | undefined] * // | [1 | undefined, 2, 3 | undefined] * // | [1 | undefined, 2 | undefined, 3] * ``` */ export type AtLeast> = OAtLeast, `${K & number}` | K> extends infer U ? U extends unknown // we distribute over the union ? _ListOf // each union member to a list : never : never declare const sym: unique symbol ================================================ FILE: sources/List/Compulsory.ts ================================================ import {Depth} from '../Object/_Internal' import {CompulsoryPart} from '../Object/Compulsory' import {List} from './List' import {_Pick} from '../Object/Pick' import {Cast} from '../Any/Cast' /** * Make that `L`'s fields cannot be [[Nullable]] or [[Optional]] (it's like * [[Required]] & [[NonNullable]] at once). * @param L to make compulsory * @param depth (?=`'flat'`) 'deep' to do it deeply * @returns [[List]] * @example * ```ts * * import {L} from 'ts-toolbelt' * * type test0 = L.Compulsory<[1, 2, 3?, 4?]> // [1, 2, 3, 4] * type test1 = L.Compulsory<['a', 'b' | undefined, 'c', 'd', 'e' | null]> // ['a', 'b', 'c', 'd', 'e'] * ``` */ export type Compulsory = Cast, List> ================================================ FILE: sources/List/CompulsoryKeys.ts ================================================ import {CompulsoryKeys as OCompulsoryKeys} from '../Object/CompulsoryKeys' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Get the keys of `L` that are [[Compulsory]] * * (⚠️ needs `--strictNullChecks` enabled) * @param L * @returns [[Key]] * @example * ```ts * import {L} from 'ts-toolbelt' * * type test0 = L.CompulsoryKeys<[1, 2, 3]> // {0: 1, 1: 2, 2: 3} * ``` */ export type CompulsoryKeys = OCompulsoryKeys> ================================================ FILE: sources/List/Concat.ts ================================================ import {List} from './List' /** * Attach `L1` at the end of `L` * @param L to concat with * @param L1 to be attached * @returns [[List]] * @example * ```ts * import {L} from 'ts-toolbelt' * * type test0 = L.Concat<[1, 2], [3, 4]> // [1, 2, 3, 4] * type test1 = L.Concat<[1, 2], [[3], 4]> // [1, 2, [3], 4] * type test2 = L.Concat<[1, 2], number[]> // [1, 2, ...number[]] * type test3 = L.Concat // [1, 2, 3] * ``` */ export type Concat = [...L, ...L1] ================================================ FILE: sources/List/Diff.ts ================================================ import {Diff as ODiff} from '../Object/Diff' import {ListOf} from '../Object/ListOf' import {Match} from '../Any/_Internal' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Get a [[List]] that is the difference between `L` & `L1` * (`L`'s differences have priority over `L1`'s if entries overlap) * (If `match = 'default'`, no type checks are done) * @param L to check differences with * @param L1 to check differences against * @param match (?=`'default'`) to change precision * @returns [[List]] * @example * ```ts * ``` */ export type Diff = ListOf, ObjectOf, match>> ================================================ FILE: sources/List/Drop.ts ================================================ import {Tail} from './Tail' import {Cast} from '../Any/Cast' import {IterationOf} from '../Iteration/IterationOf' import {Iteration} from '../Iteration/Iteration' import {Way} from '../Iteration/_Internal' import {List} from './List' import {Pos} from '../Iteration/Pos' import {Prev} from '../Iteration/Prev' import {Prepend} from './Prepend' import {Naked} from './_Internal' import {Extends} from '../Any/Extends' /** * @hidden */ type DropForth = { 0: DropForth, Prev> 1: L }[Extends<0, Pos>] /** * @hidden */ type DropBack, LN extends List = []> = { 0: DropBack, Prepend]>> 1: LN }[Extends<-1, Pos>] /** * @hidden */ type __Drop = { '->': DropForth '<-': DropBack }[way] /** * @hidden */ export type _Drop = __Drop, IterationOf, way> extends infer X ? Cast : never /** * Remove `N` entries out of `L` * @param L to remove from * @param N to remove out * @param way (?=`'->'`) from front: '->', from end: '<-' * @returns [[List]] * @example * ```ts * ``` */ export type Drop = L extends unknown ? N extends unknown ? _Drop : never : never ================================================ FILE: sources/List/Either.ts ================================================ import {Key} from './_Internal' import {Either as OEither} from '../Object/Either' import {ObjectOf} from './ObjectOf' import {_ListOf} from '../Object/ListOf' import {List} from './List' import {Boolean} from '../Boolean/_Internal' /** * Split `L` into a [[Union]] with `K` keys in such a way that none of * the keys are ever present with one another within the different unions. * @param L to split * @param K to split with * @param strict (?=`1`) to force excess property checks https://github.com/microsoft/TypeScript/issues/20863 * @returns [[List]] [[Union]] * @example * ```ts * ``` */ export type Either = OEither, `${K & number}` | K, strict> extends infer OE ? OE extends unknown ? _ListOf : never : never ================================================ FILE: sources/List/Exclude.ts ================================================ import {Match} from '../Any/_Internal' import {ListOf} from '../Object/ListOf' import {Exclude as OExclude} from '../Object/Exclude' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Exclude the entries of `L1` out of `L` * (If `match = 'default'`, no type checks are done) * @param L to remove from * @param L1 to remove out * @param match (?=`'default'`) to change precision * @returns [[List]] * @example * ```ts * ``` */ export type Exclude = ListOf, ObjectOf, match>> ================================================ FILE: sources/List/ExcludeKeys.ts ================================================ import {ExcludeKeys as OExcludeKeys} from '../Object/ExcludeKeys' import {Match} from '../Any/_Internal' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Exclude the keys of `L1` out of the keys of `L` * (If `match = 'default'`, no type checks are done) * @param L to remove the keys from * @param L1 to remove the keys out * @param match (?=`'default'`) to change precision * @returns [[Key]] * @example * ```ts * ``` */ export type ExcludeKeys = OExcludeKeys, ObjectOf, match> ================================================ FILE: sources/List/Extract.ts ================================================ import {KeySet} from './KeySet' import {Pick} from './Pick' import {List} from './List' /** * Pick a range of entries (portion) from `L` * @param L to pick from * @param From to start with * @param To to end with * @returns [[List]] * @example * ```ts * ``` */ export type Extract = Pick> ================================================ FILE: sources/List/Filter.ts ================================================ import {Filter as OFilter} from '../Object/Filter' import {ListOf} from '../Object/ListOf' import {Match} from '../Any/_Internal' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Filter out of `L` the entries that match `M` * @param L to remove from * @param M to select entries * @param match (?=`'default'`) to change precision * @returns [[List]] * @example * ```ts * ``` */ export type Filter = ListOf, M, match>> ================================================ FILE: sources/List/FilterKeys.ts ================================================ import {FilterKeys as OFilterKeys} from '../Object/FilterKeys' import {Match} from '../Any/_Internal' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Filter out the keys of `L` which entries match `M` * @param L to remove from * @param M to select entries * @param match (?=`'default'`) to change precision * @returns [[Key]] * @example * ```ts * ``` */ export type FilterKeys = OFilterKeys, M, match> ================================================ FILE: sources/List/Flatten.ts ================================================ import {List} from './List' import {_UnNest} from './UnNest' import {Cast} from '../Any/Cast' import {Equals} from '../Any/Equals' import {Iteration} from '../Iteration/Iteration' import {IterationOf} from '../Iteration/IterationOf' import {Extends} from '../Any/Extends' import {Next} from '../Iteration/Next' import {Or} from '../Boolean/Or' import {Boolean} from '../Boolean/_Internal' /** * @hidden */ type __Flatten> = { 0: __Flatten<_UnNest, L, strict, limit, Next> 1: L }[Or, Extends>] /** * @hidden */ export type _Flatten = __Flatten> extends infer X ? Cast : never /** * Remove all dimensions of `L` (10 max) * @param L to un-nest * @param strict (?=`1`) `0` to not preserve tuples * @param limit (?=`string`) to stop un-nesting at * @returns [[List]] * @example * ```ts * ``` */ export type Flatten = L extends unknown ? _Flatten : never ================================================ FILE: sources/List/Group.ts ================================================ import {_Drop} from './Drop' import {_Take} from './Take' import {Cast} from '../Any/Cast' import {Append} from './Append' import {List} from './List' import {Extends} from '../Any/Extends' /** * @hidden */ type __Group = { 0: __Group<_Drop, N, Append>> 1: LN }[Extends>] /** * @hidden */ export type _Group = __Group extends infer X ? Cast : never /** * Split `L` into sub-[[List]]s every `N` * @param L to group * @param N to split at * @returns [[List]] * @example * ```ts * ``` */ export type Group = L extends unknown ? N extends unknown ? _Group : never : never ================================================ FILE: sources/List/Has.ts ================================================ import {Match} from '../Any/_Internal' import {Has as OHas} from '../Object/Has' import {Key} from './_Internal' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Check whether `L` has a entry of key `K` that matches `M` * @param L to be inspected * @param K to choose entry * @param M (?=`any`) to check entry type * @param match (?=`'default'`) to change precision * @returns [[Boolean]] * @example * ```ts * ``` */ export type Has = OHas, `${K & number}` | K, M, match> ================================================ FILE: sources/List/HasPath.ts ================================================ import {HasPath as OHasPath} from '../Object/HasPath' import {Match} from '../Any/_Internal' import {Key} from '../Any/Key' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Check whether `L` has nested entries that match `M` * @param L to be inspected * @param Path to be followed * @param M (?=`any`) to check entry type * @param match (?=`'default'`) to change precision * @returns [[Boolean]] * @example * ```ts * ``` */ export type HasPath, M extends any = any, match extends Match = 'default'> = OHasPath, Path, M, match> ================================================ FILE: sources/List/Head.ts ================================================ import {Length} from './Length' import {List} from './List' /** * Get the first entry of `L` * @param L to extract from * @returns [[Any]] * @example * ```ts * ``` */ export type Head = Length extends 0 ? never : L[0] ================================================ FILE: sources/List/Includes.ts ================================================ import {Match} from '../Any/_Internal' import {Includes as OIncludes} from '../Object/Includes' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Check whether `L` has entries that match `M` * @param L to be inspected * @param M to check entry type * @param match (?=`'default'`) to change precision * @returns [[Boolean]] * @example * ```ts * ``` */ export type Includes = OIncludes, M, match> ================================================ FILE: sources/List/Intersect.ts ================================================ import {Intersect as OIntersect} from '../Object/Intersect' import {Match} from '../Any/_Internal' import {ListOf} from '../Object/ListOf' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Get the intersecting entries of `L` & `L1` * (If `match = 'default'`, no type checks are done) * @param L to check similarities with * @param L1 to check similarities against * @returns [[List]] * @example * ```ts * ``` */ export type Intersect = ListOf, ObjectOf, match>> ================================================ FILE: sources/List/IntersectKeys.ts ================================================ import {Match} from '../Any/_Internal' import {IntersectKeys as OIntersectKeys} from '../Object/IntersectKeys' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Get the intersecting entries of `L` & `L1` * (If `match = 'default'`, no type checks are done) * @param L to check similarities with * @param L1 to check similarities against * @returns [[Key]] * @example * ```ts * ``` */ export type IntersectKeys = OIntersectKeys, L1, match> ================================================ FILE: sources/List/KeySet.ts ================================================ import {Range} from '../Number/Range' import {UnionOf} from './UnionOf' /** * Create a set of keys * @param From to start with * @param To to end with * @returns [[Key]] * @example * ```ts * ``` */ export type KeySet = UnionOf'>> ================================================ FILE: sources/List/Last.ts ================================================ import {Tail} from './Tail' import {Length} from './Length' import {List} from './List' /** * Get the last entry of `L` * @param L to extract from * @returns [[Any]] * @example * ```ts * ``` */ export type Last = L[Length>] ================================================ FILE: sources/List/LastKey.ts ================================================ import {Length} from './Length' import {Tail} from './Tail' import {List} from './List' /** * Get the last index of `L` * @param L to get from * @returns `number` * @example * ```ts * ``` */ export type LastKey = Length> ================================================ FILE: sources/List/Length.ts ================================================ import {List} from './List' /** * Get the length of `L` * @param L to get length * @returns [[String]] or `number` * @example * ```ts * ``` */ export type Length = L['length'] ================================================ FILE: sources/List/List.ts ================================================ /** * A [[List]] * @param A its type * @returns [[List]] * @example * ```ts * type list0 = [1, 2, 3] * type list1 = number[] * ``` */ export type List = ReadonlyArray ================================================ FILE: sources/List/Longest.ts ================================================ import {Has} from '../Union/Has' import {List} from './List' /** * Get the longest [[List]] of `L` & `L1` * (`L` has priority if both lengths are equal) * @param L to compare length * @param L1 to compare length * @returns `L | L1` * @example * ```ts * ``` */ export type Longest = L extends unknown ? L1 extends unknown ? {0: L1, 1: L}[Has] : never : never ================================================ FILE: sources/List/Merge.ts ================================================ import {Merge as OMerge} from '../Object/Merge' import {List} from './List' import {Depth} from '../Object/_Internal' import {BuiltIn} from '../Misc/BuiltIn' import {Cast} from '../Any/Cast' /** * Accurately merge the fields of `L` with the ones of `L1`. It is * equivalent to the spread operator in JavaScript. [[Union]]s and [[Optional]] * fields will be handled gracefully. * * (⚠️ needs `--strictNullChecks` enabled) * @param L to complete * @param L1 to copy from * @param depth (?=`'flat'`) 'deep' to do it deeply * @param ignore (?=`BuiltIn`) types not to merge * @param fill (?=`undefined`) types of `O` to be replaced with ones of `O1` * @returns [[List]] * @example * ```ts * ``` */ export type Merge = Cast, List> ================================================ FILE: sources/List/MergeAll.ts ================================================ import {MergeAll as OMergeAll} from '../Object/MergeAll' import {List} from '../List/List' import {Depth} from '../Object/_Internal' import {BuiltIn} from '../Misc/BuiltIn' import {Cast} from '../Any/Cast' /** * [[Merge]] a list of [[List]]s into `L`. Merges from left to right, first * items get completed by the next ones (last-in completes). * @param L to start with * @param Ls to merge * @param depth (?=`'flat'`) 'deep' to do it deeply * @param ignore (?=`BuiltIn`) types not to merge * @param fill (?=`undefined`) types of `O` to be replaced with ones of `O1` * @returns [[List]] * @example * ```ts * ``` */ export type MergeAll, depth extends Depth = 'flat', ignore extends object = BuiltIn, fill extends any = undefined> = Cast, List> ================================================ FILE: sources/List/Modify.ts ================================================ import {Replace} from '../Union/Replace' import {x} from '../Any/x' import {List} from './List' import {Cast} from '../Any/Cast' import {At} from '../Any/At' /** * Modify `L` with `LMod` & the [[x]] placeholder * @param L to copy from * @param LMod to copy to * @returns [[List]] * @example * ```ts * ``` */ export type Modify = Cast<{ [K in keyof LMod]: Replace, undefined>> }, List> ================================================ FILE: sources/List/NonNullable.ts ================================================ import {_Pick} from '../Object/Pick' import {Key} from './_Internal' import {NonNullable as UNonNullable} from '../Union/NonNullable' import {Depth} from '../Object/_Internal' import {BuiltIn} from '../Misc/BuiltIn' import {Cast} from '../Any/Cast' import {List} from './List' /** * @hidden */ export type NonNullableFlat = { [P in keyof O]: P extends K ? UNonNullable : O[P] } & {} /** * @hidden */ type _NonNullableDeep = { [K in keyof O]: O[K] extends BuiltIn ? O[K] : NonNullableDeep } /** * @hidden */ export type NonNullableDeep = _NonNullableDeep> /** * @hidden */ export type NonNullablePart = { 'flat': NonNullableFlat 'deep': NonNullableDeep }[depth] /** * Make some entries of `L` not nullable (deeply or not) * @param L to make non nullable * @param K (?=`Key`) to choose fields * @param depth (?=`'flat'`) 'deep' to do it deeply * @returns [[List]] * @example * ```ts * ``` */ export type NonNullable = Cast, List> ================================================ FILE: sources/List/NonNullableKeys.ts ================================================ import {NonNullableKeys as ONonNullableKeys} from '../Object/NonNullableKeys' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Get the keys of `L` that are non-nullable * @param L * @returns [[Key]] * @example * ```ts * ``` */ export type NonNullableKeys = ONonNullableKeys> ================================================ FILE: sources/List/Nullable.ts ================================================ import {Key} from './_Internal' import {List} from './List' import {Update} from '../Object/Update' import {x} from '../Any/x' import {Cast} from '../Any/Cast' /** * Make some entries of `L` nullable (deeply or not) * @param L to make nullable * @param K (?=`Key`) to choose fields * @param depth (?=`'flat'`) 'deep' to do it deeply * @returns [[List]] * @example * ```ts * ``` */ export type Nullable = Cast, List> ================================================ FILE: sources/List/NullableKeys.ts ================================================ import {NullableKeys as ONullableKeys} from '../Object/NullableKeys' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Get the keys of `L` that are nullable * @param L * @returns [[Key]] * @example * ```ts * ``` */ export type NullableKeys = ONullableKeys> ================================================ FILE: sources/List/ObjectOf.ts ================================================ import {_Omit} from '../Object/Omit' import {_Pick} from '../Object/Pick' import {Length} from './Length' import {List} from './List' /** * Transform a [[List]] into an [[Object]] equivalent * @param L to transform * @returns [[Object]] * @example * ```ts * ``` */ export type ObjectOf = O extends unknown ? number extends Length // detect arrays ? _Pick // preserves arrays : _Omit // transforms tuples : never ================================================ FILE: sources/List/Omit.ts ================================================ import {_Omit as _OOmit} from '../Object/Omit' import {_ListOf} from '../Object/ListOf' import {Key} from './_Internal' import {List} from './List' import {ObjectOf} from './ObjectOf' /** * @hidden */ export type _Omit = _ListOf<_OOmit, `${K & number}` | K>> /** * Remove out of `L` the entries of key `K` * @param L to remove from * @param K to chose entries * @returns [[List]] * @example * ```ts * ``` */ export type Omit = L extends unknown ? _Omit : never ================================================ FILE: sources/List/Optional.ts ================================================ import {Cast} from '../Any/Cast' import {OptionalPart} from '../Object/Optional' import {Depth} from '../Object/_Internal' import {List} from './List' /** * Make `L` optional (deeply or not) * @param L to make optional * @param depth (?=`'flat'`) 'deep' to do it deeply * @returns [[List]] * @example * ```ts * ``` */ export type Optional = Cast, List> ================================================ FILE: sources/List/OptionalKeys.ts ================================================ import {OptionalKeys as OOptionalKeys} from '../Object/OptionalKeys' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Get the keys of `L` that are optional * @param L * @returns [[Key]] * @example * ```ts * ``` */ export type OptionalKeys = OOptionalKeys> ================================================ FILE: sources/List/Overwrite.ts ================================================ import {Overwrite as OOverwrite} from '../Object/Overwrite' import {Cast} from '../Any/Cast' import {List} from './List' /** * Update the entries of `L` with the ones of `L1` * @param L to update * @param L1 to update with * @returns [[Object]] * @example * ```ts * ``` */ export type Overwrite = Cast, List> ================================================ FILE: sources/List/Partial.ts ================================================ import {Partial as OPartial} from '../Object/Partial' import {Depth} from '../Object/_Internal' import {Cast} from '../Any/Cast' import {List} from './List' /** * Make all fields of `O` optional (deeply or not) * @param L to make optional * @param depth (?=`'flat'`) 'deep' to do it deeply * @returns [[List]] * @example * ```ts * import {O} from 'ts-toolbelt' * * type L = [1, 2, 3, [4, [5]]] * * type test0 = O.Partial * type test1 = O.Partial * ``` */ export type Partial = Cast, List> ================================================ FILE: sources/List/Patch.ts ================================================ import {Patch as OPatch} from '../Object/Patch' import {List} from './List' import {Depth} from '../Object/_Internal' import {BuiltIn} from '../Misc/BuiltIn' import {Cast} from '../Any/Cast' /** * Complete the fields of `L` with the ones of `L1`. This is a version of * [[Merge]] that does NOT handle optional fields, it only completes fields of `O` * with the ones of `O1` if they don't exist. * * (⚠️ needs `--strictNullChecks` enabled) * @param L to complete * @param L1 to copy from * @param depth (?=`'flat'`) 'deep' to do it deeply * @param ignore (?=`BuiltIn`) types not to merge * @param fill (?=`never`) types of `O` to be replaced with ones of `O1` * @returns [[List]] * @example * ```ts * ``` */ export type Patch = Cast, List> ================================================ FILE: sources/List/PatchAll.ts ================================================ import {PatchAll as OPatchAll} from '../Object/PatchAll' import {List} from '../List/List' import {Depth} from '../Object/_Internal' import {BuiltIn} from '../Misc/BuiltIn' import {Cast} from '../Any/Cast' /** * [[Patch]] a list of [[List]]s into `L`. Patches from left to right, first * items get completed by the next ones (last-in completes). * @param O to start with * @param Os to patch * @param depth (?=`'flat'`) 'deep' to do it deeply * @param ignore (?=`BuiltIn`) types not to merge * @param fill (?=`never`) types of `O` to be replaced with ones of `O1` * @returns [[List]] * @example * ```ts * ``` */ export type PatchAll, depth extends Depth = 'flat', ignore extends object = BuiltIn, fill extends any = never> = Cast, List> ================================================ FILE: sources/List/Path.ts ================================================ import {Path as OPath} from '../Object/Path' import {Key} from '../Any/Key' import {List} from './List' /** * Get in `L` the type of nested properties * @param L to be inspected * @param Path to be followed * @returns [[Any]] * @example * ```ts * ``` */ export type Path> = OPath ================================================ FILE: sources/List/Paths.ts ================================================ import {Paths as OPaths} from '../Object/Paths' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Get all the possible paths of `L` * (⚠️ this won't work with circular-refs) * @param L to be inspected * @returns [[String]][] * @example * ```ts * ``` */ export type Paths = OPaths> ================================================ FILE: sources/List/Pick.ts ================================================ import {_Pick as _OPick} from '../Object/Pick' import {_ListOf} from '../Object/ListOf' import {Key} from './_Internal' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * @hidden */ export type _Pick = _ListOf<_OPick, `${K & number}` | K>> /** * Extract out of `L` the entries of key `K` * @param L to extract from * @param K to chose entries * @returns [[List]] * @example * ```ts * ``` */ export type Pick = L extends unknown ? _Pick : never ================================================ FILE: sources/List/Pop.ts ================================================ import {_Omit} from './Omit' import {List} from './List' /** * Remove the last element out of `L` * @param L to remove from * @returns [[List]] * @example * ```ts * ``` */ export type Pop = L extends (readonly [...infer LBody, any] | readonly [...infer LBody, any?]) ? LBody : L ================================================ FILE: sources/List/Prepend.ts ================================================ import {List} from './List' /** * Add an element `A` at the beginning of `L` * @param L to append to * @param A to be added to * @returns [[List]] * @example * ```ts * ``` */ export type Prepend = [A, ...L] ================================================ FILE: sources/List/Readonly.ts ================================================ import {Depth} from '../Object/_Internal' import {ReadonlyPart} from '../Object/Readonly' import {List} from './List' import {Cast} from '../Any/Cast' /** * Make `L` readonly (deeply or not) * @param L to make readonly * @param depth (?=`'flat'`) 'deep' to do it deeply * @returns [[List]] * @example * ```ts * ``` */ export type Readonly = Cast, List> ================================================ FILE: sources/List/ReadonlyKeys.ts ================================================ import {ReadonlyKeys as OReadonlyKeys} from '../Object/ReadonlyKeys' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Get the keys of `L` that are readonly * @param L * @returns [[Key]] * @example * ```ts * ``` */ export type ReadonlyKeys = OReadonlyKeys> ================================================ FILE: sources/List/Remove.ts ================================================ import {KeySet} from './KeySet' import {Omit} from './Omit' import {List} from './List' /** * Remove out of `L` a range of entries * @param L to remove from * @param From to start from * @param To to end with * @returns [[List]] * @example * ```ts * ``` */ export type Remove = Omit> ================================================ FILE: sources/List/Repeat.ts ================================================ import {Next} from '../Iteration/Next' import {Prepend} from './Prepend' import {IterationOf} from '../Iteration/IterationOf' import {Iteration} from '../Iteration/Iteration' import {Cast} from '../Any/Cast' import {List} from './List' import {Extends} from '../Any/Extends' import {Pos} from '../Iteration/Pos' /** * @hidden */ type __Repeat> = { 0: __Repeat, Next> 1: L }[Extends, N>] /** * @hidden */ export type _Repeat = __Repeat extends infer X ? Cast : never /** * Fill a [[List]] with `N` times `A` * @param A to fill with * @param N to repeat it * @param L (?=`[]`) to be filled * @returns [[List]] * @example * ```ts * ``` */ export type Repeat = N extends unknown ? L extends unknown ? _Repeat : never : never ================================================ FILE: sources/List/Replace.ts ================================================ import {Replace as OReplace} from '../Object/Replace' import {Match} from '../Any/_Internal' import {Cast} from '../Any/Cast' import {List} from './List' /** * Update with `A` the entries of `L` that match `M` * @param O to update * @param M to select fields * @param A to update with * @param match (?=`'default'`) to change precision * @returns [[List]] * @example * ```ts * ``` */ export type Replace = Cast, List> ================================================ FILE: sources/List/Required.ts ================================================ import {Depth} from '../Object/_Internal' import {RequiredPart} from '../Object/Required' import {List} from './List' import {Cast} from '../Any/Cast' /** * Make `L` required (deeply or not) * @param L to make required * @param depth (?=`'flat'`) 'deep' to do it deeply * @returns [[List]] * @example * ```ts * ``` */ export type Required = Cast, List> ================================================ FILE: sources/List/RequiredKeys.ts ================================================ import {RequiredKeys as ORequiredKeys} from '../Object/RequiredKeys' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Get the keys of `L` that are readonly * @param L * @returns [[Key]] * @example * ```ts * ``` */ export type RequiredKeys = ORequiredKeys> ================================================ FILE: sources/List/Reverse.ts ================================================ import {Prepend} from './Prepend' import {Pos} from '../Iteration/Pos' import {Next} from '../Iteration/Next' import {Length} from './Length' import {IterationOf} from '../Iteration/IterationOf' import {Iteration} from '../Iteration/Iteration' import {Cast} from '../Any/Cast' import {List} from './List' import {Naked} from './_Internal' import {Extends} from '../Any/Extends' /** * @hidden */ type __Reverse> = { 0: __Reverse]>, Next> 1: LO }[Extends, Length>] /** * @hidden */ export type _Reverse = __Reverse, LO> extends infer X ? Cast : never /** * Turn a [[List]] the other way around * @param L to reverse * @param LO (?=`[]`) to prepend to * @returns [[List]] * @example * ```ts * ``` */ export type Reverse = L extends unknown ? _Reverse : never ================================================ FILE: sources/List/Select.ts ================================================ import {Match} from '../Any/_Internal' import {Select as OSelect} from '../Object/Select' import {ListOf} from '../Object/ListOf' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Extract the entries of `L` that match `M` * @param L to extract from * @param M to select entries * @param match (?=`'default'`) to change precision * @returns [[List]] * @example * ```ts * ``` */ export type Select = ListOf, M, match>> ================================================ FILE: sources/List/SelectKeys.ts ================================================ import {Match} from '../Any/_Internal' import {SelectKeys as OSelectKeys} from '../Object/SelectKeys' import {ObjectOf} from './ObjectOf' import {List} from './List' /** * Get the keys of `L` which entries match `M` * @param L to extract from * @param M to select entries * @param match (?=`'default'`) to change precision * @returns [[Key]] * @example * ```ts * ``` */ export type SelectKeys = OSelectKeys, M, match> ================================================ FILE: sources/List/Shortest.ts ================================================ import {Has} from '../Union/Has' import {List} from './List' /** * Get the shortest [[List]] of `L` & `L1` * (`L` has priority if both lengths are equal) * @param L to compare length * @param L1 to compare length * @returns `L | L1` * @example * ```ts * ``` */ export type Shortest = L extends unknown ? L1 extends unknown ? {0: L1, 1: L}[Has] : never : never ================================================ FILE: sources/List/Tail.ts ================================================ import {List} from './List' /** * Remove the first item out of a [[List]] * @param L * @returns [[List]] * @example * ```ts * ``` */ export type Tail = L extends readonly [] ? L : L extends readonly [any?, ...infer LTail] ? LTail : L ================================================ FILE: sources/List/Take.ts ================================================ import {IterationOf} from '../Iteration/IterationOf' import {Iteration} from '../Iteration/Iteration' import {Pos} from '../Iteration/Pos' import {Prepend} from './Prepend' import {Way} from '../Iteration/_Internal' import {List} from './List' import {Prev} from '../Iteration/Prev' import {Cast} from '../Any/Cast' import {Tail} from './Tail' import {Extends} from '../Any/Extends' /** * starts in reverse from `N` till `N` = 0 * @hidden */ type TakeForth, LN extends List = []> = { 0: TakeForth, Prepend]>> 1: LN }[Extends<-1, Pos>] /** * starts in reverse from the end till `N` = 0 * @hidden */ type TakeBack = { 0: TakeBack, Prev> 1: L }[Extends<0, Pos>] /** * @hidden */ type __Take = { '->': TakeForth // Reverse logic to work naturally #`Prepend` '<-': TakeBack // Reverse logic to work naturally #`Prepend` }[way] /** * @hidden */ export type _Take = __Take, way> extends infer X ? Cast : never /** * Extract `N` entries out of `L` * @param L to extract from * @param N to extract out * @param way (?=`'->'`) to extract from end * @returns [[List]] * @example * ```ts * ``` */ export type Take = L extends unknown ? N extends unknown ? _Take : never : never ================================================ FILE: sources/List/UnNest.ts ================================================ import {Concat} from './Concat' import {Append} from './Append' import {Cast} from '../Any/Cast' import {Length} from './Length' import {Iteration} from '../Iteration/Iteration' import {IterationOf} from '../Iteration/IterationOf' import {Next} from '../Iteration/Next' import {Pos} from '../Iteration/Pos' import {List} from './List' import {UnionOf} from './UnionOf' import {Naked} from './_Internal' import {Extends} from '../Any/Extends' import {Boolean} from '../Boolean/_Internal' import {Not} from '../Boolean/Not' import {And} from '../Boolean/And' /** * @hidden */ type UnNestLoose = (UnionOf extends infer UL // make `L` a union ? UL extends unknown // for each in union ? UL extends List // if its an array ? UnionOf