moderndash 0.0.11 → 0.0.12
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 +2 -2
- package/src/array/shuffle.ts +1 -1
- package/src/array/uniqWith.ts +1 -1
- package/src/collection/countBy.ts +4 -4
- package/src/collection/groupBy.ts +3 -3
- package/src/object/pick.ts +4 -5
- package/src/string/camelCase.ts +15 -0
- package/src/string/capitalize.ts +11 -0
- package/src/string/deburr.ts +15 -0
- package/src/string/escape.ts +11 -0
- package/src/string/escapeRegExp.ts +12 -0
- package/src/string/kebabCase.ts +15 -0
- package/src/string/pascalCase.ts +16 -0
- package/src/string/snakeCase.ts +17 -0
- package/src/string/startCase.ts +15 -0
- package/src/string/stripSpecialChars.ts +11 -0
- package/src/string/unescape.ts +14 -2
- package/LICENSE +0 -21
- package/README.md +0 -92
- package/dist/index.cjs +0 -711
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -668
- package/dist/index.js +0 -638
- package/dist/index.js.map +0 -1
- package/src/function/times.ts +0 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moderndash",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A lodash inspired utility framework for ESM/Typescript/ES2020",
|
|
6
6
|
"scripts": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"dist",
|
|
41
41
|
"src"
|
|
42
42
|
],
|
|
43
|
-
"homepage": "https://
|
|
43
|
+
"homepage": "https://moderndash.io",
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@vitest/coverage-c8": "0.27.1",
|
|
46
46
|
"@vitest/ui": "0.27.1",
|
package/src/array/shuffle.ts
CHANGED
package/src/array/uniqWith.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @category Array
|
|
6
6
|
* @param array - The array to inspect.
|
|
7
7
|
* @param comparator - The comparator invoked per element.
|
|
8
|
-
* @returns
|
|
8
|
+
* @returns Returns the new duplicate free array.
|
|
9
9
|
* @example
|
|
10
10
|
* const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]
|
|
11
11
|
*
|
|
@@ -7,10 +7,6 @@ import { getValuesFromCollection } from '@helpers/collections';
|
|
|
7
7
|
* each element of `collection` thru `iteratee`. The corresponding value of
|
|
8
8
|
* each key is the number of times the key was returned by `iteratee`.
|
|
9
9
|
*
|
|
10
|
-
* @category Collection
|
|
11
|
-
* @param iteratee - The iteratee to transform keys.
|
|
12
|
-
* @param collection - The array or record to iterate over.
|
|
13
|
-
* @returns Returns the composed aggregate object.
|
|
14
10
|
* @example
|
|
15
11
|
* const users = [
|
|
16
12
|
* { 'user': 'barney', 'active': true },
|
|
@@ -20,6 +16,10 @@ import { getValuesFromCollection } from '@helpers/collections';
|
|
|
20
16
|
*
|
|
21
17
|
* countBy(users, value => value.active);
|
|
22
18
|
* // => { 'true': 2, 'false': 1 }
|
|
19
|
+
* @category Collection
|
|
20
|
+
* @param iteratee - The iteratee to transform keys.
|
|
21
|
+
* @param collection - The array or record to iterate over.
|
|
22
|
+
* @returns Returns the composed aggregate object.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
export function countBy<TInput, TKey extends RecordKey>(collection: ArrayOrRecord<TInput>, iteratee: (value: TInput) => TKey): Record<TKey, number> {
|
|
@@ -10,13 +10,13 @@ import { getValuesFromCollection } from '@helpers/collections';
|
|
|
10
10
|
* value of each key is an array of elements responsible for generating the
|
|
11
11
|
* key.
|
|
12
12
|
*
|
|
13
|
+
* @example
|
|
14
|
+
* groupBy([6.1, 4.2, 6.3], Math.floor)
|
|
15
|
+
* // => { '4': [4.2], '6': [6.1, 6.3] }
|
|
13
16
|
* @category Collection
|
|
14
17
|
* @param collection - The array or object to iterate over.
|
|
15
18
|
* @param iteratee - The iteratee to transform keys.
|
|
16
19
|
* @returns Returns the composed aggregate object.
|
|
17
|
-
* @example
|
|
18
|
-
* groupBy([6.1, 4.2, 6.3], Math.floor)
|
|
19
|
-
* // => { '4': [4.2], '6': [6.1, 6.3] }
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
export function groupBy<T, U extends RecordKey>(collection: ArrayOrRecord<T>, iteratee: (value: T) => U): Record<U, T[]> {
|
package/src/object/pick.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates an object composed of the picked `object` properties.
|
|
3
3
|
*
|
|
4
|
-
* @category Object
|
|
5
|
-
* @param object The source object.
|
|
6
|
-
* @param keys The property paths to pick.
|
|
7
|
-
* @returns {Object} Returns the new object.
|
|
8
4
|
* @example
|
|
9
|
-
*
|
|
10
5
|
* const object = { 'a': 1, 'b': '2', 'c': 3 }
|
|
11
6
|
*
|
|
12
7
|
* pick(object, ['a', 'c'])
|
|
13
8
|
* // => { 'a': 1, 'c': 3 }
|
|
9
|
+
* @category Object
|
|
10
|
+
* @param object - The source object.
|
|
11
|
+
* @param keys - The property paths to pick.
|
|
12
|
+
* @returns Returns the new object.
|
|
14
13
|
*/
|
|
15
14
|
|
|
16
15
|
export function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K> {
|
package/src/string/camelCase.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { splitWords } from '@helpers/stringModifiers';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Converts `string` to camelCase.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* camelCase('Foo Bar')
|
|
8
|
+
* // => 'fooBar'
|
|
9
|
+
* camelCase('--foo-bar--')
|
|
10
|
+
* // => 'fooBar'
|
|
11
|
+
* camelCase('__FOO_BAR__')
|
|
12
|
+
* // => 'fooBar'
|
|
13
|
+
* @category String
|
|
14
|
+
* @param str - The string to convert.
|
|
15
|
+
* @returns Returns the camel cased string.
|
|
16
|
+
*/
|
|
17
|
+
|
|
3
18
|
export function camelCase(str: string): string {
|
|
4
19
|
const words = splitWords(str);
|
|
5
20
|
|
package/src/string/capitalize.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the first character of a string to upper case and the remaining to lower case.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* capitalize('FRED')
|
|
6
|
+
* // => 'Fred'
|
|
7
|
+
* @category String
|
|
8
|
+
* @param str - The string to capitalize.
|
|
9
|
+
* @returns Returns the capitalized string.
|
|
10
|
+
*/
|
|
11
|
+
|
|
1
12
|
export function capitalize(str: string): string {
|
|
2
13
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
3
14
|
}
|
package/src/string/deburr.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deburrs a string by converting
|
|
3
|
+
* [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
|
|
4
|
+
* and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
|
|
5
|
+
* letters to basic Latin letters and removing
|
|
6
|
+
* [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* deburr('déjà vu')
|
|
10
|
+
* // => 'deja vu'
|
|
11
|
+
* @category String
|
|
12
|
+
* @param str - The string to deburr.
|
|
13
|
+
* @returns Returns the deburred string.
|
|
14
|
+
*/
|
|
15
|
+
|
|
1
16
|
export function deburr(str: string): string {
|
|
2
17
|
// eslint-disable-next-line no-control-regex
|
|
3
18
|
return str.replace(/[^\u0000-\u007E]/g, (chr: string) =>
|
package/src/string/escape.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the characters `&`, `<`, `>`, `"` and `'` in a string to their corresponding HTML entities.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* escape('fred, barney, & pebbles')
|
|
6
|
+
* // => 'fred, barney, & pebbles'
|
|
7
|
+
* @category String
|
|
8
|
+
* @param str - The string to escape.
|
|
9
|
+
* @returns Returns the escaped string.
|
|
10
|
+
*/
|
|
11
|
+
|
|
1
12
|
export function escape(str: string): string {
|
|
2
13
|
const escapeChars: Record<string, string> = {
|
|
3
14
|
'&': '&',
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escapes the `RegExp` special characters `^`, `$`, `\`, `.`, `*`, `+`,
|
|
3
|
+
* `?`, `(`, `)`, `[`, `]`, `{`, `}`, and `|` in a string.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* escapeRegExp('[moderndash](https://moderndash.io/)')
|
|
7
|
+
* // => '\[moderndash\]\(https://moderndash\.io/\)'
|
|
8
|
+
* @category String
|
|
9
|
+
* @param str - The string to escape.
|
|
10
|
+
* @returns Returns the escaped string.
|
|
11
|
+
*/
|
|
12
|
+
|
|
1
13
|
export function escapeRegExp(str: string): string {
|
|
2
14
|
return str.replace(/[$()*+.?[\\\]^{|}]/g, '\\$&');
|
|
3
15
|
}
|
package/src/string/kebabCase.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { splitWords } from '@helpers/stringModifiers';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Converts a string to kebab-case.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* kebabCase('Foo Bar')
|
|
8
|
+
* // => 'foo-bar'
|
|
9
|
+
* kebabCase('fooBar')
|
|
10
|
+
* // => 'foo-bar'
|
|
11
|
+
* kebabCase('__FOO_BAR__')
|
|
12
|
+
* // => 'foo-bar'
|
|
13
|
+
* @category String
|
|
14
|
+
* @param str - The string to convert.
|
|
15
|
+
* @returns Returns the kebab cased string.
|
|
16
|
+
*/
|
|
17
|
+
|
|
3
18
|
export function kebabCase(str: string): string {
|
|
4
19
|
const words = splitWords(str);
|
|
5
20
|
let kebabCase = '';
|
package/src/string/pascalCase.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { splitWords } from '@helpers/stringModifiers';
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts a string to PascalCase.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* kebabCase('Foo Bar')
|
|
9
|
+
* // => 'FooBar'
|
|
10
|
+
* kebabCase('fooBar')
|
|
11
|
+
* // => 'FooBar'
|
|
12
|
+
* kebabCase('__FOO_BAR__')
|
|
13
|
+
* // => 'FooBar'
|
|
14
|
+
* @category String
|
|
15
|
+
* @param str - The string to convert.
|
|
16
|
+
* @returns Returns the pascal cased string.
|
|
17
|
+
*/
|
|
18
|
+
|
|
3
19
|
export function pascalCase(str: string): string {
|
|
4
20
|
const words = splitWords(str);
|
|
5
21
|
let pascalCase = '';
|
package/src/string/snakeCase.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { splitWords } from '@helpers/stringModifiers';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Converts a string to snake_case.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* snakeCase('Foo Bar')
|
|
8
|
+
* // => 'foo_bar'
|
|
9
|
+
* snakeCase('fooBar')
|
|
10
|
+
* // => 'foo_bar'
|
|
11
|
+
* snakeCase('--FOO-BAR--')
|
|
12
|
+
* // => 'foo_bar'
|
|
13
|
+
* snakeCase('foo2bar')
|
|
14
|
+
* // => 'foo_2_bar'
|
|
15
|
+
* @category String
|
|
16
|
+
* @param str - The string to convert.
|
|
17
|
+
* @returns Returns the snake cased string.
|
|
18
|
+
*/
|
|
19
|
+
|
|
3
20
|
export function snakeCase(str: string): string {
|
|
4
21
|
const words = splitWords(str);
|
|
5
22
|
let snakeCase = '';
|
package/src/string/startCase.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { splitWords } from '@helpers/stringModifiers';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Converts a string to Start Case.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* startCase('--foo-bar--')
|
|
8
|
+
* // => 'Foo Bar'
|
|
9
|
+
* startCase('fooBar')
|
|
10
|
+
* // => 'Foo Bar'
|
|
11
|
+
* startCase('__FOO_BAR__')
|
|
12
|
+
* // => 'Foo Bar'
|
|
13
|
+
* @category String
|
|
14
|
+
* @param str - The string to convert.
|
|
15
|
+
* @returns Returns the start cased string.
|
|
16
|
+
*/
|
|
17
|
+
|
|
3
18
|
export function startCase(str: string): string {
|
|
4
19
|
const words = splitWords(str);
|
|
5
20
|
let startCase = '';
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { deburr } from '@string/deburr';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Removes all special characters from a string.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* stripSpecialChars('Héllo! World #$%&*!')
|
|
8
|
+
* // => 'Hello World'
|
|
9
|
+
* @category String
|
|
10
|
+
* @param str - The string to remove special characters from.
|
|
11
|
+
* @returns Returns the string with special characters removed.
|
|
12
|
+
*/
|
|
13
|
+
|
|
3
14
|
export function stripSpecialChars(str: string): string {
|
|
4
15
|
str = deburr(str);
|
|
5
16
|
return str.replace(/[^\s\w]/gi, '');
|
package/src/string/unescape.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Converts the HTML entities `&`, `<`, `>`, `"` and `'`
|
|
3
|
+
* in a string to their corresponding characters.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* unescape('fred, barney, & pebbles')
|
|
7
|
+
* // => 'fred, barney, & pebbles'
|
|
8
|
+
* @category String
|
|
9
|
+
* @param str - The string to unescape.
|
|
10
|
+
* @returns Returns the unescaped string.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export function unescape(str: string): string {
|
|
2
14
|
const entityMap: Record<string, string> = {
|
|
3
15
|
'&': '&',
|
|
4
16
|
'<': '<',
|
|
@@ -6,5 +18,5 @@ export function unescapeHTML(html: string): string {
|
|
|
6
18
|
'"': '"',
|
|
7
19
|
''': '\''
|
|
8
20
|
};
|
|
9
|
-
return
|
|
21
|
+
return str.replace(/&(?:amp|lt|gt|quot|#(0+)?39);/g, (entity: string) => entityMap[entity] || entity);
|
|
10
22
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
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
|
-
|
|
22
|
-
## Removed Functions because of trivial native alternatives
|
|
23
|
-
Look at [You-Dont-Need-Lodash](https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore) for native replacements.
|
|
24
|
-
|
|
25
|
-
### Array Functions
|
|
26
|
-
- compact
|
|
27
|
-
- concat
|
|
28
|
-
- differenceBy property shorthand
|
|
29
|
-
- drop
|
|
30
|
-
- dropRight
|
|
31
|
-
- fill
|
|
32
|
-
- findIndex
|
|
33
|
-
- findLastIndex
|
|
34
|
-
- first/head
|
|
35
|
-
- flatten
|
|
36
|
-
- flattenDeep
|
|
37
|
-
- flattenDepth
|
|
38
|
-
- fromPairs
|
|
39
|
-
- initial
|
|
40
|
-
- join
|
|
41
|
-
- last
|
|
42
|
-
- lastIndexOf
|
|
43
|
-
- nth
|
|
44
|
-
- without
|
|
45
|
-
- reverse
|
|
46
|
-
- slice
|
|
47
|
-
- sortedIndexOf
|
|
48
|
-
- tail
|
|
49
|
-
- take
|
|
50
|
-
- takeRight
|
|
51
|
-
- without
|
|
52
|
-
|
|
53
|
-
### Collection Functions
|
|
54
|
-
- each/forEach
|
|
55
|
-
- every
|
|
56
|
-
- filter
|
|
57
|
-
- find
|
|
58
|
-
- flatMap
|
|
59
|
-
- includes
|
|
60
|
-
|
|
61
|
-
### String Functions
|
|
62
|
-
- lowerCase
|
|
63
|
-
- trim
|
|
64
|
-
- trimEnd
|
|
65
|
-
- trimStart
|
|
66
|
-
- pad
|
|
67
|
-
- padEnd
|
|
68
|
-
- padStart
|
|
69
|
-
|
|
70
|
-
Functions are not considered trivial if they:
|
|
71
|
-
- include reduce methods
|
|
72
|
-
- include multiple nested function calls
|
|
73
|
-
|
|
74
|
-
## TODO
|
|
75
|
-
- More unzip tests
|
|
76
|
-
- Check if flatmapdeep, flatmapDepth is included in native flatmap
|
|
77
|
-
- GroupBy Property Shorthand
|
|
78
|
-
|
|
79
|
-
## Might be added later (open for discussion)
|
|
80
|
-
- pull functions (pull, pullAll, pullAllBy, pullAllWith, pullAt)
|
|
81
|
-
- remove
|
|
82
|
-
- sorted functions (sortedIndex, sortedIndexBy, sortedIndexOf, sortedLastIndex, sortedLastIndexBy, sortedLastIndexOf, sortedUniq, sortedUniqBy)
|
|
83
|
-
- if performance is better than native alternatives (testing needed)
|
|
84
|
-
- xor functions (xor, xorBy, xorWith)
|
|
85
|
-
- zipObject, zipObjectDeep
|
|
86
|
-
- forEachRight
|
|
87
|
-
- findLast
|
|
88
|
-
- lowerFirst
|
|
89
|
-
- keyBy
|
|
90
|
-
|
|
91
|
-
## Continue at
|
|
92
|
-
- invokeMap
|