moderndash 0.0.12 → 0.0.14
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/LICENSE +21 -0
- package/README.md +93 -0
- package/package.json +1 -1
- package/src/array/intersectionBy.ts +3 -3
- package/src/array/intersectionWith.ts +4 -4
- package/src/function/times.ts +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Maximilian Dewald
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
<p align=center>
|
|
4
|
+
A Typescript-First utility library inspired by Lodash.
|
|
5
|
+
Optimized for modern browsers.
|
|
6
|
+
</p>
|
|
7
|
+
<p align=center>
|
|
8
|
+
✅ ESM
|
|
9
|
+
✅ Tree-shakable
|
|
10
|
+
✅ Typescript Strict Mode (no any types)
|
|
11
|
+
✅ Zero dependencies
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
-------
|
|
15
|
+
|
|
16
|
+
> **Warning**
|
|
17
|
+
> This library is still in development and is not ready for production use.
|
|
18
|
+
|
|
19
|
+
## Documentation
|
|
20
|
+
The documentation is WIP.
|
|
21
|
+
[Documentation](https://moderndash.io/)
|
|
22
|
+
|
|
23
|
+
## Removed Functions because of trivial native alternatives
|
|
24
|
+
Look at [You-Dont-Need-Lodash](https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore) for native replacements.
|
|
25
|
+
|
|
26
|
+
### Array Functions
|
|
27
|
+
- compact
|
|
28
|
+
- concat
|
|
29
|
+
- differenceBy property shorthand
|
|
30
|
+
- drop
|
|
31
|
+
- dropRight
|
|
32
|
+
- fill
|
|
33
|
+
- findIndex
|
|
34
|
+
- findLastIndex
|
|
35
|
+
- first/head
|
|
36
|
+
- flatten
|
|
37
|
+
- flattenDeep
|
|
38
|
+
- flattenDepth
|
|
39
|
+
- fromPairs
|
|
40
|
+
- initial
|
|
41
|
+
- join
|
|
42
|
+
- last
|
|
43
|
+
- lastIndexOf
|
|
44
|
+
- nth
|
|
45
|
+
- without
|
|
46
|
+
- reverse
|
|
47
|
+
- slice
|
|
48
|
+
- sortedIndexOf
|
|
49
|
+
- tail
|
|
50
|
+
- take
|
|
51
|
+
- takeRight
|
|
52
|
+
- without
|
|
53
|
+
|
|
54
|
+
### Collection Functions
|
|
55
|
+
- each/forEach
|
|
56
|
+
- every
|
|
57
|
+
- filter
|
|
58
|
+
- find
|
|
59
|
+
- flatMap
|
|
60
|
+
- includes
|
|
61
|
+
|
|
62
|
+
### String Functions
|
|
63
|
+
- lowerCase
|
|
64
|
+
- trim
|
|
65
|
+
- trimEnd
|
|
66
|
+
- trimStart
|
|
67
|
+
- pad
|
|
68
|
+
- padEnd
|
|
69
|
+
- padStart
|
|
70
|
+
|
|
71
|
+
Functions are not considered trivial if they:
|
|
72
|
+
- include reduce methods
|
|
73
|
+
- include multiple nested function calls
|
|
74
|
+
|
|
75
|
+
## TODO
|
|
76
|
+
- More unzip tests
|
|
77
|
+
- Check if flatmapdeep, flatmapDepth is included in native flatmap
|
|
78
|
+
- GroupBy Property Shorthand
|
|
79
|
+
|
|
80
|
+
## Might be added later (open for discussion)
|
|
81
|
+
- pull functions (pull, pullAll, pullAllBy, pullAllWith, pullAt)
|
|
82
|
+
- remove
|
|
83
|
+
- sorted functions (sortedIndex, sortedIndexBy, sortedIndexOf, sortedLastIndex, sortedLastIndexBy, sortedLastIndexOf, sortedUniq, sortedUniqBy)
|
|
84
|
+
- if performance is better than native alternatives (testing needed)
|
|
85
|
+
- xor functions (xor, xorBy, xorWith)
|
|
86
|
+
- zipObject, zipObjectDeep
|
|
87
|
+
- forEachRight
|
|
88
|
+
- findLast
|
|
89
|
+
- lowerFirst
|
|
90
|
+
- keyBy
|
|
91
|
+
|
|
92
|
+
## Continue at
|
|
93
|
+
- invokeMap
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@ import { isEqualWith } from '@lang/isEqualWith';
|
|
|
11
11
|
* determined by the first array. The iteratee is invoked with one argument:
|
|
12
12
|
* (value).
|
|
13
13
|
*
|
|
14
|
+
* @example
|
|
15
|
+
* intersectionBy(Math.floor, [2.1, 1.2], [2.3, 3.4])
|
|
16
|
+
* // => [2.1]
|
|
14
17
|
* @category Array
|
|
15
18
|
* @param iteratee - The iteratee invoked per element. Or property shorthand.
|
|
16
19
|
* @param arrays - The arrays to inspect.
|
|
17
20
|
* @returns Returns the new array of intersecting values.
|
|
18
|
-
* @example
|
|
19
|
-
* intersectionBy(Math.floor, [2.1, 1.2], [2.3, 3.4])
|
|
20
|
-
* // => [2.1]
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
export function intersectionBy<TInput>(iteratee: IterateeFunction<TInput> | PropertyShorthand<TInput>, ...arrays: MinimumTwoArrays<TInput>): TInput[] {
|
|
@@ -6,16 +6,16 @@ import type { MinimumTwoArrays } from '../types';
|
|
|
6
6
|
* of result values are determined by the first array. The comparator is
|
|
7
7
|
* invoked with two arguments: (arrVal, othVal).
|
|
8
8
|
*
|
|
9
|
-
* @category Array
|
|
10
|
-
* @param comparator - The comparator invoked per element.
|
|
11
|
-
* @param arrays - The arrays to inspect.
|
|
12
|
-
* @returns Returns the new array of intersecting values.
|
|
13
9
|
* @example
|
|
14
10
|
* const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
|
|
15
11
|
* const others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]
|
|
16
12
|
*
|
|
17
13
|
* intersectionWith(isEqual, objects, others)
|
|
18
14
|
* // => [{ 'x': 1, 'y': 2 }]
|
|
15
|
+
* @category Array
|
|
16
|
+
* @param comparator - The comparator invoked per element.
|
|
17
|
+
* @param arrays - The arrays to inspect.
|
|
18
|
+
* @returns Returns the new array of intersecting values.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
export function intersectionWith<T>(comparator: (a: T, b: T) => boolean, ...arrays: MinimumTwoArrays<T>): T[] {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invokes the iteratee `n` times, returning an array of the results of
|
|
3
|
+
* each invocation. The function is invoked with one argument: (index).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* times(3, index => console.log("Run", index)))
|
|
7
|
+
* // => "Run 0" | "Run 1" | "Run 2"
|
|
8
|
+
* times(3, Math.random)
|
|
9
|
+
* // => [0.123, 0.456, 0.789]
|
|
10
|
+
* times(4, () => 0)
|
|
11
|
+
* // => [0, 0, 0, 0]
|
|
12
|
+
* @category Function
|
|
13
|
+
* @param n - The number of times to invoke `func`.
|
|
14
|
+
* @param iteratee - The function invoked per iteration.
|
|
15
|
+
* @returns Returns the array of results.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export function times<T>(n: number, func: (index: number) => T): T[] {
|
|
19
|
+
const result: T[] = [];
|
|
20
|
+
for (let i = 0; i < n; i++) {
|
|
21
|
+
result.push(func(i));
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|