@vanillaes/absurdum 2.0.6 → 2.0.10
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/README.md +3 -3
- package/index.d.ts +3 -3
- package/index.js +2 -0
- package/index.min.js +3 -3
- package/package.json +16 -17
- package/src/arrays/chunk.d.ts +5 -6
- package/src/arrays/chunk.js +6 -6
- package/src/arrays/compact.d.ts +4 -5
- package/src/arrays/compact.js +5 -6
- package/src/arrays/difference.d.ts +5 -6
- package/src/arrays/difference.js +6 -7
- package/src/arrays/drop.d.ts +5 -6
- package/src/arrays/drop.js +5 -6
- package/src/arrays/dropRight.d.ts +5 -6
- package/src/arrays/dropRight.js +5 -6
- package/src/arrays/fill.d.ts +6 -7
- package/src/arrays/fill.js +5 -6
- package/src/arrays/filter.d.ts +4 -5
- package/src/arrays/filter.js +5 -6
- package/src/arrays/find.d.ts +3 -4
- package/src/arrays/find.js +7 -6
- package/src/arrays/findIndex.d.ts +3 -4
- package/src/arrays/findIndex.js +3 -4
- package/src/arrays/findLastIndex.d.ts +3 -4
- package/src/arrays/findLastIndex.js +4 -5
- package/src/arrays/flat.d.ts +5 -6
- package/src/arrays/flat.js +5 -6
- package/src/arrays/frequency.d.ts +6 -5
- package/src/arrays/frequency.js +8 -7
- package/src/arrays/intersection.d.ts +5 -6
- package/src/arrays/intersection.js +7 -6
- package/src/arrays/map.d.ts +4 -5
- package/src/arrays/map.js +5 -6
- package/src/arrays/pull.d.ts +4 -5
- package/src/arrays/pull.js +5 -6
- package/src/arrays/take.d.ts +5 -6
- package/src/arrays/take.js +5 -6
- package/src/arrays/takeRight.d.ts +5 -6
- package/src/arrays/takeRight.js +5 -6
- package/src/arrays/union.d.ts +4 -5
- package/src/arrays/union.js +4 -5
- package/src/arrays/unique.d.ts +4 -5
- package/src/arrays/unique.js +4 -5
- package/src/arrays/unzip.d.ts +4 -5
- package/src/arrays/unzip.js +6 -5
- package/src/arrays/without.d.ts +4 -4
- package/src/arrays/without.js +5 -6
- package/src/arrays/xor.d.ts +4 -5
- package/src/arrays/xor.js +5 -6
- package/src/arrays/zip.d.ts +6 -7
- package/src/arrays/zip.js +7 -8
- package/src/objects/assign.d.ts +1 -3
- package/src/objects/assign.js +3 -3
- package/src/objects/at.d.ts +2 -4
- package/src/objects/at.js +3 -3
- package/src/objects/defaults.d.ts +1 -3
- package/src/objects/defaults.js +3 -3
- package/src/objects/defaultsDeep.d.ts +1 -3
- package/src/objects/defaultsDeep.js +3 -3
- package/src/objects/entries.d.ts +1 -3
- package/src/objects/entries.js +3 -3
- package/src/objects/filter.d.ts +3 -5
- package/src/objects/filter.js +2 -3
- package/src/objects/findKey.d.ts +2 -4
- package/src/objects/findKey.js +2 -3
- package/src/objects/findLastKey.d.ts +2 -4
- package/src/objects/findLastKey.js +2 -3
- package/src/objects/forIn.d.ts +3 -5
- package/src/objects/forIn.js +3 -4
- package/src/objects/fromEntries.d.ts +1 -3
- package/src/objects/fromEntries.js +3 -3
- package/src/objects/get.d.ts +1 -4
- package/src/objects/get.js +2 -3
- package/src/objects/has.d.ts +1 -4
- package/src/objects/has.js +3 -3
- package/src/objects/invert.d.ts +1 -3
- package/src/objects/invert.js +3 -3
- package/src/objects/mapKeys.d.ts +3 -5
- package/src/objects/mapKeys.js +2 -3
- package/src/objects/mapValues.d.ts +3 -5
- package/src/objects/mapValues.js +2 -3
- package/src/objects/merge.d.ts +1 -3
- package/src/objects/merge.js +3 -3
- package/src/objects/pick.d.ts +1 -3
- package/src/objects/pick.js +3 -3
- package/src/objects/result.d.ts +1 -4
- package/src/objects/result.js +2 -3
- package/src/objects/transform.d.ts +3 -5
- package/src/objects/transform.js +2 -3
- package/src/objects/values.d.ts +2 -4
- package/src/objects/values.js +3 -3
- package/src/strings/camelCase.d.ts +2 -4
- package/src/strings/camelCase.js +2 -4
- package/src/strings/chomp.d.ts +1 -4
- package/src/strings/chomp.js +1 -3
- package/src/strings/deburr.d.ts +2 -4
- package/src/strings/deburr.js +3 -4
- package/src/strings/endsWith.d.ts +1 -4
- package/src/strings/endsWith.js +3 -3
- package/src/strings/includes.d.ts +1 -3
- package/src/strings/includes.js +1 -3
- package/src/strings/kebabCase.d.ts +2 -4
- package/src/strings/kebabCase.js +2 -4
- package/src/strings/pad.d.ts +2 -6
- package/src/strings/pad.js +1 -3
- package/src/strings/padEnd.d.ts +2 -6
- package/src/strings/padEnd.js +2 -4
- package/src/strings/padStart.d.ts +2 -6
- package/src/strings/padStart.js +2 -4
- package/src/strings/pascalCase.d.ts +2 -4
- package/src/strings/pascalCase.js +2 -4
- package/src/strings/repeat.d.ts +1 -3
- package/src/strings/repeat.js +1 -3
- package/src/strings/reverse.d.ts +0 -2
- package/src/strings/reverse.js +1 -3
- package/src/strings/snakeCase.d.ts +2 -4
- package/src/strings/snakeCase.js +2 -4
- package/src/strings/startsWith.d.ts +0 -3
- package/src/strings/startsWith.js +3 -3
- package/src/strings/trimEnd.d.ts +3 -5
- package/src/strings/trimEnd.js +2 -4
- package/src/strings/trimStart.d.ts +3 -5
- package/src/strings/trimStart.js +2 -4
- package/src/strings/truncate.d.ts +9 -11
- package/src/strings/truncate.js +3 -5
- package/src/strings/words.d.ts +3 -7
- package/src/strings/words.js +3 -5
package/src/arrays/zip.js
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Zip applies a specified function to the corresponding elements of two sequences,
|
|
5
5
|
* producing a sequence of the results.
|
|
6
|
-
* @
|
|
7
|
-
* @param {
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {T[]} arrayA input array
|
|
8
|
+
* @param {T[]} ArrayB input array
|
|
8
9
|
* @param {Function} [func] to be applied to corresponding values (default (a, b)=>[a, b])
|
|
9
|
-
* @returns {
|
|
10
|
+
* @returns {T[]} input array filled value pairs after the function has been applied
|
|
10
11
|
* @example
|
|
11
12
|
* const result = zip([5, 12, 8, 130, 44], ["ham", "cheese", "bread"]);
|
|
12
13
|
* console.log(result)
|
|
@@ -16,21 +17,19 @@
|
|
|
16
17
|
* console.log(result)
|
|
17
18
|
* > [ 'ham 5', 'cheese 12', 'bread 8' ]
|
|
18
19
|
*/
|
|
19
|
-
function zip (arrayA, ArrayB, func = (a, b) => [a, b]) {
|
|
20
|
+
export function zip (arrayA, ArrayB, func = (/** @type {T} */ a, /** @type {T} */ b) => [a, b]) {
|
|
20
21
|
if (func && typeof func !== 'function') {
|
|
21
22
|
throw TypeError('func must be a function')
|
|
22
23
|
}
|
|
23
24
|
if (arrayA.length <= ArrayB.length) {
|
|
24
|
-
return arrayA.reduce((res, cur, i) => {
|
|
25
|
+
return arrayA.reduce((/** @type {T[]} */ res, cur, i) => {
|
|
25
26
|
res[i] = func(cur, ArrayB[i])
|
|
26
27
|
return res
|
|
27
28
|
}, [])
|
|
28
29
|
} else {
|
|
29
|
-
return ArrayB.reduce((res, cur, i) => {
|
|
30
|
+
return ArrayB.reduce((/** @type {T[]} */ res, cur, i) => {
|
|
30
31
|
res[i] = func(arrayA[i], cur)
|
|
31
32
|
return res
|
|
32
33
|
}, [])
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
export { zip }
|
package/src/objects/assign.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Assign merges object properties from all supplied objects. If a property
|
|
3
3
|
* already exists, then it is overwritten when merged from left to right.
|
|
4
|
-
*
|
|
5
4
|
* @param {object} object input object
|
|
6
5
|
* @param {...object} sources input source object(s)
|
|
7
6
|
* @returns {object} returns new object
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
8
|
* const someObj = { hold: 44, fast: 14 };
|
|
11
9
|
* const result = objects.assign(someObj, { hold: 25, your: 19, horses: 4 });
|
|
12
10
|
* console.log(result);
|
|
13
11
|
* > { hold: 25, fast: 14, your: 19, horses: 4 }
|
|
14
12
|
*/
|
|
15
|
-
export function assign(object:
|
|
13
|
+
export function assign(object: object, ...sources: object[]): object;
|
package/src/objects/assign.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Assign merges object properties from all supplied objects. If a property
|
|
3
5
|
* already exists, then it is overwritten when merged from left to right.
|
|
@@ -10,7 +12,7 @@
|
|
|
10
12
|
* console.log(result);
|
|
11
13
|
* > { hold: 25, fast: 14, your: 19, horses: 4 }
|
|
12
14
|
*/
|
|
13
|
-
function assign (object, ...sources) {
|
|
15
|
+
export function assign (object, ...sources) {
|
|
14
16
|
if (arguments.length < 2) { return arguments.length === 1 ? object : {} }
|
|
15
17
|
const result = [object, ...sources]
|
|
16
18
|
|
|
@@ -22,5 +24,3 @@ function assign (object, ...sources) {
|
|
|
22
24
|
return acc
|
|
23
25
|
}, {})
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
export { assign }
|
package/src/objects/at.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* At, creates an array of values corresponding to paths of the object
|
|
3
|
-
*
|
|
4
3
|
* @param {object} object input object
|
|
5
4
|
* @param {...(string|string[])} paths strings describing paths to be returned from an object
|
|
6
|
-
* @returns {
|
|
7
|
-
*
|
|
5
|
+
* @returns {Array} array of values found by object paths in object
|
|
8
6
|
* @example
|
|
9
7
|
* const result = objects.at({ a: [13, 64], ']': 'b' });
|
|
10
8
|
* console.log(result, 'a[1]');
|
|
11
9
|
* > [64]
|
|
12
10
|
*/
|
|
13
|
-
export function at(object:
|
|
11
|
+
export function at(object: object, ...paths: (string | string[])[]): any[];
|
package/src/objects/at.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* At, creates an array of values corresponding to paths of the object
|
|
3
5
|
* @param {object} object input object
|
|
@@ -8,7 +10,7 @@
|
|
|
8
10
|
* console.log(result, 'a[1]');
|
|
9
11
|
* > [64]
|
|
10
12
|
*/
|
|
11
|
-
function at (object, ...paths) {
|
|
13
|
+
export function at (object, ...paths) {
|
|
12
14
|
if (paths.length === 0) { return [] }
|
|
13
15
|
|
|
14
16
|
const pathArray = []
|
|
@@ -38,5 +40,3 @@ function at (object, ...paths) {
|
|
|
38
40
|
return acc
|
|
39
41
|
}, [])
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
export { at }
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Defaults recursively merges object properties from all supplied objects. If a property
|
|
3
3
|
* already exists, then the existing one is kept when merged from left to right.
|
|
4
|
-
*
|
|
5
4
|
* @param {object} object input object
|
|
6
5
|
* @param {...object} sources input source object(s)
|
|
7
6
|
* @returns {object} returns new object
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
8
|
* const someObj = { hold: 44 };
|
|
11
9
|
* const result = objects.defaults(someObj, { hold: 25, your: 19, horses: 4 });
|
|
12
10
|
* console.log(result);
|
|
13
11
|
* > { hold: 44, your: 19, horses: 4 }
|
|
14
12
|
*/
|
|
15
|
-
export function defaults(object:
|
|
13
|
+
export function defaults(object: object, ...sources: object[]): object;
|
package/src/objects/defaults.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Defaults recursively merges object properties from all supplied objects. If a property
|
|
3
5
|
* already exists, then the existing one is kept when merged from left to right.
|
|
@@ -10,7 +12,7 @@
|
|
|
10
12
|
* console.log(result);
|
|
11
13
|
* > { hold: 44, your: 19, horses: 4 }
|
|
12
14
|
*/
|
|
13
|
-
function defaults (object, ...sources) {
|
|
15
|
+
export function defaults (object, ...sources) {
|
|
14
16
|
if (arguments.length < 2) { return arguments.length === 1 ? object : {} }
|
|
15
17
|
const result = [object, ...sources]
|
|
16
18
|
|
|
@@ -22,5 +24,3 @@ function defaults (object, ...sources) {
|
|
|
22
24
|
return acc
|
|
23
25
|
}, {})
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
export { defaults }
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* DefaultsDeep recursively merges object properties from all supplied objects with object values
|
|
3
3
|
* being merged recursively and once a property is set, additional values of the same property are ignored.
|
|
4
|
-
*
|
|
5
4
|
* @param {object} object input object
|
|
6
5
|
* @param {...object} sources input source object(s)
|
|
7
6
|
* @returns {object} returns an object with all included object properties merged
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
8
|
* const result = objects.defaultsDeep({ a: { b: [3, 4] } }, { a: { b: [9, 18, 15], c: 3 } });
|
|
11
9
|
* console.log(result);
|
|
12
10
|
* > { a: { b: [ 3, 4, 15 ], c: 3 } }
|
|
13
11
|
*/
|
|
14
|
-
export function defaultsDeep(object:
|
|
12
|
+
export function defaultsDeep(object: object, ...sources: object[]): object;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* DefaultsDeep recursively merges object properties from all supplied objects with object values
|
|
3
5
|
* being merged recursively and once a property is set, additional values of the same property are ignored.
|
|
@@ -9,7 +11,7 @@
|
|
|
9
11
|
* console.log(result);
|
|
10
12
|
* > { a: { b: [ 3, 4, 15 ], c: 3 } }
|
|
11
13
|
*/
|
|
12
|
-
function defaultsDeep (object, ...sources) {
|
|
14
|
+
export function defaultsDeep (object, ...sources) {
|
|
13
15
|
if (arguments.length < 2) { return arguments.length === 1 ? object : {} }
|
|
14
16
|
const result = [object, ...sources]
|
|
15
17
|
|
|
@@ -59,5 +61,3 @@ const objectMerge = (current, source) => {
|
|
|
59
61
|
}, null)
|
|
60
62
|
return res
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
export { defaultsDeep }
|
package/src/objects/entries.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Entries takes an object and returns an array composed from key-value pairs.
|
|
3
|
-
*
|
|
4
3
|
* @param {object} object input object
|
|
5
4
|
* @returns {Array} an array composed from arrays of the key-value pairs
|
|
6
|
-
*
|
|
7
5
|
* @example
|
|
8
6
|
* const result = objects.entries({ asuka: 643, heian: 795, meiji: 1868 });
|
|
9
7
|
* console.log(result);
|
|
10
8
|
* > [[asuka, 643], [heian, 795], [meiji: 1868]]
|
|
11
9
|
*/
|
|
12
|
-
export function entries(object:
|
|
10
|
+
export function entries(object: object): any[];
|
package/src/objects/entries.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Entries takes an object and returns an array composed from key-value pairs.
|
|
3
5
|
* @param {object} object input object
|
|
@@ -7,11 +9,9 @@
|
|
|
7
9
|
* console.log(result);
|
|
8
10
|
* > [[asuka, 643], [heian, 795], [meiji: 1868]]
|
|
9
11
|
*/
|
|
10
|
-
function entries (object) {
|
|
12
|
+
export function entries (object) {
|
|
11
13
|
return Object.keys(object).reduce((acc, key) => {
|
|
12
14
|
acc.push([key, object[key]])
|
|
13
15
|
return acc
|
|
14
16
|
}, [])
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
export { entries }
|
package/src/objects/filter.d.ts
CHANGED
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
* Filter iterates over an object and applies a predicate to each property, for all properties
|
|
3
3
|
* where the predicate is true, return that property in a new object. Function is invoked
|
|
4
4
|
* with 3 arguments (value, key, object)
|
|
5
|
-
*
|
|
6
|
-
* @param {Object} object input object
|
|
5
|
+
* @param {object} object input object
|
|
7
6
|
* @param {Function} predicate predicate function to check what properties to include
|
|
8
|
-
* @returns {
|
|
9
|
-
*
|
|
7
|
+
* @returns {object} object with selected properties
|
|
10
8
|
* @example
|
|
11
9
|
* const obj = { small: "ant", medium: "dog", big: "elephant" }
|
|
12
10
|
* const result = objects.filter(obj, (value, key, object) => ['small', 'big'].includes(key)));
|
|
13
11
|
* console.log(result);
|
|
14
12
|
* > { small: "ant", big: "elephant" }
|
|
15
13
|
*/
|
|
16
|
-
export function filter(object:
|
|
14
|
+
export function filter(object: object, predicate: Function): object;
|
package/src/objects/filter.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable jsdoc/reject-function-type */
|
|
2
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Filter iterates over an object and applies a predicate to each property, for all properties
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
* console.log(result);
|
|
14
15
|
* > { small: "ant", big: "elephant" }
|
|
15
16
|
*/
|
|
16
|
-
function filter (object, predicate) {
|
|
17
|
+
export function filter (object, predicate) {
|
|
17
18
|
if (typeof predicate !== 'function') { return object }
|
|
18
19
|
return Object.keys(object).reduce((acc, key) => {
|
|
19
20
|
if (predicate(object[key], key, object) === true) {
|
|
@@ -22,5 +23,3 @@ function filter (object, predicate) {
|
|
|
22
23
|
return acc
|
|
23
24
|
}, {})
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
export { filter }
|
package/src/objects/findKey.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* FindKey returns the key of the first property value for which a supplied function returns true
|
|
3
|
-
*
|
|
4
3
|
* @param {object} object input object
|
|
5
|
-
* @param {
|
|
4
|
+
* @param {Function} [predicate] function to test against object values (default x=>x)
|
|
6
5
|
* @param {*} [thisArg] value of this in a function call
|
|
7
6
|
* @returns {string} string of the first object key whose value returns truthy against the function
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
8
|
* const result = Objects.findKey({ apple: 34, pear: 434, orange: 4 }, x => x > 100 );
|
|
11
9
|
* console.log(result);
|
|
12
10
|
* > 'pear'
|
|
13
11
|
*/
|
|
14
|
-
export function findKey(object:
|
|
12
|
+
export function findKey(object: object, predicate?: Function, thisArg?: any): string;
|
package/src/objects/findKey.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable jsdoc/reject-any-type,jsdoc/reject-function-type */
|
|
2
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* FindKey returns the key of the first property value for which a supplied function returns true
|
|
@@ -11,7 +12,7 @@
|
|
|
11
12
|
* console.log(result);
|
|
12
13
|
* > 'pear'
|
|
13
14
|
*/
|
|
14
|
-
function findKey (object, predicate = x => x, thisArg) {
|
|
15
|
+
export function findKey (object, predicate = x => x, thisArg) {
|
|
15
16
|
const keys = Object.keys(object)
|
|
16
17
|
|
|
17
18
|
if (typeof predicate === 'function') {
|
|
@@ -58,5 +59,3 @@ const objContained = (objA, objB) => {
|
|
|
58
59
|
return true
|
|
59
60
|
}, false)
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
-
export { findKey }
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* FindLastKey returns the key of the last property value for which a supplied function returns true
|
|
3
|
-
*
|
|
4
3
|
* @param {object} object input object
|
|
5
|
-
* @param {
|
|
4
|
+
* @param {Function} [predicate] function to test against object values (default x=>x)
|
|
6
5
|
* @param {*} [thisArg] value of this in a function call
|
|
7
6
|
* @returns {string} string of the first object key whose value returns truthy against the function
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
8
|
* const result = Objects.findLastKey({ apple: 34, pear: 434, orange: 4, grapefruit: 212 }, x => x > 100 );
|
|
11
9
|
* console.log(result);
|
|
12
10
|
* > 'grapefruit'
|
|
13
11
|
*/
|
|
14
|
-
export function findLastKey(object:
|
|
12
|
+
export function findLastKey(object: object, predicate?: Function, thisArg?: any): string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable jsdoc/reject-any-type,jsdoc/reject-function-type */
|
|
2
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* FindLastKey returns the key of the last property value for which a supplied function returns true
|
|
@@ -11,7 +12,7 @@
|
|
|
11
12
|
* console.log(result);
|
|
12
13
|
* > 'grapefruit'
|
|
13
14
|
*/
|
|
14
|
-
function findLastKey (object, predicate = x => x, thisArg) {
|
|
15
|
+
export function findLastKey (object, predicate = x => x, thisArg) {
|
|
15
16
|
const keys = Object.keys(object)
|
|
16
17
|
|
|
17
18
|
if (typeof predicate === 'function') {
|
|
@@ -58,5 +59,3 @@ const objContained = (objA, objB) => {
|
|
|
58
59
|
return true
|
|
59
60
|
}, false)
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
-
export { findLastKey }
|
package/src/objects/forIn.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* forIn iterates over own and inherited enumerable string keyed properties of an object and invokes
|
|
3
3
|
* iteratee for each property. The iteratee is invoked with three arguments: (value, key, object)
|
|
4
|
-
*
|
|
5
|
-
* @param {Object} object input object
|
|
4
|
+
* @param {object} object input object
|
|
6
5
|
* @param {Function} func function invoked per iteration
|
|
7
|
-
* @returns {
|
|
8
|
-
*
|
|
6
|
+
* @returns {object} original object
|
|
9
7
|
* @example
|
|
10
8
|
* const Obj_A = function () {
|
|
11
9
|
* this.a = 5;
|
|
@@ -19,4 +17,4 @@
|
|
|
19
17
|
* // 15
|
|
20
18
|
* > { a: 5, b: 10 }
|
|
21
19
|
*/
|
|
22
|
-
export function forIn(object:
|
|
20
|
+
export function forIn(object: object, func: Function): object;
|
package/src/objects/forIn.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable jsdoc/reject-function-type */
|
|
2
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* forIn iterates over own and inherited enumerable string keyed properties of an object and invokes
|
|
@@ -19,7 +20,7 @@
|
|
|
19
20
|
* // 15
|
|
20
21
|
* > { a: 5, b: 10 }
|
|
21
22
|
*/
|
|
22
|
-
function forIn (object, func) {
|
|
23
|
+
export function forIn (object, func) {
|
|
23
24
|
const objProto = Object.getPrototypeOf(object)
|
|
24
25
|
const proto = objProto ? Object.keys(objProto) : []
|
|
25
26
|
|
|
@@ -33,7 +34,5 @@ function forIn (object, func) {
|
|
|
33
34
|
return null
|
|
34
35
|
}, null)
|
|
35
36
|
|
|
36
|
-
return object
|
|
37
|
+
return Object.setPrototypeOf(object, Object.prototype)
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
export { forIn }
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* FromEntries takes an array of arrays with key-value pairs and returns an
|
|
3
3
|
* object composed from key-value pairs.
|
|
4
|
-
*
|
|
5
4
|
* @param {Array} array input key-value pairs in an array of arrays
|
|
6
5
|
* @returns {object} an object composed from the key-value pairs
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = objects.fromEntries([['age', 12034], ['name', 'Trair'],['state', 'Floating']]);
|
|
10
8
|
* console.log(result);
|
|
11
9
|
* > { age: 12034, name: 'Trair', state: 'Floating' }
|
|
12
10
|
*/
|
|
13
|
-
export function fromEntries(array: any[]):
|
|
11
|
+
export function fromEntries(array: any[]): object;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* FromEntries takes an array of arrays with key-value pairs and returns an
|
|
3
5
|
* object composed from key-value pairs.
|
|
@@ -8,11 +10,9 @@
|
|
|
8
10
|
* console.log(result);
|
|
9
11
|
* > { age: 12034, name: 'Trair', state: 'Floating' }
|
|
10
12
|
*/
|
|
11
|
-
function fromEntries (array) {
|
|
13
|
+
export function fromEntries (array) {
|
|
12
14
|
return array.reduce((acc, curr) => {
|
|
13
15
|
acc[curr[0]] = curr[1]
|
|
14
16
|
return acc
|
|
15
17
|
}, {})
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
export { fromEntries }
|
package/src/objects/get.d.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Get, creates an array of values corresponding to paths of the object
|
|
3
|
-
*
|
|
4
3
|
* @param {object} object input object
|
|
5
4
|
* @param {Array|string} path string or an array of strings describing paths to be returned from an object
|
|
6
5
|
* @param {*} [defaultValue] value returned when path resolves undefined
|
|
7
6
|
* @returns {*} value found by object paths in object, or returns defaultValue if provided and return would otherwise be undefined
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
8
|
* const result = objects.get({ front: [1, 3, 5], back: [37, 39] });
|
|
11
9
|
* console.log(result, 'back[1]');
|
|
12
10
|
* > 39
|
|
13
|
-
*
|
|
14
11
|
* @example
|
|
15
12
|
* const result = objects.get({ front: [1, 3, 5], back: [37, 39] });
|
|
16
13
|
* console.log(result, ['front', 5], "no value here");
|
|
17
14
|
* > 'no value here'
|
|
18
15
|
*/
|
|
19
|
-
export function get(object:
|
|
16
|
+
export function get(object: object, path: any[] | string, defaultValue?: any): any;
|
package/src/objects/get.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable jsdoc/reject-any-type */
|
|
2
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Get, creates an array of values corresponding to paths of the object
|
|
@@ -15,7 +16,7 @@
|
|
|
15
16
|
* console.log(result, ['front', 5], "no value here");
|
|
16
17
|
* > 'no value here'
|
|
17
18
|
*/
|
|
18
|
-
function get (object, path, defaultValue) {
|
|
19
|
+
export function get (object, path, defaultValue) {
|
|
19
20
|
if (typeof path === 'undefined') { return undefined }
|
|
20
21
|
let pathArray
|
|
21
22
|
|
|
@@ -36,5 +37,3 @@ function get (object, path, defaultValue) {
|
|
|
36
37
|
|
|
37
38
|
return result !== undefined ? result : defaultValue
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
export { get }
|
package/src/objects/has.d.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Has, creates an array of values corresponding to paths of the object
|
|
3
|
-
*
|
|
4
3
|
* @param {object} object input object
|
|
5
4
|
* @param {Array|string} path strings describing paths to be returned from an object
|
|
6
5
|
* @returns {boolean} boolean true is a direct property of the object
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = objects.has({ front: [1, 3, 5], back: [37, 39] });
|
|
10
8
|
* console.log(result, 'back[1]');
|
|
11
9
|
* > true
|
|
12
|
-
*
|
|
13
10
|
* @example
|
|
14
11
|
* const result = objects.has({ front: [1, 3, 5], back: [37, 39] });
|
|
15
12
|
* console.log(result, ['front', 1]);
|
|
16
13
|
* > true
|
|
17
14
|
*/
|
|
18
|
-
export function has(object:
|
|
15
|
+
export function has(object: object, path: any[] | string): boolean;
|
package/src/objects/has.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Has, creates an array of values corresponding to paths of the object
|
|
3
5
|
* @param {object} object input object
|
|
@@ -12,7 +14,7 @@
|
|
|
12
14
|
* console.log(result, ['front', 1]);
|
|
13
15
|
* > true
|
|
14
16
|
*/
|
|
15
|
-
function has (object, path) {
|
|
17
|
+
export function has (object, path) {
|
|
16
18
|
if (typeof path === 'undefined') { return false }
|
|
17
19
|
let pathArray
|
|
18
20
|
|
|
@@ -31,5 +33,3 @@ function has (object, path) {
|
|
|
31
33
|
}
|
|
32
34
|
}, object)
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
export { has }
|
package/src/objects/invert.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Create a new object with key-value pairs inverted, in the case of duplicate values the latter value
|
|
3
3
|
* will overwrite the previous value.
|
|
4
|
-
*
|
|
5
4
|
* @param {object} object input string
|
|
6
5
|
* @returns {object} returns an object with key-value pairs inverted
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = Objects.invert({ a: 1, b: 2, c: 1 });
|
|
10
8
|
* console.log(result);
|
|
11
9
|
* > { '1': 'c', '2': 'b' }
|
|
12
10
|
*/
|
|
13
|
-
export function invert(object:
|
|
11
|
+
export function invert(object: object): object;
|
package/src/objects/invert.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Create a new object with key-value pairs inverted, in the case of duplicate values the latter value
|
|
3
5
|
* will overwrite the previous value.
|
|
@@ -8,11 +10,9 @@
|
|
|
8
10
|
* console.log(result);
|
|
9
11
|
* > { '1': 'c', '2': 'b' }
|
|
10
12
|
*/
|
|
11
|
-
function invert (object) {
|
|
13
|
+
export function invert (object) {
|
|
12
14
|
return Object.keys(object).reduce((acc, key) => {
|
|
13
15
|
acc[object[key]] = key
|
|
14
16
|
return acc
|
|
15
17
|
}, {})
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
export { invert }
|
package/src/objects/mapKeys.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MapKeys iterates over an object of values and applies a function to each key
|
|
3
|
-
*
|
|
4
|
-
* @param {Object} object input object
|
|
3
|
+
* @param {object} object input object
|
|
5
4
|
* @param {Function} func map function
|
|
6
|
-
* @returns {
|
|
7
|
-
*
|
|
5
|
+
* @returns {object} object with mutated keys
|
|
8
6
|
* @example
|
|
9
7
|
* const result = objects.mapKeys({ a: 1, b: 2, c: 3 }, value => `neat_${value}`);
|
|
10
8
|
* console.log(result);
|
|
11
9
|
* > { neat_1: 1, neat_2: 2, neat_3: 3 }
|
|
12
10
|
*/
|
|
13
|
-
export function mapKeys(object:
|
|
11
|
+
export function mapKeys(object: object, func: Function): object;
|
package/src/objects/mapKeys.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable jsdoc/reject-function-type */
|
|
2
|
+
// @ts-nocheck TODO: Fix types on this late
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* MapKeys iterates over an object of values and applies a function to each key
|
|
@@ -10,7 +11,7 @@
|
|
|
10
11
|
* console.log(result);
|
|
11
12
|
* > { neat_1: 1, neat_2: 2, neat_3: 3 }
|
|
12
13
|
*/
|
|
13
|
-
function mapKeys (object, func) {
|
|
14
|
+
export function mapKeys (object, func) {
|
|
14
15
|
if (typeof func !== 'function') { return object }
|
|
15
16
|
return Object.keys(object).reduce(
|
|
16
17
|
(acc, key) => ({
|
|
@@ -20,5 +21,3 @@ function mapKeys (object, func) {
|
|
|
20
21
|
{}
|
|
21
22
|
)
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
export { mapKeys }
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MapKeys iterates over an object and applies a function to each value
|
|
3
|
-
*
|
|
4
|
-
* @param {Object} object input object
|
|
3
|
+
* @param {object} object input object
|
|
5
4
|
* @param {Function} func map function
|
|
6
|
-
* @returns {
|
|
7
|
-
*
|
|
5
|
+
* @returns {object} object with mutated values
|
|
8
6
|
* @example
|
|
9
7
|
* const result = objects.mapValues({ a: 1, b: 2, c: 3 }, value => `neat_${value}`);
|
|
10
8
|
* console.log(result);
|
|
11
9
|
* > { a: neat_1, b: neat_2, c: neat_3 }
|
|
12
10
|
*/
|
|
13
|
-
export function mapValues(object:
|
|
11
|
+
export function mapValues(object: object, func: Function): object;
|
package/src/objects/mapValues.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable jsdoc/reject-function-type */
|
|
2
|
+
// @ts-nocheck TODO: Fix types on this late
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* MapKeys iterates over an object and applies a function to each value
|
|
@@ -10,12 +11,10 @@
|
|
|
10
11
|
* console.log(result);
|
|
11
12
|
* > { a: neat_1, b: neat_2, c: neat_3 }
|
|
12
13
|
*/
|
|
13
|
-
function mapValues (object, func) {
|
|
14
|
+
export function mapValues (object, func) {
|
|
14
15
|
if (typeof func !== 'function') { return object }
|
|
15
16
|
return Object.keys(object).reduce((acc, key) => ({
|
|
16
17
|
...acc,
|
|
17
18
|
[key]: func(object[key], key, object)
|
|
18
19
|
}), {})
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
export { mapValues }
|
package/src/objects/merge.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Merge recursively merges object properties from all supplied objects with object values
|
|
3
3
|
* being merged recursively and other value types overridden when applied from left to right.
|
|
4
|
-
*
|
|
5
4
|
* @param {object} object input object
|
|
6
5
|
* @param {...object} sources input object(s)
|
|
7
6
|
* @returns {object} returns an object with all included object properties merged
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
8
|
* const result = objects.merge({ hold: 25, your: 19 }, { a: 1, b: 2 });
|
|
11
9
|
* console.log(result);
|
|
12
10
|
* > { a: 1, b: 2, hold: 25, your: 19 }
|
|
13
11
|
*/
|
|
14
|
-
export function merge(object:
|
|
12
|
+
export function merge(object: object, ...sources: object[]): object;
|
package/src/objects/merge.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-nocheck TODO: Fix types on this late
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Merge recursively merges object properties from all supplied objects with object values
|
|
3
5
|
* being merged recursively and other value types overridden when applied from left to right.
|
|
@@ -9,7 +11,7 @@
|
|
|
9
11
|
* console.log(result);
|
|
10
12
|
* > { a: 1, b: 2, hold: 25, your: 19 }
|
|
11
13
|
*/
|
|
12
|
-
function merge (object, ...sources) {
|
|
14
|
+
export function merge (object, ...sources) {
|
|
13
15
|
if (arguments.length < 2) { return arguments.length === 1 ? object : {} }
|
|
14
16
|
const result = [object, ...sources]
|
|
15
17
|
|
|
@@ -59,5 +61,3 @@ const objectMerge = (current, source) => {
|
|
|
59
61
|
}, null)
|
|
60
62
|
return res
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
export { merge }
|