@vanillaes/absurdum 2.0.5 → 2.0.7
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/package.json +13 -12
- package/src/arrays/chunk.js +1 -3
- package/src/arrays/compact.js +0 -2
- package/src/arrays/difference.js +0 -2
- package/src/arrays/drop.js +1 -3
- package/src/arrays/dropRight.js +1 -3
- package/src/arrays/fill.js +4 -4
- package/src/arrays/filter.js +2 -2
- package/src/arrays/find.js +2 -2
- package/src/arrays/findIndex.js +2 -2
- package/src/arrays/findLastIndex.js +2 -2
- package/src/arrays/flat.js +1 -3
- package/src/arrays/frequency.js +1 -3
- package/src/arrays/intersection.js +0 -2
- package/src/arrays/map.js +2 -2
- package/src/arrays/pull.js +2 -2
- package/src/arrays/take.js +1 -3
- package/src/arrays/takeRight.js +1 -3
- package/src/arrays/union.js +0 -2
- package/src/arrays/unique.js +0 -2
- package/src/arrays/unzip.js +0 -2
- package/src/arrays/without.js +2 -1
- package/src/arrays/xor.js +0 -2
- package/src/arrays/zip.js +3 -3
- package/src/objects/assign.js +0 -2
- package/src/objects/at.js +1 -3
- package/src/objects/defaults.js +0 -2
- package/src/objects/defaultsDeep.js +0 -2
- package/src/objects/entries.js +0 -2
- package/src/objects/filter.js +4 -4
- package/src/objects/findKey.js +3 -3
- package/src/objects/findLastKey.js +3 -3
- package/src/objects/forIn.js +4 -4
- package/src/objects/fromEntries.js +0 -2
- package/src/objects/get.js +2 -3
- package/src/objects/has.js +0 -3
- package/src/objects/invert.js +0 -2
- package/src/objects/mapKeys.js +4 -4
- package/src/objects/mapValues.js +4 -4
- package/src/objects/merge.js +0 -2
- package/src/objects/pick.js +0 -2
- package/src/objects/result.js +2 -3
- package/src/objects/transform.js +4 -4
- package/src/objects/values.js +1 -3
- package/src/strings/camelCase.js +0 -2
- package/src/strings/chomp.js +1 -4
- package/src/strings/deburr.js +0 -2
- package/src/strings/endsWith.js +1 -4
- package/src/strings/includes.js +1 -3
- package/src/strings/kebabCase.js +0 -2
- package/src/strings/pad.js +2 -6
- package/src/strings/padEnd.js +2 -6
- package/src/strings/padStart.js +2 -6
- package/src/strings/pascalCase.js +0 -2
- package/src/strings/repeat.js +1 -3
- package/src/strings/reverse.js +0 -2
- package/src/strings/snakeCase.js +0 -2
- package/src/strings/startsWith.js +0 -3
- package/src/strings/trimEnd.js +1 -3
- package/src/strings/trimStart.js +1 -3
- package/src/strings/truncate.js +8 -10
- package/src/strings/words.js +2 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanillaes/absurdum",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "Absurdum - The Ridiculous Application of Reduce",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esm",
|
|
@@ -27,21 +27,28 @@
|
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
29
|
"import": "./index.js",
|
|
30
|
+
"types": "./index.d.ts",
|
|
30
31
|
"browser": "./index.min.js"
|
|
31
32
|
},
|
|
32
33
|
"./arrays": {
|
|
33
|
-
"import": "./src/arrays/index.js"
|
|
34
|
+
"import": "./src/arrays/index.js",
|
|
35
|
+
"types": "./src/arrays/index.d.ts",
|
|
36
|
+
"browser": "./src/arrays/index.min.js"
|
|
34
37
|
},
|
|
35
38
|
"./objects": {
|
|
36
|
-
"import": "./src/objects/index.js"
|
|
39
|
+
"import": "./src/objects/index.js",
|
|
40
|
+
"types": "./src/objects/index.d.ts",
|
|
41
|
+
"browser": "./src/objects/index.min.js"
|
|
37
42
|
},
|
|
38
43
|
"./strings": {
|
|
39
|
-
"import": "./src/strings/index.js"
|
|
44
|
+
"import": "./src/strings/index.js",
|
|
45
|
+
"types": "./src/strings/index.d.ts",
|
|
46
|
+
"browser": "./src/strings/index.min.js"
|
|
40
47
|
}
|
|
41
48
|
},
|
|
42
|
-
"types": "index.d.ts",
|
|
43
49
|
"scripts": {
|
|
44
50
|
"test": "esmtk test",
|
|
51
|
+
"lint": "esmtk lint",
|
|
45
52
|
"type": "esmtk type index.js",
|
|
46
53
|
"build": "npm run build:min && npm run build:docs && npm run build:typings",
|
|
47
54
|
"build:docs": "node .config/docs.config.js",
|
|
@@ -52,19 +59,13 @@
|
|
|
52
59
|
"clean:min": "esmtk clean --minify",
|
|
53
60
|
"clean:typings": "esmtk clean --typings",
|
|
54
61
|
"preview": "esmtk preview",
|
|
55
|
-
"preversion": "npm test && npm run type",
|
|
62
|
+
"preversion": "npm test && npm run lint && npm run type",
|
|
56
63
|
"postversion": "git push --follow-tags"
|
|
57
64
|
},
|
|
58
65
|
"devDependencies": {
|
|
59
66
|
"docdown": "github:evanplaice/docdown",
|
|
60
67
|
"glob": "^7.2.0"
|
|
61
68
|
},
|
|
62
|
-
"standard": {
|
|
63
|
-
"ignore": [
|
|
64
|
-
"index.js",
|
|
65
|
-
"docs.config.js"
|
|
66
|
-
]
|
|
67
|
-
},
|
|
68
69
|
"dependencies": {
|
|
69
70
|
"@vanillaes/esmtk": "^1.2.3"
|
|
70
71
|
}
|
package/src/arrays/chunk.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Splits the input array up into an subset arrays of equal size
|
|
3
|
-
*
|
|
4
3
|
* @param {Array} array input array
|
|
5
|
-
* @param {number} [size
|
|
4
|
+
* @param {number} [size] size of each chunk (default 1)
|
|
6
5
|
* @returns {Array} array of chunk arrays
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = arrays.chunk([1, 2, 3, 4, 5], 2);
|
|
10
8
|
* console.log(result);
|
package/src/arrays/compact.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Compact removes all falsy values `[false, null, 0, "", undefined, NaN]` from an array.
|
|
3
|
-
*
|
|
4
3
|
* @param {Array} array input array
|
|
5
4
|
* @returns {Array} the input array w/ no falsy values
|
|
6
|
-
*
|
|
7
5
|
* @example
|
|
8
6
|
* const result = arrays.compact([1, false, 2, null, 3, 0, 4, "", 5, undefined, 6, NaN]);
|
|
9
7
|
* console.log(result);
|
package/src/arrays/difference.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Finds the difference of two arrays
|
|
3
|
-
*
|
|
4
3
|
* @param {Array} arrayA first input array
|
|
5
4
|
* @param {Array} arrayB second input array
|
|
6
5
|
* @returns {Array} an array containing the difference
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = arrays.difference([2, 1], [2, 3]);
|
|
10
8
|
* console.log(result);
|
package/src/arrays/drop.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Remove N items from the beginning of the input array
|
|
3
|
-
*
|
|
4
3
|
* @param {Array} array input array
|
|
5
|
-
* @param {number} [count
|
|
4
|
+
* @param {number} [count] number of items to drop (default 1)
|
|
6
5
|
* @returns {Array} input array sans the dropped items
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = arrays.drop([1, 2, 3], 2);
|
|
10
8
|
* console.log(result);
|
package/src/arrays/dropRight.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Remove N items from the end of the input array
|
|
3
|
-
*
|
|
4
3
|
* @param {Array} array input array
|
|
5
|
-
* @param {number} [count
|
|
4
|
+
* @param {number} [count] number of items to drop (default 1)
|
|
6
5
|
* @returns {Array} input array sans the dropped items
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = arrays.drop([1, 2, 3], 2);
|
|
10
8
|
* console.log(result);
|
package/src/arrays/fill.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-any-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Fills items in an array with a specified value. Optionally, one can start and/or end from a specific index.
|
|
3
|
-
*
|
|
4
5
|
* @param {Array} array input array
|
|
5
6
|
* @param {*} value value that fills the array
|
|
6
|
-
* @param {number} [start
|
|
7
|
-
* @param {number} [end
|
|
7
|
+
* @param {number} [start] start index (default 0)
|
|
8
|
+
* @param {number} [end] end index (default array.length)
|
|
8
9
|
* @returns {Array} input array filled w/ the value
|
|
9
|
-
*
|
|
10
10
|
* @example
|
|
11
11
|
* const result = arrays.fill([1, 2, 3, 4], 'a', 1, 2);
|
|
12
12
|
* console.log(result)
|
package/src/arrays/filter.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Iterates over an array of values and only outputs values where `predicate is equal to true`.
|
|
3
|
-
*
|
|
4
5
|
* @param {Array} array input array
|
|
5
6
|
* @param {Function} predicate predicate function
|
|
6
7
|
* @returns {Array} the input array w/ unwanted values removed
|
|
7
|
-
*
|
|
8
8
|
* @example
|
|
9
9
|
* const result = arrays.filter([1, 2, 3, 4], (x) => x % 2 === 0);
|
|
10
10
|
* console.log(result)
|
package/src/arrays/find.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-any-type,jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Find method returns the value of first element at which a provided function is true,
|
|
3
5
|
* or undefined if no elements in the array satisfy the function.
|
|
4
|
-
*
|
|
5
6
|
* @param {Array} array input array
|
|
6
7
|
* @param {Function} predicate to be run against each element of the array
|
|
7
8
|
* @param {*} [thisArg] this argument in the function
|
|
8
9
|
* @returns {*} value of element that satisfied function.
|
|
9
|
-
*
|
|
10
10
|
* @example
|
|
11
11
|
* const result = arrays.find([5, 12, 8, 130, 44], (x) => x > 10);
|
|
12
12
|
* console.log(result);
|
package/src/arrays/findIndex.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-any-type,jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* FindIndex method returns the value of First element at which a provided function is true,
|
|
3
5
|
* or -1 if no elements in the array satisfy the function.
|
|
4
|
-
*
|
|
5
6
|
* @param {Array} array input array
|
|
6
7
|
* @param {Function} predicate to be run against each element of the array
|
|
7
8
|
* @param {*} [thisArg] this argument in the function
|
|
8
9
|
* @returns {*} value of element that satisfied function.
|
|
9
|
-
*
|
|
10
10
|
* @example
|
|
11
11
|
* const result = arrays.findIndex([5, 12, 8, 130, 44], (x) => x < 10);
|
|
12
12
|
* console.log(result);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-any-type,jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* FindLastIndex method returns the value of Last element at which a provided function is true,
|
|
3
5
|
* or undefined if no elements in the array satisfy the function.
|
|
4
|
-
*
|
|
5
6
|
* @param {Array} array input array
|
|
6
7
|
* @param {Function} predicate to be run against each element of the array
|
|
7
8
|
* @param {*} [thisArg] this argument in the function
|
|
8
9
|
* @returns {*} value of element that satisfied function.
|
|
9
|
-
*
|
|
10
10
|
* @example
|
|
11
11
|
* const result = arrays.findLastIndex([5, 12, 8, 130, 44], (x) => x < 10);
|
|
12
12
|
* console.log(result);
|
package/src/arrays/flat.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flat flattens an array of nested arrays
|
|
3
|
-
*
|
|
4
3
|
* @param {Array} array input array
|
|
5
|
-
* @param {number} [depth
|
|
4
|
+
* @param {number} [depth] depth of array elements to flat (default 1)
|
|
6
5
|
* @returns {Array} the flattened array
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = arrays.flat([1, [2, [3, [4]]]]);
|
|
10
8
|
* console.log(result);
|
package/src/arrays/frequency.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Frequency returns an object mapping each unique item in an array
|
|
3
3
|
* to the number of items it occurs in the array.
|
|
4
|
-
*
|
|
5
4
|
* @param {Array} array input array
|
|
6
|
-
* @returns {
|
|
7
|
-
*
|
|
5
|
+
* @returns {object} object of uniq values and their frequency of occurrence
|
|
8
6
|
* @example
|
|
9
7
|
* const result = arrays.frequency(['a', 'b', 'a', 'c', 'a', 'c', 'b']);
|
|
10
8
|
* console.log(result)
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Intersection creates an array of unique values that are included in all given arrays
|
|
3
|
-
*
|
|
4
3
|
* @param {Array} arrays input array(s)
|
|
5
4
|
* @returns {Array} an array containing the unique intersecting values between all input arrays
|
|
6
|
-
*
|
|
7
5
|
* @example
|
|
8
6
|
* const result = arrays.intersection([4, 2, 1], [2, 3, 4]));
|
|
9
7
|
* console.log(result);
|
package/src/arrays/map.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Map iterates over an array of values and applies a function to each value
|
|
3
|
-
*
|
|
4
5
|
* @param {Array} array input array
|
|
5
6
|
* @param {Function} func function describing how to map values
|
|
6
7
|
* @returns {Array} array of mutated values
|
|
7
|
-
*
|
|
8
8
|
* @example
|
|
9
9
|
* const result = arrays.map([1, 2, 3, 4], (x) => x + 2);
|
|
10
10
|
* console.log(result)
|
package/src/arrays/pull.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-any-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Pull removes all of the given values from an array
|
|
3
|
-
*
|
|
4
5
|
* @param {Array} array input array
|
|
5
6
|
* @param {...*} values values to be removed from the array
|
|
6
7
|
* @returns {Array} array of with values removed
|
|
7
|
-
*
|
|
8
8
|
* @example
|
|
9
9
|
* const result = arrays.pull([1, 2, 3, 4], 2, 4);
|
|
10
10
|
* console.log(result)
|
package/src/arrays/take.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Take method returns a slice of array with 'count' number of elements from the beginning
|
|
3
|
-
*
|
|
4
3
|
* @param {Array} array input array
|
|
5
|
-
* @param {
|
|
4
|
+
* @param {number} [count] number of elements in the slice of the array (default 1)
|
|
6
5
|
* @returns {Array} the slice of the array of length 'count'
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = arrays.take(['Amy', 'Brie', 'Cam', 'Dimitri']);
|
|
10
8
|
* console.log(result);
|
package/src/arrays/takeRight.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Take method returns a slice of array with 'count' number of elements from the end of the array
|
|
3
|
-
*
|
|
4
3
|
* @param {Array} array input array
|
|
5
|
-
* @param {
|
|
4
|
+
* @param {number} [count] number of elements in the slice of the array (default 1)
|
|
6
5
|
* @returns {Array} the slice of the array of length 'count'
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = arrays.some(['Amy', 'Brie', 'Cam', 'Dimitri']);
|
|
10
8
|
* console.log(result);
|
package/src/arrays/union.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Union creates an array of unique elements from all given arrays in order encountered
|
|
3
|
-
*
|
|
4
3
|
* @param {Array} arrays input arrays
|
|
5
4
|
* @returns {Array} an array of unique elements from all given arrays
|
|
6
|
-
*
|
|
7
5
|
* @example
|
|
8
6
|
* const result = arrays.union([2], [1, 2, 3, 1]);
|
|
9
7
|
* > [2, 1, 3]
|
package/src/arrays/unique.js
CHANGED
package/src/arrays/unzip.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Performs a manipulation to undo the zip command
|
|
3
|
-
*
|
|
4
3
|
* @param {Array} array input array
|
|
5
4
|
* @returns {Array} an array of unique values
|
|
6
|
-
*
|
|
7
5
|
* @example
|
|
8
6
|
* const result = arrays.unzip([['a', 'b', 'c'], [1, 2, 3], [true, false, true]]);
|
|
9
7
|
* console.log(result);
|
package/src/arrays/without.js
CHANGED
package/src/arrays/xor.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates an array of unique values that is the symmetric difference of the given arrays
|
|
3
|
-
*
|
|
4
3
|
* @param {...Array} arrays input arrays
|
|
5
4
|
* @returns {Array} an array of unique values
|
|
6
|
-
*
|
|
7
5
|
* @example
|
|
8
6
|
* const result = arrays.xor(['a', 1, [5]], ['b', 1, 'a'], ['b', 'c', 5]);
|
|
9
7
|
* console.log(result);
|
package/src/arrays/zip.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Zip applies a specified function to the corresponding elements of two sequences,
|
|
3
5
|
* producing a sequence of the results.
|
|
4
|
-
*
|
|
5
6
|
* @param {Array} arrayA input array
|
|
6
7
|
* @param {Array} ArrayB input array
|
|
7
|
-
* @param {Function} [func
|
|
8
|
+
* @param {Function} [func] to be applied to corresponding values (default (a, b)=>[a, b])
|
|
8
9
|
* @returns {Array} input array filled value pairs after the function has been applied
|
|
9
|
-
*
|
|
10
10
|
* @example
|
|
11
11
|
* const result = zip([5, 12, 8, 130, 44], ["ham", "cheese", "bread"]);
|
|
12
12
|
* console.log(result)
|
package/src/objects/assign.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
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 });
|
package/src/objects/at.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
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]');
|
package/src/objects/defaults.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
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 });
|
|
@@ -1,11 +1,9 @@
|
|
|
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);
|
package/src/objects/entries.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
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);
|
package/src/objects/filter.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Filter iterates over an object and applies a predicate to each property, for all properties
|
|
3
5
|
* where the predicate is true, return that property in a new object. Function is invoked
|
|
4
6
|
* with 3 arguments (value, key, object)
|
|
5
|
-
*
|
|
6
|
-
* @param {Object} object input object
|
|
7
|
+
* @param {object} object input object
|
|
7
8
|
* @param {Function} predicate predicate function to check what properties to include
|
|
8
|
-
* @returns {
|
|
9
|
-
*
|
|
9
|
+
* @returns {object} object with selected properties
|
|
10
10
|
* @example
|
|
11
11
|
* const obj = { small: "ant", medium: "dog", big: "elephant" }
|
|
12
12
|
* const result = objects.filter(obj, (value, key, object) => ['small', 'big'].includes(key)));
|
package/src/objects/findKey.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-any-type,jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* FindKey returns the key of the first property value for which a supplied function returns true
|
|
3
|
-
*
|
|
4
5
|
* @param {object} object input object
|
|
5
|
-
* @param {
|
|
6
|
+
* @param {Function} [predicate] function to test against object values (default x=>x)
|
|
6
7
|
* @param {*} [thisArg] value of this in a function call
|
|
7
8
|
* @returns {string} string of the first object key whose value returns truthy against the function
|
|
8
|
-
*
|
|
9
9
|
* @example
|
|
10
10
|
* const result = Objects.findKey({ apple: 34, pear: 434, orange: 4 }, x => x > 100 );
|
|
11
11
|
* console.log(result);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-any-type,jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* FindLastKey returns the key of the last property value for which a supplied function returns true
|
|
3
|
-
*
|
|
4
5
|
* @param {object} object input object
|
|
5
|
-
* @param {
|
|
6
|
+
* @param {Function} [predicate] function to test against object values (default x=>x)
|
|
6
7
|
* @param {*} [thisArg] value of this in a function call
|
|
7
8
|
* @returns {string} string of the first object key whose value returns truthy against the function
|
|
8
|
-
*
|
|
9
9
|
* @example
|
|
10
10
|
* const result = Objects.findLastKey({ apple: 34, pear: 434, orange: 4, grapefruit: 212 }, x => x > 100 );
|
|
11
11
|
* console.log(result);
|
package/src/objects/forIn.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* forIn iterates over own and inherited enumerable string keyed properties of an object and invokes
|
|
3
5
|
* iteratee for each property. The iteratee is invoked with three arguments: (value, key, object)
|
|
4
|
-
*
|
|
5
|
-
* @param {Object} object input object
|
|
6
|
+
* @param {object} object input object
|
|
6
7
|
* @param {Function} func function invoked per iteration
|
|
7
|
-
* @returns {
|
|
8
|
-
*
|
|
8
|
+
* @returns {object} original object
|
|
9
9
|
* @example
|
|
10
10
|
* const Obj_A = function () {
|
|
11
11
|
* this.a = 5;
|
|
@@ -1,10 +1,8 @@
|
|
|
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);
|
package/src/objects/get.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-any-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Get, creates an array of values corresponding to paths of the object
|
|
3
|
-
*
|
|
4
5
|
* @param {object} object input object
|
|
5
6
|
* @param {Array|string} path string or an array of strings describing paths to be returned from an object
|
|
6
7
|
* @param {*} [defaultValue] value returned when path resolves undefined
|
|
7
8
|
* @returns {*} value found by object paths in object, or returns defaultValue if provided and return would otherwise be undefined
|
|
8
|
-
*
|
|
9
9
|
* @example
|
|
10
10
|
* const result = objects.get({ front: [1, 3, 5], back: [37, 39] });
|
|
11
11
|
* console.log(result, 'back[1]');
|
|
12
12
|
* > 39
|
|
13
|
-
*
|
|
14
13
|
* @example
|
|
15
14
|
* const result = objects.get({ front: [1, 3, 5], back: [37, 39] });
|
|
16
15
|
* console.log(result, ['front', 5], "no value here");
|
package/src/objects/has.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
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]);
|
package/src/objects/invert.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
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);
|
package/src/objects/mapKeys.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* MapKeys iterates over an object of values and applies a function to each key
|
|
3
|
-
*
|
|
4
|
-
* @param {Object} object input object
|
|
5
|
+
* @param {object} object input object
|
|
5
6
|
* @param {Function} func map function
|
|
6
|
-
* @returns {
|
|
7
|
-
*
|
|
7
|
+
* @returns {object} object with mutated keys
|
|
8
8
|
* @example
|
|
9
9
|
* const result = objects.mapKeys({ a: 1, b: 2, c: 3 }, value => `neat_${value}`);
|
|
10
10
|
* console.log(result);
|
package/src/objects/mapValues.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* MapKeys iterates over an object and applies a function to each value
|
|
3
|
-
*
|
|
4
|
-
* @param {Object} object input object
|
|
5
|
+
* @param {object} object input object
|
|
5
6
|
* @param {Function} func map function
|
|
6
|
-
* @returns {
|
|
7
|
-
*
|
|
7
|
+
* @returns {object} object with mutated values
|
|
8
8
|
* @example
|
|
9
9
|
* const result = objects.mapValues({ a: 1, b: 2, c: 3 }, value => `neat_${value}`);
|
|
10
10
|
* console.log(result);
|
package/src/objects/merge.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
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);
|
package/src/objects/pick.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pick returns a new object composed from the selected object properties.
|
|
3
|
-
*
|
|
4
3
|
* @param {object} object input object
|
|
5
4
|
* @param {...(string|string[])} paths paths names of properties to be returned from an object
|
|
6
5
|
* @returns {object} object with selected properties
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = Objects.pick({ a: 'mixed', b34: 'toast', 45: 'pasta' }, 'a', 45);
|
|
10
8
|
* console.log(result);
|
package/src/objects/result.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-any-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Result, creates an array of values corresponding to paths of the object. If value is a function, returns result of calling function
|
|
3
|
-
*
|
|
4
5
|
* @param {object} object input object
|
|
5
6
|
* @param {Array|string} path string or an array of strings describing paths to be returned from an object
|
|
6
7
|
* @param {*} [defaultValue] value returned when path resolves undefined
|
|
7
8
|
* @returns {*} value found by object paths in object, or returns defaultValue if provided and return would otherwise be undefined
|
|
8
|
-
*
|
|
9
9
|
* @example
|
|
10
10
|
* const obj = { front: [1, 3, 5], back: [() => 15, () => 19] };
|
|
11
11
|
* console.log(objects.result(obj, 'back[1]'));
|
|
12
12
|
* > 19
|
|
13
|
-
*
|
|
14
13
|
* @example
|
|
15
14
|
* const obj = { front: [1, 3, 5], back: [37, 39] };
|
|
16
15
|
* const func = (x) => { return x+7; }
|
package/src/objects/transform.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-function-type */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Transform works like reduce, except the accumulator is implicitly returned
|
|
3
|
-
*
|
|
4
5
|
* @param {object} object input object
|
|
5
|
-
* @param {
|
|
6
|
-
* @param {object|Array} [accumulator
|
|
6
|
+
* @param {Function} func iteratee function
|
|
7
|
+
* @param {object|Array} [accumulator] custom accumulator object (default {})
|
|
7
8
|
* @returns {object|Array} returns accumulator object after the input object has been iterated over by the function.
|
|
8
|
-
*
|
|
9
9
|
* @example
|
|
10
10
|
* const result = objects.transform({ harmony: 2, daft: 4, stripes: 6 }, function(acc, val, key) {
|
|
11
11
|
* acc[key] = val + 5 + '_' + idx;
|
package/src/objects/values.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Values is an alias for Object.values returns an array of all values in an object
|
|
3
|
-
*
|
|
4
3
|
* @param {object} object input object
|
|
5
|
-
* @returns {
|
|
6
|
-
*
|
|
4
|
+
* @returns {Array} returns an array of all values in an object
|
|
7
5
|
* @example
|
|
8
6
|
* const result = objects.values({ hold: 25, your: 19, horses: 4 });
|
|
9
7
|
* console.log(result);
|
package/src/strings/camelCase.js
CHANGED
package/src/strings/chomp.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Chomp removes record separator characters (ex \n, \r, \r\n) from the end of a string.
|
|
3
|
-
*
|
|
4
3
|
* @param {string} string input string
|
|
5
|
-
* @param {string} [separator
|
|
4
|
+
* @param {string} [separator] separator removed from end of string (default '\r' | '\n' | '\r\n')
|
|
6
5
|
* @returns {string} does the input end with the substring?
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = strings.chomp('Goldy\n\r\n');
|
|
10
8
|
* console.log(result);
|
|
11
9
|
* > 'Goldy\n'
|
|
12
|
-
*
|
|
13
10
|
* @example
|
|
14
11
|
* const result = strings.chomp('Sauce', 'ce');
|
|
15
12
|
* console.log(result);
|
package/src/strings/deburr.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Deburrs string by converting all complex Latin characters to basic Latin letters in a string.
|
|
3
|
-
*
|
|
4
3
|
* @param {string} [string] input string
|
|
5
4
|
* @returns {string} returns simplified string
|
|
6
|
-
*
|
|
7
5
|
* @example
|
|
8
6
|
* const result = strings.deburr('_ŁŐúnged\ufe2f_');
|
|
9
7
|
* console.log(result);
|
package/src/strings/endsWith.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tests a string to see if it ends with a substring
|
|
3
|
-
*
|
|
4
3
|
* @param {string} string input string
|
|
5
|
-
* @param {string} [substr
|
|
4
|
+
* @param {string} [substr] substring to test (default '')
|
|
6
5
|
* @returns {boolean} does the input end with the substring?
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = strings.endsWith('This sentence ends with', 'with');
|
|
10
8
|
* console.log(result);
|
|
11
9
|
* > true
|
|
12
|
-
*
|
|
13
10
|
* @example
|
|
14
11
|
* const result = strings.endsWith('This sentence does not end with', 'nope');
|
|
15
12
|
* console.log(result);
|
package/src/strings/includes.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Includes determines whether one string can be found in another string
|
|
3
|
-
*
|
|
4
3
|
* @param {string} string input string
|
|
5
4
|
* @param {string} substr candidate string to be searched for
|
|
6
|
-
* @param {
|
|
5
|
+
* @param {number} start index to begin search for string
|
|
7
6
|
* @returns {boolean} does the input string include the substring?
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
8
|
* const result = strings.includes('This Lovely Life', 'Love');
|
|
11
9
|
* console.log(result);
|
package/src/strings/kebabCase.js
CHANGED
package/src/strings/pad.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pads the both ends of a string w/ repeated spaces|substrings
|
|
3
|
-
*
|
|
4
3
|
* @param {string} string input string
|
|
5
|
-
* @param {number} [length
|
|
6
|
-
* @param {string} [substr
|
|
4
|
+
* @param {number} [length] length of the padded portion (default 0)
|
|
5
|
+
* @param {string} [substr] substring to apply (default ' ')
|
|
7
6
|
* @returns {string} the input padded w/ spaces|substrings
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
8
|
* // if no `substr` is provided, it pads the string w/ spaces
|
|
11
9
|
* const result = strings.pad('xyzxyz', 9);
|
|
12
10
|
* console.log(result);
|
|
13
11
|
* > ' xyzxyz '
|
|
14
|
-
*
|
|
15
12
|
* @example
|
|
16
13
|
* // if `length` is shorter than `string` it doesn't add any padding
|
|
17
14
|
* const result = strings.pad('xyzxyz', 4);
|
|
18
15
|
* console.log(result);
|
|
19
16
|
* > 'xyzxyz'
|
|
20
|
-
*
|
|
21
17
|
* @example
|
|
22
18
|
* // if `substr` is defined, it uses that for padding
|
|
23
19
|
* const result = strings.pad('xyzxyz', 16, 'FUN');
|
package/src/strings/padEnd.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pads the end of a string w/ repeated spaces|substrings
|
|
3
|
-
*
|
|
4
3
|
* @param {string} string input string
|
|
5
|
-
* @param {number} [length
|
|
6
|
-
* @param {string} [substr
|
|
4
|
+
* @param {number} [length] length of the padded portion (default 0)
|
|
5
|
+
* @param {string} [substr] substring to apply (default ' ')
|
|
7
6
|
* @returns {string} the input padded w/ spaces|substrings
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
8
|
* // if no `substr` is provided, it pads the string w/ spaces
|
|
11
9
|
* const result = strings.padEnd('abcabc', 9);
|
|
12
10
|
* console.log(result);
|
|
13
11
|
* > abcabc
|
|
14
|
-
*
|
|
15
12
|
* @example
|
|
16
13
|
* // if `length` is shorter than `string` it doesn't add any padding
|
|
17
14
|
* const result = strings.padEnd('abcabc', 4);
|
|
18
15
|
* console.log(result);
|
|
19
16
|
* > abcabc
|
|
20
|
-
*
|
|
21
17
|
* @example
|
|
22
18
|
* // if `substr` is defined, it uses that for padding
|
|
23
19
|
* const result = strings.padEnd('abcabc', 16, 'fun');
|
package/src/strings/padStart.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* PadStart pads the start of of a string.
|
|
3
|
-
*
|
|
4
3
|
* @param {string} string input string
|
|
5
|
-
* @param {number} [length
|
|
6
|
-
* @param {string} [substr
|
|
4
|
+
* @param {number} [length] length of the padded portion (default 0)
|
|
5
|
+
* @param {string} [substr] substring to apply (default ' ')
|
|
7
6
|
* @returns {string} the input padded w/ spaces|substrings
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
8
|
* // if no `substr` is provided, it pads the string w/ spaces
|
|
11
9
|
* const result = strings.padStart('abcabc', 9);
|
|
12
10
|
* console.log(result);
|
|
13
11
|
* > abcabc
|
|
14
|
-
*
|
|
15
12
|
* @example
|
|
16
13
|
* // if `length` is shorter than `string` it doesn't add any padding
|
|
17
14
|
* const result = strings.padStart('abcabc', 4);
|
|
18
15
|
* console.log(result);
|
|
19
16
|
* > abcabc
|
|
20
|
-
*
|
|
21
17
|
* @example
|
|
22
18
|
* // if `substr` is defined, it uses that for padding
|
|
23
19
|
* const result = strings.padStart('abcabc', 16, 'fun');
|
package/src/strings/repeat.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Repeat returns a new string containing the provided string copied and concatenated
|
|
3
3
|
* for the number of times given in the parameter
|
|
4
|
-
*
|
|
5
4
|
* @param {string} string input string
|
|
6
|
-
* @param {
|
|
5
|
+
* @param {number} count number of times to repeat the string
|
|
7
6
|
* @returns {string} string containing the specified number of copies of the given string
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
8
|
* const result = strings.repeat('Moo', 3);
|
|
11
9
|
* console.log(result);
|
package/src/strings/reverse.js
CHANGED
package/src/strings/snakeCase.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* StartsWith tests a string to see if it starts with a substring
|
|
3
|
-
*
|
|
4
3
|
* @param {string} string input string
|
|
5
4
|
* @param {string} substr substring to test
|
|
6
5
|
* @returns {boolean} does the input start with the substring?
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = strings.startsWith('This sentence starts with', 'This');
|
|
10
8
|
* console.log(result);
|
|
11
9
|
* > true
|
|
12
|
-
*
|
|
13
10
|
* @example
|
|
14
11
|
* const result = strings.startsWith('This sentence does not start with', 'Nope');
|
|
15
12
|
* console.log(result);
|
package/src/strings/trimEnd.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TrimEnd trims any whitespace or the selected characters from the end of the string
|
|
3
|
-
*
|
|
4
3
|
* @param {string} [string] input string
|
|
5
|
-
* @param {string} [chars
|
|
4
|
+
* @param {string} [chars] characters to remove from end of the string (default ' ')
|
|
6
5
|
* @returns {string} string with the characters removed from end of the string
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = strings.trimEnd('-_-abc-_-', '_-');
|
|
10
8
|
* console.log(result);
|
package/src/strings/trimStart.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TrimStart trims any whitespace or the selected characters from the beginning of the string
|
|
3
|
-
*
|
|
4
3
|
* @param {string} [string] input string
|
|
5
|
-
* @param {string} [chars
|
|
4
|
+
* @param {string} [chars] characters to remove from beginning of string (default ' ')
|
|
6
5
|
* @returns {string} string with the characters removed from beginning
|
|
7
|
-
*
|
|
8
6
|
* @example
|
|
9
7
|
* const result = strings.trimStart('-_-abc-_-', '_-');
|
|
10
8
|
* console.log(result);
|
package/src/strings/truncate.js
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Truncates string if it's longer than the given maximum string length. The last characters
|
|
3
3
|
* of the truncated string are replaced with the omission string which defaults to "...".
|
|
4
|
-
*
|
|
5
4
|
* @param {string} [string] string to truncate
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {number} [options.length
|
|
8
|
-
* @param {string} [options.omission
|
|
5
|
+
* @param {object} [options] object containing options (default {})
|
|
6
|
+
* @param {number} [options.length] Max length of truncated string (default 30)
|
|
7
|
+
* @param {string} [options.omission] string to indicate omitted text (default '...')
|
|
9
8
|
* @param {RegExp|string} [options.separator] the pattern to end truncation
|
|
10
9
|
* @returns {string} returns truncated string
|
|
11
|
-
*
|
|
12
10
|
* @example
|
|
13
11
|
* const result = strings.truncate('This sentence starts with', 'This');
|
|
14
12
|
* console.log(result);
|
|
15
13
|
* > true
|
|
16
|
-
|
|
17
|
-
function truncate (string, options) {
|
|
14
|
+
*/
|
|
15
|
+
function truncate (string, options = {}) {
|
|
18
16
|
let length = 30
|
|
19
17
|
let omission = '...'
|
|
20
18
|
let separator
|
|
21
19
|
if (options) {
|
|
22
|
-
if (options
|
|
23
|
-
if (options
|
|
24
|
-
if (options
|
|
20
|
+
if (options?.length !== undefined) { length = options.length }
|
|
21
|
+
if (options?.omission !== undefined) { omission = options.omission }
|
|
22
|
+
if (options?.separator !== undefined) { separator = options.separator }
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
if (length >= string.length) { return string }
|
package/src/strings/words.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
+
/* eslint-disable no-misleading-character-class */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Splits `string` into an array of its words.
|
|
3
|
-
*
|
|
4
5
|
* @param {string} [string] string to inspect for words
|
|
5
6
|
* @param {RegExp|string} [pattern] regex pattern to match words or string of characters to split words by.
|
|
6
7
|
* @returns {Array} Returns an array of words
|
|
7
|
-
*
|
|
8
8
|
* @example
|
|
9
9
|
* const result = words('I can, I should, & I will');
|
|
10
10
|
* console.log(result);
|
|
11
11
|
* // => ['I', 'can', 'I', 'should', 'I', 'will']
|
|
12
|
-
*
|
|
13
12
|
* @example
|
|
14
13
|
* const result = words('I can, I should, & I will', ' ,');
|
|
15
14
|
* console.log(result);
|
|
16
15
|
* // => ['I', 'can', 'I', 'should', '&', 'I', 'will']
|
|
17
|
-
*
|
|
18
16
|
* @example
|
|
19
17
|
* const result = words('I can, I should, & I will', /[^, ]+/g);
|
|
20
18
|
* console.log(result);
|