diff --git a/.all-contributorsrc b/.all-contributorsrc
deleted file mode 100644
index 2a751582..00000000
--- a/.all-contributorsrc
+++ /dev/null
@@ -1,171 +0,0 @@
-{
- "projectName": "typescript-transform-paths",
- "projectOwner": "LeDDGroup",
- "repoType": "github",
- "repoHost": "https://github.com",
- "files": [
- "README.md"
- ],
- "imageSize": 100,
- "commit": true,
- "commitConvention": "angular",
- "contributors": [
- {
- "login": "danielpza",
- "name": "Daniel Perez Alvarez",
- "avatar_url": "https://avatars2.githubusercontent.com/u/17787042?v=4",
- "profile": "https://github.com/danielpza",
- "contributions": [
- "code",
- "maintenance",
- "test"
- ]
- },
- {
- "login": "anion155",
- "name": "Михайлов Антон",
- "avatar_url": "https://avatars1.githubusercontent.com/u/4786672?v=4",
- "profile": "https://github.com/anion155",
- "contributions": [
- "code",
- "bug",
- "test"
- ]
- },
- {
- "login": "joshuaavalon",
- "name": "Joshua Avalon",
- "avatar_url": "https://avatars0.githubusercontent.com/u/7152420?v=4",
- "profile": "https://joshuaavalon.io",
- "contributions": [
- "bug",
- "platform"
- ]
- },
- {
- "login": "roblav96",
- "name": "Robert Laverty",
- "avatar_url": "https://avatars1.githubusercontent.com/u/1457327?v=4",
- "profile": "https://roblav96.github.io/resume",
- "contributions": [
- "bug",
- "test"
- ]
- },
- {
- "login": "oleersoy",
- "name": "Ole Ersoy",
- "avatar_url": "https://avatars3.githubusercontent.com/u/1163873?v=4",
- "profile": "https://github.com/oleersoy",
- "contributions": [
- "bug",
- "blog"
- ]
- },
- {
- "login": "sbmw",
- "name": "sbmw",
- "avatar_url": "https://avatars0.githubusercontent.com/u/30099628?v=4",
- "profile": "https://github.com/sbmw",
- "contributions": [
- "bug"
- ]
- },
- {
- "login": "richardspence",
- "name": "richardspence",
- "avatar_url": "https://avatars2.githubusercontent.com/u/9914123?v=4",
- "profile": "https://github.com/richardspence",
- "contributions": [
- "bug"
- ]
- },
- {
- "login": "viT-1",
- "name": "Vitaly Pinchuk",
- "avatar_url": "https://avatars1.githubusercontent.com/u/19496430?v=4",
- "profile": "http://codepen.io/viT-1/",
- "contributions": [
- "bug"
- ]
- },
- {
- "login": "laij84",
- "name": "laij84",
- "avatar_url": "https://avatars0.githubusercontent.com/u/18145822?v=4",
- "profile": "https://github.com/laij84",
- "contributions": [
- "bug"
- ]
- },
- {
- "login": "dko-slapdash",
- "name": "dko-slapdash",
- "avatar_url": "https://avatars0.githubusercontent.com/u/46383452?v=4",
- "profile": "https://github.com/dko-slapdash",
- "contributions": [
- "bug"
- ]
- },
- {
- "login": "hedwiggggg",
- "name": "hedwiggggg",
- "avatar_url": "https://avatars1.githubusercontent.com/u/42947316?v=4",
- "profile": "https://github.com/hedwiggggg",
- "contributions": [
- "bug",
- "test",
- "code"
- ]
- },
- {
- "login": "kuskoman",
- "name": "kuskoman",
- "avatar_url": "https://avatars3.githubusercontent.com/u/15456923?v=4",
- "profile": "https://github.com/kuskoman",
- "contributions": [
- "doc"
- ]
- },
- {
- "login": "booninite",
- "name": "alex weidner",
- "avatar_url": "https://avatars3.githubusercontent.com/u/13647495?v=4",
- "profile": "https://github.com/booninite",
- "contributions": [
- "bug"
- ]
- },
- {
- "login": "nonara",
- "name": "Ron S.",
- "avatar_url": "https://avatars0.githubusercontent.com/u/1427565?v=4",
- "profile": "https://github.com/nonara",
- "contributions": [
- "bug",
- "test",
- "code"
- ]
- },
- {
- "login": "vladimiry",
- "name": "Vladimir Yakovlev",
- "avatar_url": "https://avatars2.githubusercontent.com/u/1560781?v=4",
- "profile": "https://github.com/vladimiry",
- "contributions": [
- "bug"
- ]
- },
- {
- "login": "vwpo",
- "name": "vwpo",
- "avatar_url": "https://avatars3.githubusercontent.com/u/57674261?v=4",
- "profile": "https://github.com/vwpo",
- "contributions": [
- "bug"
- ]
- }
- ],
- "contributorsPerLine": 7,
- "skipCi": true
-}
diff --git a/.editorconfig b/.editorconfig
index 2733847d..b67b1aed 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -363,7 +363,7 @@ ij_typescript_ternary_operation_signs_on_next_line = false
ij_typescript_ternary_operation_wrap = off
ij_typescript_union_types_wrap = on_every_item
ij_typescript_use_chained_calls_group_indents = false
-ij_typescript_use_double_quotes = false
+ij_typescript_use_double_quotes = true
ij_typescript_use_explicit_js_extension = global
ij_typescript_use_path_mapping = always
ij_typescript_use_public_modifier = false
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index c1b69cb3..e66711a3 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -1,6 +1,11 @@
name: Node.js CI
-on: [ push, pull_request ]
+on:
+ pull_request:
+ branches: [ master ]
+ types: [ opened, synchronize, closed ]
+ push:
+ branches: [ master ]
jobs:
build:
@@ -14,25 +19,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- - name: Determine Yarn Cache Path
- id: yarn-cache-dir-path
- run: echo "::set-output name=dir::$(yarn cache dir)"
-
- - uses: actions/cache@v1
- id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
- with:
- path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
- key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- restore-keys: |
- ${{ runner.os }}-yarn-
-
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- - name: Install Packages
- run: yarn install --frozen-lockfile
+ - name: Install
+ run: yarn run clean:all && yarn install --frozen-lockfile
- name: Build
run: yarn build
@@ -41,3 +34,4 @@ jobs:
run: yarn test
env:
CI: true
+ TEST_TARGET: dist
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 7824f55a..9e766a06 100755
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -41,6 +41,7 @@ jobs:
run: yarn test
env:
CI: true
+ TEST_TARGET: dist
- name: Generate Release Body
run: npx extract-changelog-release > RELEASE_BODY.md
diff --git a/.gitignore b/.gitignore
index 6cfcd46f..f310fc56 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
# Yarn
.yarn-cache
+./test/yarn.lock
# Built
*.js.map
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100755
index 00000000..37498d0a
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/esm.mjs b/esm.mjs
new file mode 100755
index 00000000..29f4af0f
--- /dev/null
+++ b/esm.mjs
@@ -0,0 +1,13 @@
+import { fileURLToPath } from 'url';
+import { createRequire } from 'module';
+const require = createRequire(fileURLToPath(import.meta.url));
+
+/** @type {import('./src/compatibility/node-register')} */
+const { nodeRegister } = require('./dist/compatibility/node-register');
+
+/** @type {import('ts-node')} */
+import tsNode from 'ts-node';
+
+const tsNodeInstance = nodeRegister();
+
+export const { resolve, getFormat, transformSource } = tsNode.createEsmHooks(tsNodeInstance);
diff --git a/jest.config.ts b/jest.config.ts
index e2d81f09..0b92e5af 100755
--- a/jest.config.ts
+++ b/jest.config.ts
@@ -12,6 +12,7 @@ const config: Config.InitialOptions = {
},
modulePaths: [ "" ],
roots: [ '' ],
+ setupFilesAfterEnv: [ "./test/src/setup.ts" ]
}
export default config;
diff --git a/package.json b/package.json
index 6d66d68e..d68228a9 100755
--- a/package.json
+++ b/package.json
@@ -3,20 +3,23 @@
"version": "3.3.1",
"description": "Transforms module resolution paths using TypeScript path mapping and/or custom paths",
"main": "dist/index.js",
- "types": "types/index.d.ts",
+ "types": "dist/index.d.ts",
"scripts": {
"compile": "tsc",
- "build": "yarn run clean && yarn run compile",
+ "build": "yarn run clean && yarn run compile && yarn run check:built-types",
+ "check:built-types": "tsc dist/index.d.ts --esModuleInterop",
+ "-------------- ": "",
"test": "jest",
- "release": "standard-version",
+ "test:src": "cross-env TEST_TARGET=src jest",
+ "test:dist": "cross-env TEST_TARGET=dist jest",
"--------------": "",
"format": "prettier --write \"{src,test}/**/{*.js,!(*.d).ts}\"",
- "clean": "rimraf dist **/*.tsbuildinfo",
- "clean:all": "yarn run clean && rimraf node_modules test/node_modules test/.yarn-cache",
- "reset": "yarn run clean:all && yarn install",
+ "clean": "npx rimraf dist **/*.tsbuildinfo",
+ "clean:all": "yarn run clean && npx rimraf node_modules **/node_modules test/.yarn-cache",
+ "reset": "yarn run clean:all && yarn install && yarn build",
"-------------- ": "",
- "prebuild": "rimraf dist",
- "install:tests": "cd test && yarn install && cd projects/extras && yarn install",
+ "prebuild": "npx rimraf dist",
+ "install:tests": "cd test && yarn install",
"prepare": "yarn run install:tests"
},
"keywords": [
@@ -54,20 +57,26 @@
"@types/jest": "^26.0.24",
"@types/minimatch": "^3.0.5",
"@types/node": "^16.4.10",
+ "@types/ts-expose-internals": "npm:ts-expose-internals@4.4.3",
+ "cross-env": "^7.0.3",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"rimraf": "^3.0.2",
"standard-version": "^9.3.1",
- "ts-expose-internals": "^4.3.2",
"ts-jest": "^27.0.4",
- "ts-node": "^10.1.0",
- "ts-patch": "^1.4.2",
- "typescript": "^4.3.5"
+ "ts-node": "^10.4.0",
+ "ts-patch": "^1.4.4",
+ "ts3": "npm:typescript@3.7.7",
+ "ts45": "npm:typescript@4.5.0-beta",
+ "typescript": "latest"
},
"peerDependencies": {
- "typescript": ">=3.6.5"
+ "typescript": ">=4.2.2"
},
"dependencies": {
"minimatch": "^3.0.4"
+ },
+ "prettier": {
+ "singleQuote": true
}
}
diff --git a/register.js b/register.js
index 09242271..7d681960 100755
--- a/register.js
+++ b/register.js
@@ -7,5 +7,4 @@ try {
);
}
-tsNode.register();
-require('./').register();
+require('./').nodeRegister();
diff --git a/src/register.ts b/src/compatibility/node-register.ts
similarity index 74%
rename from src/register.ts
rename to src/compatibility/node-register.ts
index 3ac76fd7..74799c84 100755
--- a/src/register.ts
+++ b/src/compatibility/node-register.ts
@@ -1,40 +1,51 @@
-import type TSNode from "ts-node";
-import type { REGISTER_INSTANCE } from "ts-node";
-import ts from "typescript";
-import transformer from "./transformer";
+import type TSNode from 'ts-node';
+import type { REGISTER_INSTANCE } from 'ts-node';
+import type TS from 'typescript';
+import { transformer } from '../transform';
/* ****************************************************************************************************************** */
// region: Helpers
/* ****************************************************************************************************************** */
-function getProjectTransformerConfig(pcl: ts.ParsedCommandLine) {
+const checkModuleIsTsTp = (m: string) => {
+ let transformerModule: any;
+ try {
+ transformerModule = require(m);
+ } catch {}
+
+ if (!transformerModule) return m === 'typescript-transform-paths';
+
+ return transformerModule.isTsTp;
+};
+
+function getProjectTransformerConfig(pcl: TS.ParsedCommandLine) {
const plugins = pcl.options.plugins as Record[] | undefined;
if (!plugins) return;
const res: { afterDeclarations?: Record; before?: Record } = {};
for (const plugin of plugins) {
- if (plugin.transform === "typescript-transform-paths" && !plugin.after)
- res[plugin.afterDeclarations ? "afterDeclarations" : "before"] = plugin;
+ if (plugin.transform && checkModuleIsTsTp(plugin.transform) && !plugin.after)
+ res[plugin.afterDeclarations ? 'afterDeclarations' : 'before'] = plugin;
}
return res;
}
function getTransformers(
- program?: ts.Program,
+ program?: TS.Program,
beforeConfig?: Record,
afterDeclarationsConfig?: Record
-): ts.CustomTransformers {
+): TS.CustomTransformers {
return {
...(beforeConfig && { before: [transformer(program, beforeConfig)] }),
...(afterDeclarationsConfig && { afterDeclarations: [transformer(program, afterDeclarationsConfig)] }),
- } as ts.CustomTransformers;
+ } as TS.CustomTransformers;
}
export function mergeTransformers(
- baseTransformers: ts.CustomTransformers,
- transformers: ts.CustomTransformers
-): ts.CustomTransformers {
+ baseTransformers: TS.CustomTransformers,
+ transformers: TS.CustomTransformers
+): TS.CustomTransformers {
const res = {
...((baseTransformers.before || transformers.before) && {
before: [...(transformers.before ?? []), ...(baseTransformers.before ?? [])],
@@ -57,8 +68,8 @@ export function mergeTransformers(
// region: TsNode Registration Utility
/* ****************************************************************************************************************** */
-export function register(): TSNode.RegisterOptions | undefined {
- const { tsNodeInstance, tsNode } = register.initialize();
+export function nodeRegister(): TSNode.Service | undefined {
+ const { tsNodeInstance, tsNode } = nodeRegister.initialize();
const transformerConfig = getProjectTransformerConfig(tsNodeInstance.config);
if (!transformerConfig) return;
@@ -67,7 +78,7 @@ export function register(): TSNode.RegisterOptions | undefined {
const registerOptions: TSNode.RegisterOptions = Object.assign({}, tsNodeInstance.options);
if (registerOptions.transformers) {
- if (typeof registerOptions.transformers === "function") {
+ if (typeof registerOptions.transformers === 'function') {
let oldTransformersFactory = registerOptions.transformers;
registerOptions.transformers = (program) => {
const transformers = getTransformers(program, beforeConfig, afterDeclarationsConfig);
@@ -85,11 +96,10 @@ export function register(): TSNode.RegisterOptions | undefined {
}
// Re-register with new transformers
- tsNode.register(registerOptions);
- return registerOptions;
+ return tsNode.register(registerOptions);
}
-export namespace register {
+export namespace nodeRegister {
export function initialize(): {
tsNode: typeof TSNode;
instanceSymbol: typeof REGISTER_INSTANCE;
@@ -97,14 +107,14 @@ export namespace register {
} {
let tsNode: typeof TSNode;
try {
- tsNode = require("ts-node");
+ tsNode = require('ts-node');
} catch {
throw new Error(
`Cannot resolve ts-node. Make sure ts-node is installed before using typescript-transform-paths/register`
);
}
- const instanceSymbol: typeof REGISTER_INSTANCE = tsNode["REGISTER_INSTANCE"];
+ const instanceSymbol: typeof REGISTER_INSTANCE = tsNode['REGISTER_INSTANCE'];
let tsNodeInstance = global.process[instanceSymbol];
if (!tsNodeInstance) {
@@ -117,6 +127,4 @@ export namespace register {
}
}
-export default register;
-
// endregion
diff --git a/src/declarations/typescript3.d.ts b/src/declarations/typescript3.d.ts
deleted file mode 100755
index 6b59236a..00000000
--- a/src/declarations/typescript3.d.ts
+++ /dev/null
@@ -1,13717 +0,0 @@
-/*! *****************************************************************************
-Copyright (c) Microsoft Corporation. All rights reserved.
-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
-
-THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
-WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
-MERCHANTABLITY OR NON-INFRINGEMENT.
-
-See the Apache Version 2.0 License for specific language governing permissions
-and limitations under the License.
-***************************************************************************** */
-
-declare namespace ts {
- const versionMajorMinor = "3.7";
- /** The version of the TypeScript compiler release */
- const version: string;
-}
-declare namespace ts {
- /**
- * Type of objects whose values are all of the same type.
- * The `in` and `for-in` operators can *not* be safely used,
- * since `Object.prototype` may be modified by outside code.
- */
- interface MapLike {
- [index: string]: T;
- }
- interface SortedReadonlyArray extends ReadonlyArray {
- " __sortedArrayBrand": any;
- }
- interface SortedArray extends Array {
- " __sortedArrayBrand": any;
- }
- /** ES6 Map interface, only read methods included. */
- interface ReadonlyMap {
- get(key: string): T | undefined;
- has(key: string): boolean;
- forEach(action: (value: T, key: string) => void): void;
- readonly size: number;
- keys(): Iterator;
- values(): Iterator;
- entries(): Iterator<[string, T]>;
- }
- /** ES6 Map interface. */
- interface Map extends ReadonlyMap {
- set(key: string, value: T): this;
- delete(key: string): boolean;
- clear(): void;
- }
- /** ES6 Iterator type. */
- interface Iterator {
- next(): {
- value: T;
- done?: false;
- } | {
- value: never;
- done: true;
- };
- }
- /** Array that is only intended to be pushed to, never read. */
- interface Push {
- push(...values: T[]): void;
- }
- type EqualityComparer = (a: T, b: T) => boolean;
- type Comparer = (a: T, b: T) => Comparison;
- enum Comparison {
- LessThan = -1,
- EqualTo = 0,
- GreaterThan = 1
- }
-}
-declare namespace ts {
- const emptyArray: never[];
- /** Create a new map. If a template object is provided, the map will copy entries from it. */
- function createMap(): Map;
- function createMapFromEntries(entries: [string, T][]): Map;
- function createMapFromTemplate(template: MapLike): Map;
- const MapCtr: new () => Map;
- function shimMap(): new () => Map;
- function length(array: ReadonlyArray | undefined): number;
- /**
- * Iterates through 'array' by index and performs the callback on each element of array until the callback
- * returns a truthy value, then returns that value.
- * If no such value is found, the callback is applied to each element of array and undefined is returned.
- */
- function forEach(array: ReadonlyArray | undefined, callback: (element: T, index: number) => U | undefined): U | undefined;
- /** Like `forEach`, but suitable for use with numbers and strings (which may be falsy). */
- function firstDefined(array: ReadonlyArray | undefined, callback: (element: T, index: number) => U | undefined): U | undefined;
- function firstDefinedIterator(iter: Iterator, callback: (element: T) => U | undefined): U | undefined;
- function zipWith(arrayA: ReadonlyArray, arrayB: ReadonlyArray, callback: (a: T, b: U, index: number) => V): V[];
- function zipToIterator(arrayA: ReadonlyArray, arrayB: ReadonlyArray): Iterator<[T, U]>;
- function zipToMap(keys: ReadonlyArray, values: ReadonlyArray): Map;
- /**
- * Iterates through `array` by index and performs the callback on each element of array until the callback
- * returns a falsey value, then returns false.
- * If no such value is found, the callback is applied to each element of array and `true` is returned.
- */
- function every(array: ReadonlyArray, callback: (element: T, index: number) => boolean): boolean;
- /** Works like Array.prototype.find, returning `undefined` if no element satisfying the predicate is found. */
- function find(array: ReadonlyArray, predicate: (element: T, index: number) => element is U): U | undefined;
- function find(array: ReadonlyArray, predicate: (element: T, index: number) => boolean): T | undefined;
- function findLast(array: ReadonlyArray, predicate: (element: T, index: number) => element is U): U | undefined;
- function findLast(array: ReadonlyArray, predicate: (element: T, index: number) => boolean): T | undefined;
- /** Works like Array.prototype.findIndex, returning `-1` if no element satisfying the predicate is found. */
- function findIndex(array: ReadonlyArray, predicate: (element: T, index: number) => boolean, startIndex?: number): number;
- function findLastIndex(array: ReadonlyArray, predicate: (element: T, index: number) => boolean, startIndex?: number): number;
- /**
- * Returns the first truthy result of `callback`, or else fails.
- * This is like `forEach`, but never returns undefined.
- */
- function findMap(array: ReadonlyArray, callback: (element: T, index: number) => U | undefined): U;
- function contains(array: ReadonlyArray | undefined, value: T, equalityComparer?: EqualityComparer): boolean;
- function arraysEqual(a: ReadonlyArray, b: ReadonlyArray, equalityComparer?: EqualityComparer): boolean;
- function indexOfAnyCharCode(text: string, charCodes: ReadonlyArray, start?: number): number;
- function countWhere(array: ReadonlyArray, predicate: (x: T, i: number) => boolean): number;
- /**
- * Filters an array by a predicate function. Returns the same array instance if the predicate is
- * true for all elements, otherwise returns a new array instance containing the filtered subset.
- */
- function filter(array: T[], f: (x: T) => x is U): U[];
- function filter(array: T[], f: (x: T) => boolean): T[];
- function filter(array: ReadonlyArray, f: (x: T) => x is U): ReadonlyArray;
- function filter(array: ReadonlyArray, f: (x: T) => boolean): ReadonlyArray;
- function filter(array: T[] | undefined, f: (x: T) => x is U): U[] | undefined;
- function filter(array: T[] | undefined, f: (x: T) => boolean): T[] | undefined;
- function filter(array: ReadonlyArray | undefined, f: (x: T) => x is U): ReadonlyArray | undefined;
- function filter(array: ReadonlyArray | undefined, f: (x: T) => boolean): ReadonlyArray | undefined;
- function filterMutate(array: T[], f: (x: T, i: number, array: T[]) => boolean): void;
- function clear(array: {}[]): void;
- function map(array: ReadonlyArray, f: (x: T, i: number) => U): U[];
- function map(array: ReadonlyArray | undefined, f: (x: T, i: number) => U): U[] | undefined;
- function mapIterator(iter: Iterator, mapFn: (x: T) => U): Iterator;
- function sameMap(array: T[], f: (x: T, i: number) => T): T[];
- function sameMap(array: ReadonlyArray, f: (x: T, i: number) => T): ReadonlyArray;
- function sameMap(array: T[] | undefined, f: (x: T, i: number) => T): T[] | undefined;
- function sameMap(array: ReadonlyArray | undefined, f: (x: T, i: number) => T): ReadonlyArray | undefined;
- /**
- * Flattens an array containing a mix of array or non-array elements.
- *
- * @param array The array to flatten.
- */
- function flatten(array: T[][] | ReadonlyArray | undefined>): T[];
- /**
- * Maps an array. If the mapped value is an array, it is spread into the result.
- *
- * @param array The array to map.
- * @param mapfn The callback used to map the result into one or more values.
- */
- function flatMap(array: ReadonlyArray | undefined, mapfn: (x: T, i: number) => U | ReadonlyArray | undefined): ReadonlyArray;
- function flatMapToMutable(array: ReadonlyArray | undefined, mapfn: (x: T, i: number) => U | ReadonlyArray | undefined): U[];
- function flatMapIterator(iter: Iterator, mapfn: (x: T) => ReadonlyArray | Iterator | undefined): Iterator;
- /**
- * Maps an array. If the mapped value is an array, it is spread into the result.
- * Avoids allocation if all elements map to themselves.
- *
- * @param array The array to map.
- * @param mapfn The callback used to map the result into one or more values.
- */
- function sameFlatMap(array: T[], mapfn: (x: T, i: number) => T | ReadonlyArray): T[];
- function sameFlatMap(array: ReadonlyArray, mapfn: (x: T, i: number) => T | ReadonlyArray): ReadonlyArray;
- function mapAllOrFail(array: ReadonlyArray, mapFn: (x: T, i: number) => U | undefined): U[] | undefined;
- function mapDefined(array: ReadonlyArray | undefined, mapFn: (x: T, i: number) => U | undefined): U[];
- function mapDefinedIterator(iter: Iterator, mapFn: (x: T) => U | undefined): Iterator;
- const emptyIterator: Iterator;
- function singleIterator(value: T): Iterator;
- /**
- * Maps contiguous spans of values with the same key.
- *
- * @param array The array to map.
- * @param keyfn A callback used to select the key for an element.
- * @param mapfn A callback used to map a contiguous chunk of values to a single value.
- */
- function spanMap(array: ReadonlyArray, keyfn: (x: T, i: number) => K, mapfn: (chunk: T[], key: K, start: number, end: number) => U): U[];
- function spanMap(array: ReadonlyArray | undefined, keyfn: (x: T, i: number) => K, mapfn: (chunk: T[], key: K, start: number, end: number) => U): U[] | undefined;
- function mapEntries(map: ReadonlyMap, f: (key: string, value: T) => [string, U]): Map;
- function mapEntries(map: ReadonlyMap | undefined, f: (key: string, value: T) => [string, U]): Map | undefined;
- function some(array: ReadonlyArray | undefined): array is ReadonlyArray;
- function some(array: ReadonlyArray | undefined, predicate: (value: T) => boolean): boolean;
- /** Calls the callback with (start, afterEnd) index pairs for each range where 'pred' is true. */
- function getRangesWhere(arr: ReadonlyArray, pred: (t: T) => boolean, cb: (start: number, afterEnd: number) => void): void;
- function concatenate(array1: T[], array2: T[]): T[];
- function concatenate(array1: ReadonlyArray, array2: ReadonlyArray): ReadonlyArray;
- function concatenate(array1: T[] | undefined, array2: T[] | undefined): T[];
- function concatenate(array1: ReadonlyArray | undefined, array2: ReadonlyArray | undefined): ReadonlyArray;
- /**
- * Deduplicates an unsorted array.
- * @param equalityComparer An `EqualityComparer` used to determine if two values are duplicates.
- * @param comparer An optional `Comparer` used to sort entries before comparison, though the
- * result will remain in the original order in `array`.
- */
- function deduplicate(array: ReadonlyArray, equalityComparer: EqualityComparer, comparer?: Comparer): T[];
- function insertSorted(array: SortedArray, insert: T, compare: Comparer): void;
- function sortAndDeduplicate(array: ReadonlyArray): SortedReadonlyArray;
- function sortAndDeduplicate(array: ReadonlyArray, comparer: Comparer, equalityComparer?: EqualityComparer): SortedReadonlyArray;
- function arrayIsEqualTo(array1: ReadonlyArray | undefined, array2: ReadonlyArray | undefined, equalityComparer?: (a: T, b: T, index: number) => boolean): boolean;
- /**
- * Compacts an array, removing any falsey elements.
- */
- function compact(array: (T | undefined | null | false | 0 | "")[]): T[];
- function compact(array: ReadonlyArray): ReadonlyArray;
- function compact(array: T[]): T[];
- function compact(array: ReadonlyArray): ReadonlyArray;
- /**
- * Gets the relative complement of `arrayA` with respect to `arrayB`, returning the elements that
- * are not present in `arrayA` but are present in `arrayB`. Assumes both arrays are sorted
- * based on the provided comparer.
- */
- function relativeComplement(arrayA: T[] | undefined, arrayB: T[] | undefined, comparer: Comparer): T[] | undefined;
- function sum, K extends string>(array: ReadonlyArray, prop: K): number;
- /**
- * Appends a value to an array, returning the array.
- *
- * @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
- * is created if `value` was appended.
- * @param value The value to append to the array. If `value` is `undefined`, nothing is
- * appended.
- */
- function append[number] | undefined>(to: TArray, value: TValue): [undefined, undefined] extends [TArray, TValue] ? TArray : NonNullable[number][];
- function append(to: T[], value: T | undefined): T[];
- function append(to: T[] | undefined, value: T): T[];
- function append(to: T[] | undefined, value: T | undefined): T[] | undefined;
- function append(to: Push, value: T | undefined): void;
- /**
- * Appends a range of value to an array, returning the array.
- *
- * @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
- * is created if `value` was appended.
- * @param from The values to append to the array. If `from` is `undefined`, nothing is
- * appended. If an element of `from` is `undefined`, that element is not appended.
- * @param start The offset in `from` at which to start copying values.
- * @param end The offset in `from` at which to stop copying values (non-inclusive).
- */
- function addRange(to: T[], from: ReadonlyArray | undefined, start?: number, end?: number): T[];
- function addRange(to: T[] | undefined, from: ReadonlyArray | undefined, start?: number, end?: number): T[] | undefined;
- /**
- * @return Whether the value was added.
- */
- function pushIfUnique(array: T[], toAdd: T, equalityComparer?: EqualityComparer): boolean;
- /**
- * Unlike `pushIfUnique`, this can take `undefined` as an input, and returns a new array.
- */
- function appendIfUnique(array: T[] | undefined, toAdd: T, equalityComparer?: EqualityComparer): T[];
- /**
- * Returns a new sorted array.
- */
- function sort(array: ReadonlyArray, comparer?: Comparer): SortedReadonlyArray;
- function arrayIterator(array: ReadonlyArray): Iterator;
- function arrayReverseIterator(array: ReadonlyArray): Iterator;
- /**
- * Stable sort of an array. Elements equal to each other maintain their relative position in the array.
- */
- function stableSort(array: ReadonlyArray, comparer: Comparer): SortedReadonlyArray;
- function rangeEquals(array1: ReadonlyArray, array2: ReadonlyArray, pos: number, end: number): boolean;
- /**
- * Returns the element at a specific offset in an array if non-empty, `undefined` otherwise.
- * A negative offset indicates the element should be retrieved from the end of the array.
- */
- function elementAt(array: ReadonlyArray | undefined, offset: number): T | undefined;
- /**
- * Returns the first element of an array if non-empty, `undefined` otherwise.
- */
- function firstOrUndefined(array: ReadonlyArray): T | undefined;
- function first(array: ReadonlyArray): T;
- /**
- * Returns the last element of an array if non-empty, `undefined` otherwise.
- */
- function lastOrUndefined(array: ReadonlyArray): T | undefined;
- function last(array: ReadonlyArray): T;
- /**
- * Returns the only element of an array if it contains only one element, `undefined` otherwise.
- */
- function singleOrUndefined(array: ReadonlyArray | undefined): T | undefined;
- /**
- * Returns the only element of an array if it contains only one element; otherwise, returns the
- * array.
- */
- function singleOrMany(array: T[]): T | T[];
- function singleOrMany(array: ReadonlyArray): T | ReadonlyArray;
- function singleOrMany(array: T[] | undefined): T | T[] | undefined;
- function singleOrMany(array: ReadonlyArray | undefined): T | ReadonlyArray | undefined;
- function replaceElement(array: ReadonlyArray, index: number, value: T): T[];
- /**
- * Performs a binary search, finding the index at which `value` occurs in `array`.
- * If no such index is found, returns the 2's-complement of first index at which
- * `array[index]` exceeds `value`.
- * @param array A sorted array whose first element must be no larger than number
- * @param value The value to be searched for in the array.
- * @param keySelector A callback used to select the search key from `value` and each element of
- * `array`.
- * @param keyComparer A callback used to compare two keys in a sorted array.
- * @param offset An offset into `array` at which to start the search.
- */
- function binarySearch(array: ReadonlyArray, value: T, keySelector: (v: T) => U, keyComparer: Comparer, offset?: number): number;
- /**
- * Performs a binary search, finding the index at which an object with `key` occurs in `array`.
- * If no such index is found, returns the 2's-complement of first index at which
- * `array[index]` exceeds `key`.
- * @param array A sorted array whose first element must be no larger than number
- * @param key The key to be searched for in the array.
- * @param keySelector A callback used to select the search key from each element of `array`.
- * @param keyComparer A callback used to compare two keys in a sorted array.
- * @param offset An offset into `array` at which to start the search.
- */
- function binarySearchKey(array: ReadonlyArray, key: U, keySelector: (v: T) => U, keyComparer: Comparer, offset?: number): number;
- function reduceLeft