@silvermine/toolbox 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +49 -0
- package/.markdownlint.json +3 -0
- package/.nvmrc +1 -0
- package/CHANGELOG.md +20 -0
- package/README.md +7 -3
- package/dist/commonjs/index.js +3 -0
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/types/StrictUnion.js +4 -0
- package/dist/commonjs/types/StrictUnion.js.map +1 -0
- package/dist/commonjs/utils/pick.js +15 -0
- package/dist/commonjs/utils/pick.js.map +1 -0
- package/dist/commonjs/utils/uniq.js +49 -0
- package/dist/commonjs/utils/uniq.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/StrictUnion.js +2 -0
- package/dist/esm/types/StrictUnion.js.map +1 -0
- package/dist/esm/utils/pick.js +11 -0
- package/dist/esm/utils/pick.js.map +1 -0
- package/dist/esm/utils/uniq.js +46 -0
- package/dist/esm/utils/uniq.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/types/StrictUnion.d.ts +15 -0
- package/dist/types/utils/pick.d.ts +2 -0
- package/dist/types/utils/uniq.d.ts +8 -0
- package/package.json +16 -19
- package/src/index.ts +3 -0
- package/src/types/StrictUnion.ts +15 -0
- package/src/utils/pick.ts +24 -0
- package/src/utils/uniq.ts +59 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on: [ push, pull_request ]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
steps:
|
|
9
|
+
-
|
|
10
|
+
uses: actions/checkout@v4
|
|
11
|
+
with:
|
|
12
|
+
fetch-depth: 0 # Fetch all history
|
|
13
|
+
-
|
|
14
|
+
uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version-file: '.nvmrc'
|
|
17
|
+
- run: npm i -g npm@10.5.0
|
|
18
|
+
- run: npm ci
|
|
19
|
+
- run: npm run check-node-version
|
|
20
|
+
- run: npm run standards
|
|
21
|
+
test:
|
|
22
|
+
needs: [ build ]
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
strategy:
|
|
25
|
+
fail-fast: false
|
|
26
|
+
matrix:
|
|
27
|
+
node-version: [ 16, 20, 'lts/*', 'latest' ]
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@v4
|
|
30
|
+
-
|
|
31
|
+
name: Use Node.js ${{ matrix.node-version }}
|
|
32
|
+
uses: actions/setup-node@v4
|
|
33
|
+
with:
|
|
34
|
+
node-version: ${{ matrix.node-version }}
|
|
35
|
+
- run: npm ci # Reinstall the dependencies to ensure they install with the node's version of npm
|
|
36
|
+
- run: npm test
|
|
37
|
+
- name: Coveralls
|
|
38
|
+
uses: coverallsapp/github-action@v1
|
|
39
|
+
with:
|
|
40
|
+
parallel: true
|
|
41
|
+
flag-name: ${{ matrix.node-version }}
|
|
42
|
+
finish:
|
|
43
|
+
needs: [ test ]
|
|
44
|
+
runs-on: ubuntu-latest
|
|
45
|
+
steps:
|
|
46
|
+
- name: Close parallel build
|
|
47
|
+
uses: coverallsapp/github-action@v1
|
|
48
|
+
with:
|
|
49
|
+
parallel-finished: true
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
20.12.2
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [our coding standards][commit-messages] for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [0.3.0](https://github.com/silvermine/toolbox/compare/v0.2.0...v0.3.0) (2024-05-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add partial replacement of _.pick ([c7d143e](https://github.com/silvermine/toolbox/commit/c7d143e05867d2785de60ca4141aefb62361ac35))
|
|
12
|
+
* add replacement of _.uniq ([#23](https://github.com/silvermine/toolbox/issues/23)) ([4ece381](https://github.com/silvermine/toolbox/commit/4ece3819757dd2dbb354ad42bb496844a9cda67a))
|
|
13
|
+
* add StrictUnion ([22080e1](https://github.com/silvermine/toolbox/commit/22080e1b590b8c5ace25f544366a0807b355a27e))
|
|
14
|
+
|
|
15
|
+
### Other
|
|
16
|
+
|
|
17
|
+
* config: allow tslib 2.x as peer dep ([6320e11](https://github.com/silvermine/toolbox/commit/6320e11110deeb66008a58b0090e8dde6214cc11))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
[commit-messages]: https://github.com/silvermine/silvermine-info/blob/master/commit-history.md#commit-messages
|
package/README.md
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
# Silvermine Toolbox - TypeScript Types and Utilities
|
|
2
|
+
|
|
1
3
|
<p align="center">
|
|
2
|
-
|
|
4
|
+
<img width="300"
|
|
5
|
+
height="300"
|
|
6
|
+
src="https://raw.github.com/silvermine/toolbox/master/src/logo/toolbox.png"
|
|
7
|
+
alt="Tools such as a protractor, calculator, pencil, and a pen inside a shirt pocket."
|
|
8
|
+
>
|
|
3
9
|
</p>
|
|
4
10
|
|
|
5
|
-
# Silvermine Toolbox - TypeScript Types and Utilities
|
|
6
|
-
|
|
7
11
|
[](https://www.npmjs.com/package/@silvermine/toolbox)
|
|
8
12
|
[](./LICENSE)
|
|
9
13
|
[](https://travis-ci.com/silvermine/toolbox)
|
package/dist/commonjs/index.js
CHANGED
|
@@ -7,6 +7,7 @@ tslib_1.__exportStar(require("./types/Optional"), exports);
|
|
|
7
7
|
tslib_1.__exportStar(require("./types/PropsWithType"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./types/RequireDefined"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./types/RequireOptional"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./types/StrictUnion"), exports);
|
|
10
11
|
tslib_1.__exportStar(require("./types/StringArrayOfStringsMap"), exports);
|
|
11
12
|
tslib_1.__exportStar(require("./types/StringMap"), exports);
|
|
12
13
|
tslib_1.__exportStar(require("./types/StringUnknownMap"), exports);
|
|
@@ -28,9 +29,11 @@ tslib_1.__exportStar(require("./utils/is-null"), exports);
|
|
|
28
29
|
tslib_1.__exportStar(require("./utils/is-not-null-or-undefined"), exports);
|
|
29
30
|
tslib_1.__exportStar(require("./utils/chunk"), exports);
|
|
30
31
|
tslib_1.__exportStar(require("./utils/flatten"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./utils/pick"), exports);
|
|
31
33
|
tslib_1.__exportStar(require("./utils/pluck"), exports);
|
|
32
34
|
tslib_1.__exportStar(require("./utils/delay"), exports);
|
|
33
35
|
tslib_1.__exportStar(require("./utils/get"), exports);
|
|
34
36
|
tslib_1.__exportStar(require("./utils/escape-html"), exports);
|
|
35
37
|
tslib_1.__exportStar(require("./utils/make-template"), exports);
|
|
38
|
+
tslib_1.__exportStar(require("./utils/uniq"), exports);
|
|
36
39
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C;AAC7C,uDAA6B;AAC7B,2DAAiC;AACjC,gEAAsC;AACtC,iEAAuC;AACvC,kEAAwC;AACxC,0EAAgD;AAChD,4DAAkC;AAClC,mEAAyC;AACzC,2DAAiC;AAEjC,8DAAoC;AACpC,+DAAqC;AACrC,2DAAiC;AACjC,sEAA4C;AAC5C,2DAAiC;AACjC,gEAAsC;AACtC,6EAAmD;AACnD,4DAAkC;AAClC,4DAAkC;AAClC,6DAAmC;AACnC,kEAAwC;AACxC,4DAAkC;AAClC,+DAAqC;AACrC,0DAAgC;AAChC,2EAAiD;AAEjD,wDAA8B;AAC9B,0DAAgC;AAChC,wDAA8B;AAC9B,wDAA8B;AAC9B,sDAA4B;AAC5B,8DAAoC;AACpC,gEAAsC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C;AAC7C,uDAA6B;AAC7B,2DAAiC;AACjC,gEAAsC;AACtC,iEAAuC;AACvC,kEAAwC;AACxC,8DAAoC;AACpC,0EAAgD;AAChD,4DAAkC;AAClC,mEAAyC;AACzC,2DAAiC;AAEjC,8DAAoC;AACpC,+DAAqC;AACrC,2DAAiC;AACjC,sEAA4C;AAC5C,2DAAiC;AACjC,gEAAsC;AACtC,6EAAmD;AACnD,4DAAkC;AAClC,4DAAkC;AAClC,6DAAmC;AACnC,kEAAwC;AACxC,4DAAkC;AAClC,+DAAqC;AACrC,0DAAgC;AAChC,2EAAiD;AAEjD,wDAA8B;AAC9B,0DAAgC;AAChC,uDAA6B;AAC7B,wDAA8B;AAC9B,wDAA8B;AAC9B,sDAA4B;AAC5B,8DAAoC;AACpC,gEAAsC;AACtC,uDAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StrictUnion.js","sourceRoot":"","sources":["../../../src/types/StrictUnion.ts"],"names":[],"mappings":";AAAA,qDAAqD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pick = void 0;
|
|
4
|
+
const is_array_1 = require("./is-array");
|
|
5
|
+
function pick(obj, ...args) {
|
|
6
|
+
const props = ((args.length === 1 && is_array_1.isArray(args[0])) ? args[0] : args);
|
|
7
|
+
return props.reduce((memo, prop) => {
|
|
8
|
+
if (prop in obj) {
|
|
9
|
+
memo[prop] = obj[prop];
|
|
10
|
+
}
|
|
11
|
+
return memo;
|
|
12
|
+
}, {});
|
|
13
|
+
}
|
|
14
|
+
exports.pick = pick;
|
|
15
|
+
//# sourceMappingURL=pick.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pick.js","sourceRoot":"","sources":["../../../src/utils/pick.ts"],"names":[],"mappings":";;;AAAA,yCAAqC;AAcrC,SAAgB,IAAI,CAAsC,GAAM,EAAE,GAAG,IAAmB;IACrF,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,kBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAQ,CAAC;IAEhF,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QAChC,IAAI,IAAI,IAAI,GAAG,EAAE;YACd,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;SACzB;QACD,OAAO,IAAI,CAAC;IACf,CAAC,EAAE,EAAgB,CAAC,CAAC;AACxB,CAAC;AATD,oBASC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uniq = void 0;
|
|
4
|
+
const iterateeUniq = (arr, iteratee) => {
|
|
5
|
+
const result = [], seen = [];
|
|
6
|
+
for (let i = 0, length = arr.length; i < length; i++) {
|
|
7
|
+
let value = arr[i], computed = iteratee(value, i, arr);
|
|
8
|
+
if (seen.indexOf(computed) === -1) {
|
|
9
|
+
seen.push(computed);
|
|
10
|
+
result.push(value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
15
|
+
const sortedUniq = (arr) => {
|
|
16
|
+
const result = [];
|
|
17
|
+
let lastSeen;
|
|
18
|
+
for (let i = 0, length = arr.length; i < length; i++) {
|
|
19
|
+
let value = arr[i];
|
|
20
|
+
if (i === 0 || lastSeen !== value) {
|
|
21
|
+
result.push(value);
|
|
22
|
+
}
|
|
23
|
+
lastSeen = value;
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
const standardUniq = (arr) => {
|
|
28
|
+
const result = arr.filter((value, index, _arr) => {
|
|
29
|
+
return _arr.indexOf(value) === index;
|
|
30
|
+
});
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Produce a duplicate-free version of the array. If the array has already
|
|
35
|
+
* been sorted, you have the option of using a faster algorithm.
|
|
36
|
+
* The faster algorithm will not work with an iteratee if the iteratee
|
|
37
|
+
* is not a one-to-one function, so providing an iteratee will disable
|
|
38
|
+
* the faster algorithm.
|
|
39
|
+
*/
|
|
40
|
+
exports.uniq = (arr, isSorted, iteratee) => {
|
|
41
|
+
if (iteratee) {
|
|
42
|
+
return iterateeUniq(arr, iteratee);
|
|
43
|
+
}
|
|
44
|
+
if (isSorted) {
|
|
45
|
+
return sortedUniq(arr);
|
|
46
|
+
}
|
|
47
|
+
return standardUniq(arr);
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=uniq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniq.js","sourceRoot":"","sources":["../../../src/utils/uniq.ts"],"names":[],"mappings":";;;AAAA,MAAM,YAAY,GAAG,CAAO,GAAQ,EAAE,QAA8C,EAAO,EAAE;IAC1F,MAAM,MAAM,GAAQ,EAAE,EAChB,IAAI,GAAQ,EAAE,CAAC;IAErB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;QACnD,IAAI,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,EACd,QAAQ,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;QAEvC,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE;YAChC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACp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|
|
4
4
|
export * from './types/PropsWithType';
|
|
5
5
|
export * from './types/RequireDefined';
|
|
6
6
|
export * from './types/RequireOptional';
|
|
7
|
+
export * from './types/StrictUnion';
|
|
7
8
|
export * from './types/StringArrayOfStringsMap';
|
|
8
9
|
export * from './types/StringMap';
|
|
9
10
|
export * from './types/StringUnknownMap';
|
|
@@ -25,9 +26,11 @@ export * from './utils/is-null';
|
|
|
25
26
|
export * from './utils/is-not-null-or-undefined';
|
|
26
27
|
export * from './utils/chunk';
|
|
27
28
|
export * from './utils/flatten';
|
|
29
|
+
export * from './utils/pick';
|
|
28
30
|
export * from './utils/pluck';
|
|
29
31
|
export * from './utils/delay';
|
|
30
32
|
export * from './utils/get';
|
|
31
33
|
export * from './utils/escape-html';
|
|
32
34
|
export * from './utils/make-template';
|
|
35
|
+
export * from './utils/uniq';
|
|
33
36
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC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cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StrictUnion.js","sourceRoot":"","sources":["../../../src/types/StrictUnion.ts"],"names":[],"mappings":"AAAA,qDAAqD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isArray } from './is-array';
|
|
2
|
+
export function pick(obj, ...args) {
|
|
3
|
+
const props = ((args.length === 1 && isArray(args[0])) ? args[0] : args);
|
|
4
|
+
return props.reduce((memo, prop) => {
|
|
5
|
+
if (prop in obj) {
|
|
6
|
+
memo[prop] = obj[prop];
|
|
7
|
+
}
|
|
8
|
+
return memo;
|
|
9
|
+
}, {});
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=pick.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pick.js","sourceRoot":"","sources":["../../../src/utils/pick.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAcrC,MAAM,UAAU,IAAI,CAAsC,GAAM,EAAE,GAAG,IAAmB;IACrF,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAQ,CAAC;IAEhF,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QAChC,IAAI,IAAI,IAAI,GAAG,EAAE;YACd,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;SACzB;QACD,OAAO,IAAI,CAAC;IACf,CAAC,EAAE,EAAgB,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const iterateeUniq = (arr, iteratee) => {
|
|
2
|
+
const result = [], seen = [];
|
|
3
|
+
for (let i = 0, length = arr.length; i < length; i++) {
|
|
4
|
+
let value = arr[i], computed = iteratee(value, i, arr);
|
|
5
|
+
if (seen.indexOf(computed) === -1) {
|
|
6
|
+
seen.push(computed);
|
|
7
|
+
result.push(value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
const sortedUniq = (arr) => {
|
|
13
|
+
const result = [];
|
|
14
|
+
let lastSeen;
|
|
15
|
+
for (let i = 0, length = arr.length; i < length; i++) {
|
|
16
|
+
let value = arr[i];
|
|
17
|
+
if (i === 0 || lastSeen !== value) {
|
|
18
|
+
result.push(value);
|
|
19
|
+
}
|
|
20
|
+
lastSeen = value;
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
const standardUniq = (arr) => {
|
|
25
|
+
const result = arr.filter((value, index, _arr) => {
|
|
26
|
+
return _arr.indexOf(value) === index;
|
|
27
|
+
});
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Produce a duplicate-free version of the array. If the array has already
|
|
32
|
+
* been sorted, you have the option of using a faster algorithm.
|
|
33
|
+
* The faster algorithm will not work with an iteratee if the iteratee
|
|
34
|
+
* is not a one-to-one function, so providing an iteratee will disable
|
|
35
|
+
* the faster algorithm.
|
|
36
|
+
*/
|
|
37
|
+
export const uniq = (arr, isSorted, iteratee) => {
|
|
38
|
+
if (iteratee) {
|
|
39
|
+
return iterateeUniq(arr, iteratee);
|
|
40
|
+
}
|
|
41
|
+
if (isSorted) {
|
|
42
|
+
return sortedUniq(arr);
|
|
43
|
+
}
|
|
44
|
+
return standardUniq(arr);
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=uniq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniq.js","sourceRoot":"","sources":["../../../src/utils/uniq.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,C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KAAK,CAAC,KAAK,KAAK,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AACjB,CAAC,CAAC;AAGF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAO,GAAQ,EAAE,QAAkB,EAAE,QAA+C,EAAO,EAAE;IAC9G,IAAI,QAAQ,EAAE;QACX,OAAO,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;KACrC;IACD,IAAI,QAAQ,EAAE;QACX,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;KACzB;IACD,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './types/Optional';
|
|
|
4
4
|
export * from './types/PropsWithType';
|
|
5
5
|
export * from './types/RequireDefined';
|
|
6
6
|
export * from './types/RequireOptional';
|
|
7
|
+
export * from './types/StrictUnion';
|
|
7
8
|
export * from './types/StringArrayOfStringsMap';
|
|
8
9
|
export * from './types/StringMap';
|
|
9
10
|
export * from './types/StringUnknownMap';
|
|
@@ -25,8 +26,10 @@ export * from './utils/is-null';
|
|
|
25
26
|
export * from './utils/is-not-null-or-undefined';
|
|
26
27
|
export * from './utils/chunk';
|
|
27
28
|
export * from './utils/flatten';
|
|
29
|
+
export * from './utils/pick';
|
|
28
30
|
export * from './utils/pluck';
|
|
29
31
|
export * from './utils/delay';
|
|
30
32
|
export * from './utils/get';
|
|
31
33
|
export * from './utils/escape-html';
|
|
32
34
|
export * from './utils/make-template';
|
|
35
|
+
export * from './utils/uniq';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare type UnionKeys<T> = T extends unknown ? keyof T : never;
|
|
2
|
+
declare type InvalidKeys<K extends string | number | symbol> = {
|
|
3
|
+
[P in K]?: never;
|
|
4
|
+
};
|
|
5
|
+
declare type StrictUnionHelper<T, TAll> = T extends unknown ? (T & InvalidKeys<Exclude<UnionKeys<TAll>, keyof T>>) : never;
|
|
6
|
+
/**
|
|
7
|
+
* A basic TypeScript union (e.g. A | B) results in a type containing the available
|
|
8
|
+
* properties from the provided types. When StrictUnion is used (e.g. StrictUnion<A | B>),
|
|
9
|
+
* the resulting type can only contain the properties from one of the types (e.g. all the
|
|
10
|
+
* properties from A, but none of the properties from B).
|
|
11
|
+
*
|
|
12
|
+
* See: https://github.com/microsoft/TypeScript/issues/20863#issuecomment-520551758
|
|
13
|
+
*/
|
|
14
|
+
export declare type StrictUnion<T> = StrictUnionHelper<T, T>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Produce a duplicate-free version of the array. If the array has already
|
|
3
|
+
* been sorted, you have the option of using a faster algorithm.
|
|
4
|
+
* The faster algorithm will not work with an iteratee if the iteratee
|
|
5
|
+
* is not a one-to-one function, so providing an iteratee will disable
|
|
6
|
+
* the faster algorithm.
|
|
7
|
+
*/
|
|
8
|
+
export declare const uniq: <T, U>(arr: T[], isSorted?: boolean | undefined, iteratee?: ((value: T, i: number, arr: T[]) => U) | undefined) => T[];
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@silvermine/toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A library of common TypeScript types, custom type guards, and utility functions.",
|
|
5
5
|
"main": "./dist/commonjs/index",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
7
7
|
"module": "./dist/esm/index",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"prepare": "grunt build",
|
|
10
|
-
"
|
|
11
|
-
"test": "
|
|
12
|
-
"
|
|
10
|
+
"check-node-version": "check-node-version --npm 10.5.0 --print",
|
|
11
|
+
"test": "TS_NODE_PROJECT='tests/tsconfig.json' TS_NODE_FILES=true nyc mocha --opts ./.mocha.opts",
|
|
12
|
+
"eslint": "eslint '{,!(node_modules|dist)/**/}*.{js,ts}'",
|
|
13
|
+
"markdownlint": "markdownlint -c .markdownlint.json -i CHANGELOG.md '{,!(node_modules)/**/}*.md'",
|
|
14
|
+
"commitlint": "commitlint --from 0b9d320",
|
|
15
|
+
"standards": "npm run markdownlint && npm run eslint",
|
|
16
|
+
"release:preview": "node ./node_modules/@silvermine/standardization/scripts/release.js preview",
|
|
17
|
+
"release:prep-changelog": "node ./node_modules/@silvermine/standardization/scripts/release.js prep-changelog",
|
|
18
|
+
"release:finalize": "node ./node_modules/@silvermine/standardization/scripts/release.js finalize"
|
|
13
19
|
},
|
|
14
20
|
"author": "Matt Luedke",
|
|
15
21
|
"license": "MIT",
|
|
@@ -27,13 +33,13 @@
|
|
|
27
33
|
"type guards"
|
|
28
34
|
],
|
|
29
35
|
"peerDependencies": {
|
|
30
|
-
"tslib": "1.9.
|
|
36
|
+
"tslib": "^1.9.0 || ^2"
|
|
31
37
|
},
|
|
32
38
|
"devDependencies": {
|
|
33
39
|
"@silvermine/chai-strictly-equal": "1.1.0",
|
|
34
|
-
"@silvermine/eslint-config": "
|
|
35
|
-
"@silvermine/standardization": "
|
|
36
|
-
"@silvermine/typescript-config": "git+https://github.com/silvermine/typescript-config
|
|
40
|
+
"@silvermine/eslint-config": "github:silvermine/eslint-config-silvermine#39387feb42f5d78bf4947fbb7cb0727b5ea2bebe",
|
|
41
|
+
"@silvermine/standardization": "2.0.0",
|
|
42
|
+
"@silvermine/typescript-config": "git+https://github.com/silvermine/typescript-config#23213e33077089e723629dead5342abe6f3b3c8c",
|
|
37
43
|
"@types/chai": "4.1.7",
|
|
38
44
|
"@types/mocha": "5.2.5",
|
|
39
45
|
"@types/node": "12.20.45",
|
|
@@ -41,28 +47,19 @@
|
|
|
41
47
|
"chai": "4.2.0",
|
|
42
48
|
"check-node-version": "4.0.2",
|
|
43
49
|
"coveralls": "3.0.9",
|
|
44
|
-
"
|
|
45
|
-
"eslint": "6.8.0",
|
|
50
|
+
"eslint": "8.0.0",
|
|
46
51
|
"grunt": "1.0.4",
|
|
47
52
|
"grunt-cli": "1.3.2",
|
|
48
53
|
"grunt-concurrent": "2.3.1",
|
|
49
54
|
"grunt-contrib-clean": "2.0.0",
|
|
50
55
|
"grunt-contrib-watch": "1.1.0",
|
|
51
|
-
"grunt-eslint": "24.0.0",
|
|
52
56
|
"grunt-exec": "3.0.0",
|
|
53
57
|
"mocha": "5.2.0",
|
|
54
58
|
"nyc": "13.1.0",
|
|
55
59
|
"sinon": "5.1.1",
|
|
56
60
|
"source-map-support": "0.5.16",
|
|
57
|
-
"standard-version": "5.0.2",
|
|
58
61
|
"ts-node": "7.0.1",
|
|
59
|
-
"tslib": "
|
|
62
|
+
"tslib": "2.6.2",
|
|
60
63
|
"typescript": "3.9.5"
|
|
61
|
-
},
|
|
62
|
-
"dependencies": {},
|
|
63
|
-
"config": {
|
|
64
|
-
"commitizen": {
|
|
65
|
-
"path": "./node_modules/cz-conventional-changelog"
|
|
66
|
-
}
|
|
67
64
|
}
|
|
68
65
|
}
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './types/Optional';
|
|
|
4
4
|
export * from './types/PropsWithType';
|
|
5
5
|
export * from './types/RequireDefined';
|
|
6
6
|
export * from './types/RequireOptional';
|
|
7
|
+
export * from './types/StrictUnion';
|
|
7
8
|
export * from './types/StringArrayOfStringsMap';
|
|
8
9
|
export * from './types/StringMap';
|
|
9
10
|
export * from './types/StringUnknownMap';
|
|
@@ -27,8 +28,10 @@ export * from './utils/is-not-null-or-undefined';
|
|
|
27
28
|
|
|
28
29
|
export * from './utils/chunk';
|
|
29
30
|
export * from './utils/flatten';
|
|
31
|
+
export * from './utils/pick';
|
|
30
32
|
export * from './utils/pluck';
|
|
31
33
|
export * from './utils/delay';
|
|
32
34
|
export * from './utils/get';
|
|
33
35
|
export * from './utils/escape-html';
|
|
34
36
|
export * from './utils/make-template';
|
|
37
|
+
export * from './utils/uniq';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-type-alias */
|
|
2
|
+
|
|
3
|
+
type UnionKeys<T> = T extends unknown ? keyof T : never;
|
|
4
|
+
type InvalidKeys<K extends string | number | symbol> = { [P in K]?: never };
|
|
5
|
+
type StrictUnionHelper<T, TAll> = T extends unknown ? (T & InvalidKeys<Exclude<UnionKeys<TAll>, keyof T>>) : never;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A basic TypeScript union (e.g. A | B) results in a type containing the available
|
|
9
|
+
* properties from the provided types. When StrictUnion is used (e.g. StrictUnion<A | B>),
|
|
10
|
+
* the resulting type can only contain the properties from one of the types (e.g. all the
|
|
11
|
+
* properties from A, but none of the properties from B).
|
|
12
|
+
*
|
|
13
|
+
* See: https://github.com/microsoft/TypeScript/issues/20863#issuecomment-520551758
|
|
14
|
+
*/
|
|
15
|
+
export type StrictUnion<T> = StrictUnionHelper<T, T>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isArray } from './is-array';
|
|
2
|
+
|
|
3
|
+
// NOTE: If changing these types, ensure the following cases cause a type error:
|
|
4
|
+
//
|
|
5
|
+
// const noProps = pick({ a: 1 });
|
|
6
|
+
//
|
|
7
|
+
// noProps.a; // Property 'a' does not exist on type 'Pick<{ a: number; }, never>'.
|
|
8
|
+
//
|
|
9
|
+
// const emptyArr = pick({ a: 1 }, []);
|
|
10
|
+
//
|
|
11
|
+
// emptyArr.a; // Property 'a' does not exist on type 'Pick<{ a: number; }, never>'.
|
|
12
|
+
|
|
13
|
+
export function pick<T extends object, K extends keyof T>(obj: T, props: K[]): Pick<T, K>;
|
|
14
|
+
export function pick<T extends object, K extends keyof T = never>(obj: T, ...props: K[]): Pick<T, K>;
|
|
15
|
+
export function pick<T extends object, K extends keyof T>(obj: T, ...args: K[] | [ K[] ]): Pick<T, K> {
|
|
16
|
+
const props = ((args.length === 1 && isArray(args[0])) ? args[0] : args) as K[];
|
|
17
|
+
|
|
18
|
+
return props.reduce((memo, prop) => {
|
|
19
|
+
if (prop in obj) {
|
|
20
|
+
memo[prop] = obj[prop];
|
|
21
|
+
}
|
|
22
|
+
return memo;
|
|
23
|
+
}, {} as Pick<T, K>);
|
|
24
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const iterateeUniq = <T, U>(arr: T[], iteratee: (value: T, i: number, arr: T[]) => U): T[] => {
|
|
2
|
+
const result: T[] = [],
|
|
3
|
+
seen: U[] = [];
|
|
4
|
+
|
|
5
|
+
for (let i = 0, length = arr.length; i < length; i++) {
|
|
6
|
+
let value = arr[i],
|
|
7
|
+
computed = iteratee(value, i, arr);
|
|
8
|
+
|
|
9
|
+
if (seen.indexOf(computed) === -1) {
|
|
10
|
+
seen.push(computed);
|
|
11
|
+
result.push(value);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const sortedUniq = <T, U>(arr: T[]): T[] => {
|
|
19
|
+
const result: T[] = [];
|
|
20
|
+
|
|
21
|
+
let lastSeen: T | U | undefined;
|
|
22
|
+
|
|
23
|
+
for (let i = 0, length = arr.length; i < length; i++) {
|
|
24
|
+
let value = arr[i];
|
|
25
|
+
|
|
26
|
+
if (i === 0 || lastSeen !== value) {
|
|
27
|
+
result.push(value);
|
|
28
|
+
}
|
|
29
|
+
lastSeen = value;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const standardUniq = <T>(arr: T[]): T[] => {
|
|
36
|
+
const result = arr.filter((value, index, _arr) => {
|
|
37
|
+
return _arr.indexOf(value) === index;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Produce a duplicate-free version of the array. If the array has already
|
|
46
|
+
* been sorted, you have the option of using a faster algorithm.
|
|
47
|
+
* The faster algorithm will not work with an iteratee if the iteratee
|
|
48
|
+
* is not a one-to-one function, so providing an iteratee will disable
|
|
49
|
+
* the faster algorithm.
|
|
50
|
+
*/
|
|
51
|
+
export const uniq = <T, U>(arr: T[], isSorted?: boolean, iteratee?: (value: T, i: number, arr: T[]) => U): T[] => {
|
|
52
|
+
if (iteratee) {
|
|
53
|
+
return iterateeUniq(arr, iteratee);
|
|
54
|
+
}
|
|
55
|
+
if (isSorted) {
|
|
56
|
+
return sortedUniq(arr);
|
|
57
|
+
}
|
|
58
|
+
return standardUniq(arr);
|
|
59
|
+
};
|