@webalternatif/js-core 1.6.0 → 1.6.3
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/dist/cjs/array.js +13 -1
- package/dist/cjs/dom.js +4 -4
- package/dist/cjs/is.js +5 -5
- package/dist/cjs/onOff.js +2 -2
- package/dist/cjs/random.js +6 -6
- package/dist/cjs/string.js +19 -17
- package/dist/cjs/utils.js +1 -1
- package/dist/esm/Mouse.js +1 -1
- package/dist/esm/Translator.js +2 -2
- package/dist/esm/array.js +17 -5
- package/dist/esm/dom.js +8 -8
- package/dist/esm/eventDispatcher.js +2 -2
- package/dist/esm/is.js +6 -6
- package/dist/esm/math.js +3 -3
- package/dist/esm/onOff.js +6 -6
- package/dist/esm/random.js +6 -6
- package/dist/esm/string.js +23 -21
- package/dist/esm/stringPrototype.js +2 -2
- package/dist/esm/traversal.js +3 -3
- package/dist/esm/utils.js +3 -3
- package/docs/array.md +57 -0
- package/docs/dom.md +683 -0
- package/docs/eventDispatcher.md +15 -0
- package/docs/is.md +15 -0
- package/docs/math.md +47 -0
- package/docs/mouse.md +15 -0
- package/docs/random.md +15 -0
- package/docs/string.md +145 -0
- package/docs/translator.md +95 -0
- package/docs/traversal.md +159 -0
- package/docs/utils.md +75 -0
- package/package.json +30 -4
- package/types/array.d.ts +2 -2
- package/types/dom.d.ts +4 -4
- package/types/index.d.ts +2 -2
package/docs/math.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Math Utilities
|
|
2
|
+
|
|
3
|
+
Description of the math utilities.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { math } from '@webalternatif/js-core'
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
<!-- GENERATED:math -->
|
|
15
|
+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
16
|
+
|
|
17
|
+
## dec2hex
|
|
18
|
+
|
|
19
|
+
[src/math.js:79-82][1]
|
|
20
|
+
|
|
21
|
+
Converts a decimal number into hexadecimal
|
|
22
|
+
|
|
23
|
+
### Parameters
|
|
24
|
+
|
|
25
|
+
* `n` **[number][2]** 
|
|
26
|
+
|
|
27
|
+
Returns **[string][3]** 
|
|
28
|
+
|
|
29
|
+
## hex2dec
|
|
30
|
+
|
|
31
|
+
[src/math.js:90-109][4]
|
|
32
|
+
|
|
33
|
+
Converts a hexadecimal into a decimal number
|
|
34
|
+
|
|
35
|
+
### Parameters
|
|
36
|
+
|
|
37
|
+
* `hex` **[string][3]** 
|
|
38
|
+
|
|
39
|
+
Returns **[number][2]** 
|
|
40
|
+
|
|
41
|
+
[1]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/math.js#L79-L82 "Source code on GitHub"
|
|
42
|
+
|
|
43
|
+
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
44
|
+
|
|
45
|
+
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
46
|
+
|
|
47
|
+
[4]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/math.js#L90-L109 "Source code on GitHub"
|
package/docs/mouse.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Mouse Utilities
|
|
2
|
+
|
|
3
|
+
Description of the mouse utilities.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { mouse } from '@webalternatif/js-core'
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
<!-- GENERATED:mouse -->
|
|
15
|
+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
package/docs/random.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Random Utilities
|
|
2
|
+
|
|
3
|
+
Description of the random utilities.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { random } from '@webalternatif/js-core'
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
<!-- GENERATED:random -->
|
|
15
|
+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
package/docs/string.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# String Utilities
|
|
2
|
+
|
|
3
|
+
Description of the string utilities.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { string } from '@webalternatif/js-core'
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
<!-- GENERATED:string -->
|
|
15
|
+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
16
|
+
|
|
17
|
+
## pad
|
|
18
|
+
|
|
19
|
+
Pads a string to a specified length with a specified string and padding type
|
|
20
|
+
|
|
21
|
+
### Parameters
|
|
22
|
+
|
|
23
|
+
* `str` **[string][1]** 
|
|
24
|
+
* `pad_length` **[number][2]** 
|
|
25
|
+
* `pad_str` **[string][1]?** (optional, default `' '`)
|
|
26
|
+
* `pad_type` **[string][1]?** (optional, default `'left'`)
|
|
27
|
+
|
|
28
|
+
Returns **[string][1]** 
|
|
29
|
+
|
|
30
|
+
## rgb2hex
|
|
31
|
+
|
|
32
|
+
Converts RGB values to a hexadecimal color string.
|
|
33
|
+
|
|
34
|
+
### Parameters
|
|
35
|
+
|
|
36
|
+
* `r` **([number][2] | [Array][3]<[number][2]>)** Either an array representing a RGB color (e.g. \[255, 0, 0]) or the red component as a
|
|
37
|
+
number (0-255).
|
|
38
|
+
* `g` **[number][2]?** The green component (0-255). Required if `r` is a number.
|
|
39
|
+
* `b` **[number][2]?** The blue component (0-255). Required if `r` is a number.
|
|
40
|
+
|
|
41
|
+
### Examples
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
// Using separate RGB components
|
|
45
|
+
rgb2hex(255, 0, 0); // Returns 'FF0000'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
// Using an array of RGB components
|
|
50
|
+
rgb2hex([255, 0, 0]); // Returns 'FF0000'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Returns **[string][1]** The hexadecimal color string (e.g., 'FF0000').
|
|
54
|
+
|
|
55
|
+
## hex2rgb
|
|
56
|
+
|
|
57
|
+
Converts a hexadecimal color to RGB values.
|
|
58
|
+
|
|
59
|
+
### Parameters
|
|
60
|
+
|
|
61
|
+
* `hex` **[string][1]** The hexadecimal value (e.g #FF0000)
|
|
62
|
+
|
|
63
|
+
Returns **[Array][3]<[number][2]>** The RGB color array (e.g \[255, 0, 0]).
|
|
64
|
+
|
|
65
|
+
## parse\_url
|
|
66
|
+
|
|
67
|
+
Parses a URL string into its components.
|
|
68
|
+
|
|
69
|
+
### Parameters
|
|
70
|
+
|
|
71
|
+
* `str` **[string][1]** The URL string to be parsed.
|
|
72
|
+
|
|
73
|
+
### Properties
|
|
74
|
+
|
|
75
|
+
* `scheme` **[string][1]?** The scheme (protocol) of the URL (e.g., `http`, `https`).
|
|
76
|
+
* `authority` **[string][1]?** The authority part of the URL.
|
|
77
|
+
* `userInfo` **[string][1]?** The user information (e.g., `user:pass`).
|
|
78
|
+
* `user` **[string][1]?** The username from the user information.
|
|
79
|
+
* `pass` **[string][1]?** The password from the user information.
|
|
80
|
+
* `host` **[string][1]?** The host of the URL (e.g., `example.com`).
|
|
81
|
+
* `port` **[string][1]?** The port of the URL (e.g., `8080`).
|
|
82
|
+
* `relative` **[string][1]?** The relative URL.
|
|
83
|
+
* `path` **[string][1]?** The path of the URL (e.g., `/path/to/resource`).
|
|
84
|
+
* `directory` **[string][1]?** The directory of the URL path.
|
|
85
|
+
* `file` **[string][1]?** The file name from the path, if applicable.
|
|
86
|
+
* `query` **[string][1]?** The query string (e.g., `key=value&key2=value2`).
|
|
87
|
+
* `fragment` **[string][1]?** The fragment (hash) of the URL (e.g., `#section`).
|
|
88
|
+
|
|
89
|
+
Returns **[Object][4]** An object containing the parsed components of the URL.
|
|
90
|
+
|
|
91
|
+
## addUrlParam
|
|
92
|
+
|
|
93
|
+
Adds or updates one or more query parameters to a given URL.
|
|
94
|
+
|
|
95
|
+
### Parameters
|
|
96
|
+
|
|
97
|
+
* `url` **[string][1]** The URL to which the parameters should be added.
|
|
98
|
+
* `param` **([string][1] | [Object][4])** The key of the parameter to add, or an object containing multiple key-value pairs to add.
|
|
99
|
+
* `value` **([string][1] | null)** The value of the parameter to add. Ignored if `param` is an object. (optional, default `null`)
|
|
100
|
+
|
|
101
|
+
### Examples
|
|
102
|
+
|
|
103
|
+
Add a single parameter to a URL without a query string
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
addUrlParam('https://example.com', 'key', 'value');
|
|
107
|
+
// Returns: 'https://example.com?key=value'
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Add multiple parameters to a URL
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
addUrlParam('https://example.com', { key1: 'value1', key2: 'value2' });
|
|
114
|
+
// Returns: 'https://example.com?key1=value1&key2=value2'
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Returns **[string][1]** The updated URL with the new query parameters.
|
|
118
|
+
|
|
119
|
+
## escapeRegex
|
|
120
|
+
|
|
121
|
+
* **See**: [http://stackoverflow.com/questions/3115150/how-to-escape-regular-expression-special-characters-using-javascript][5]
|
|
122
|
+
|
|
123
|
+
### Parameters
|
|
124
|
+
|
|
125
|
+
* `str`  
|
|
126
|
+
|
|
127
|
+
## toCssClassName
|
|
128
|
+
|
|
129
|
+
* **See**: [https://stackoverflow.com/questions/7627000/javascript-convert-string-to-safe-class-name-for-css][6]
|
|
130
|
+
|
|
131
|
+
### Parameters
|
|
132
|
+
|
|
133
|
+
* `str`  
|
|
134
|
+
|
|
135
|
+
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
136
|
+
|
|
137
|
+
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
138
|
+
|
|
139
|
+
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
140
|
+
|
|
141
|
+
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
142
|
+
|
|
143
|
+
[5]: http://stackoverflow.com/questions/3115150/how-to-escape-regular-expression-special-characters-using-javascript
|
|
144
|
+
|
|
145
|
+
[6]: https://stackoverflow.com/questions/7627000/javascript-convert-string-to-safe-class-name-for-css
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Translator
|
|
2
|
+
|
|
3
|
+
Description of the translator.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { translator } from '@webalternatif/js-core'
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
<!-- GENERATED:translator -->
|
|
15
|
+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
16
|
+
|
|
17
|
+
## Translator
|
|
18
|
+
|
|
19
|
+
[src/Translator.js:20-142][1]
|
|
20
|
+
|
|
21
|
+
### Parameters
|
|
22
|
+
|
|
23
|
+
* `mapping`  
|
|
24
|
+
* `defaultLang`  
|
|
25
|
+
|
|
26
|
+
### translate
|
|
27
|
+
|
|
28
|
+
[src/Translator.js:61-75][2]
|
|
29
|
+
|
|
30
|
+
#### Parameters
|
|
31
|
+
|
|
32
|
+
* `label` **[string][3]** 
|
|
33
|
+
* `lang` **[string][3]?** 
|
|
34
|
+
* `namespace` **[string][3]** (optional, default `'core'`)
|
|
35
|
+
|
|
36
|
+
Returns **[string][3]** 
|
|
37
|
+
|
|
38
|
+
### translateFrom
|
|
39
|
+
|
|
40
|
+
[src/Translator.js:83-100][4]
|
|
41
|
+
|
|
42
|
+
#### Parameters
|
|
43
|
+
|
|
44
|
+
* `label` **[string][3]** 
|
|
45
|
+
* `from` **[string][3]** Language from.
|
|
46
|
+
* `to` **[string][3]** Language to.
|
|
47
|
+
* `namespace` **[string][3]** (optional, default `'core'`)
|
|
48
|
+
|
|
49
|
+
## TranslatorNsMapping
|
|
50
|
+
|
|
51
|
+
[src/Translator.js:20-142][5]
|
|
52
|
+
|
|
53
|
+
Type: Record<[string][3], Record<[string][3], Record<[string][3], TranslatorValue>>>
|
|
54
|
+
|
|
55
|
+
## TranslatorCoreMapping
|
|
56
|
+
|
|
57
|
+
[src/Translator.js:20-142][6]
|
|
58
|
+
|
|
59
|
+
Type: Record<[string][3], Record<[string][3], TranslatorValue>>
|
|
60
|
+
|
|
61
|
+
## TranslatorMapping
|
|
62
|
+
|
|
63
|
+
[src/Translator.js:20-142][7]
|
|
64
|
+
|
|
65
|
+
Type: ([TranslatorNsMapping][8] | [TranslatorCoreMapping][9])
|
|
66
|
+
|
|
67
|
+
## lang
|
|
68
|
+
|
|
69
|
+
[src/Translator.js:22-22][10]
|
|
70
|
+
|
|
71
|
+
## mapping
|
|
72
|
+
|
|
73
|
+
[src/Translator.js:25-25][11]
|
|
74
|
+
|
|
75
|
+
[1]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/Translator.js#L20-L142 "Source code on GitHub"
|
|
76
|
+
|
|
77
|
+
[2]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/Translator.js#L61-L75 "Source code on GitHub"
|
|
78
|
+
|
|
79
|
+
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
80
|
+
|
|
81
|
+
[4]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/Translator.js#L83-L100 "Source code on GitHub"
|
|
82
|
+
|
|
83
|
+
[5]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/Translator.js#L8-L10 "Source code on GitHub"
|
|
84
|
+
|
|
85
|
+
[6]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/Translator.js#L12-L14 "Source code on GitHub"
|
|
86
|
+
|
|
87
|
+
[7]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/Translator.js#L16-L18 "Source code on GitHub"
|
|
88
|
+
|
|
89
|
+
[8]: #translatornsmapping
|
|
90
|
+
|
|
91
|
+
[9]: #translatorcoremapping
|
|
92
|
+
|
|
93
|
+
[10]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/Translator.js#L22-L22 "Source code on GitHub"
|
|
94
|
+
|
|
95
|
+
[11]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/Translator.js#L25-L25 "Source code on GitHub"
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Traversal Utilities
|
|
2
|
+
|
|
3
|
+
Description of the traversal utilities.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { traversal } from '@webalternatif/js-core'
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
<!-- GENERATED:traversal -->
|
|
15
|
+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
16
|
+
|
|
17
|
+
## Collection
|
|
18
|
+
|
|
19
|
+
[src/traversal.js:24-70][1]
|
|
20
|
+
|
|
21
|
+
Type: ([Array][2]\<T> | [Set][3]\<T> | [Map][4]\<any, T> | [Object][5]<[string][6], T> | [string][6] | [Array][2]<[string][6]>)
|
|
22
|
+
|
|
23
|
+
## each
|
|
24
|
+
|
|
25
|
+
[src/traversal.js:24-70][7]
|
|
26
|
+
|
|
27
|
+
Iterates over Arrays, Strings, Maps, Sets and plain Objects.
|
|
28
|
+
|
|
29
|
+
The callback receives:
|
|
30
|
+
(keyOrIndex, value, o, index)
|
|
31
|
+
|
|
32
|
+
If the callback returns `false`, the iteration stops.
|
|
33
|
+
|
|
34
|
+
### Parameters
|
|
35
|
+
|
|
36
|
+
* `o` **[Collection][8]\<T>** 
|
|
37
|
+
* `callback`  
|
|
38
|
+
* `context` **any?** Optional "this" binding for the callback
|
|
39
|
+
|
|
40
|
+
## foreach
|
|
41
|
+
|
|
42
|
+
[src/traversal.js:84-86][9]
|
|
43
|
+
|
|
44
|
+
Same as each except that key and value are reversed in callback
|
|
45
|
+
|
|
46
|
+
The callback receives:
|
|
47
|
+
(value, keyOrIndex, o, index)
|
|
48
|
+
|
|
49
|
+
### Parameters
|
|
50
|
+
|
|
51
|
+
* `o` **[Collection][8]\<T>** 
|
|
52
|
+
* `callback`  
|
|
53
|
+
* `context` **any?** Optional "this" binding for the callback
|
|
54
|
+
|
|
55
|
+
## map
|
|
56
|
+
|
|
57
|
+
[src/traversal.js:103-114][10]
|
|
58
|
+
|
|
59
|
+
Iterates over Arrays, Strings, Maps, Sets and plain Objects.
|
|
60
|
+
Returns an array from the callback results.
|
|
61
|
+
Values strictly equal to `null` are skipped.
|
|
62
|
+
Values strictly equal to `false` stops the iteration.
|
|
63
|
+
|
|
64
|
+
The callback receives:
|
|
65
|
+
(keyOrIndex, value, o, index)
|
|
66
|
+
|
|
67
|
+
### Parameters
|
|
68
|
+
|
|
69
|
+
* `o` **[Collection][8]\<T>** 
|
|
70
|
+
* `callback`  
|
|
71
|
+
* `context` **any?** Optional "this" binding for the callback
|
|
72
|
+
|
|
73
|
+
Returns **[Array][2]\<R>** Returns the resulted array
|
|
74
|
+
|
|
75
|
+
## reduce
|
|
76
|
+
|
|
77
|
+
[src/traversal.js:128-144][11]
|
|
78
|
+
|
|
79
|
+
Reduces a collection to a single value
|
|
80
|
+
|
|
81
|
+
The reducer receives:
|
|
82
|
+
(accumulator, value, index, source)
|
|
83
|
+
|
|
84
|
+
### Parameters
|
|
85
|
+
|
|
86
|
+
* `o` **[Collection][8]\<T>** 
|
|
87
|
+
* `callback`  
|
|
88
|
+
* `initialValue` **R?** la valeur initiale
|
|
89
|
+
|
|
90
|
+
Returns **R** Returns the accumulated value
|
|
91
|
+
|
|
92
|
+
## extend
|
|
93
|
+
|
|
94
|
+
[src/traversal.js:154-183][12]
|
|
95
|
+
|
|
96
|
+
Creates a shallow or deep copy of one or more objects or arrays
|
|
97
|
+
If the first argument is `true`, nested plain objects are merged recursively.
|
|
98
|
+
|
|
99
|
+
### Parameters
|
|
100
|
+
|
|
101
|
+
* `args` **...([boolean][13] | T)** 
|
|
102
|
+
|
|
103
|
+
Returns **T** A copy of the merged result
|
|
104
|
+
|
|
105
|
+
## clone
|
|
106
|
+
|
|
107
|
+
[src/traversal.js:192-208][14]
|
|
108
|
+
|
|
109
|
+
Creates a deep copy of an Object or Array
|
|
110
|
+
|
|
111
|
+
### Parameters
|
|
112
|
+
|
|
113
|
+
* `o` **T** 
|
|
114
|
+
|
|
115
|
+
Returns **T** The copy of o
|
|
116
|
+
|
|
117
|
+
## merge
|
|
118
|
+
|
|
119
|
+
[src/traversal.js:219-232][15]
|
|
120
|
+
|
|
121
|
+
Merge multiple collections into a single array
|
|
122
|
+
|
|
123
|
+
### Parameters
|
|
124
|
+
|
|
125
|
+
* `first` **[Collection][8]\<T>** 
|
|
126
|
+
* `second` **[Collection][8]\<T>?** (optional, default `[]`)
|
|
127
|
+
* `args` **...[Collection][8]\<T>** Remaining collections to merge
|
|
128
|
+
|
|
129
|
+
Returns **[Array][2]\<T>** the resulted merged array
|
|
130
|
+
|
|
131
|
+
[1]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/traversal.js#L5-L8 "Source code on GitHub"
|
|
132
|
+
|
|
133
|
+
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
134
|
+
|
|
135
|
+
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
136
|
+
|
|
137
|
+
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map
|
|
138
|
+
|
|
139
|
+
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
140
|
+
|
|
141
|
+
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
142
|
+
|
|
143
|
+
[7]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/traversal.js#L24-L70 "Source code on GitHub"
|
|
144
|
+
|
|
145
|
+
[8]: #collection
|
|
146
|
+
|
|
147
|
+
[9]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/traversal.js#L84-L86 "Source code on GitHub"
|
|
148
|
+
|
|
149
|
+
[10]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/traversal.js#L103-L114 "Source code on GitHub"
|
|
150
|
+
|
|
151
|
+
[11]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/traversal.js#L128-L144 "Source code on GitHub"
|
|
152
|
+
|
|
153
|
+
[12]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/traversal.js#L154-L183 "Source code on GitHub"
|
|
154
|
+
|
|
155
|
+
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
156
|
+
|
|
157
|
+
[14]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/traversal.js#L192-L208 "Source code on GitHub"
|
|
158
|
+
|
|
159
|
+
[15]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/traversal.js#L219-L232 "Source code on GitHub"
|
package/docs/utils.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# General Utilities
|
|
2
|
+
|
|
3
|
+
Description of the general utilities.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { utils } from '@webalternatif/js-core'
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
<!-- GENERATED:utils -->
|
|
15
|
+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
16
|
+
|
|
17
|
+
## flatten
|
|
18
|
+
|
|
19
|
+
[src/utils.js:53-59][1]
|
|
20
|
+
|
|
21
|
+
Recursively flattens an object or array into a single-level array.
|
|
22
|
+
|
|
23
|
+
### Parameters
|
|
24
|
+
|
|
25
|
+
* `o` **([Object][2] | [Array][3])** The object or array to flatten.
|
|
26
|
+
|
|
27
|
+
### Examples
|
|
28
|
+
|
|
29
|
+
Flatten an array of arrays
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
const result = flatten([1, [2, [3, 4]], 5]);
|
|
33
|
+
console.log(result);
|
|
34
|
+
// Output: [1, 2, 3, 4, 5]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Flatten an object
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
const result = flatten({ a: 1, b: [2, { c: 3 }], d: 4 });
|
|
41
|
+
console.log(result);
|
|
42
|
+
// Output: [1, 2, 3, 4]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Returns **[Array][3]** A flattened array containing all the values from the input object or array.
|
|
46
|
+
|
|
47
|
+
## debounce
|
|
48
|
+
|
|
49
|
+
[src/utils.js:105-129][4]
|
|
50
|
+
|
|
51
|
+
Creates a debounced function that delays the invocation of `func` until after `wait` milliseconds
|
|
52
|
+
have elapsed since the last time the debounced function was invoked.
|
|
53
|
+
|
|
54
|
+
### Parameters
|
|
55
|
+
|
|
56
|
+
* `func` **[Function][5]** The function to debounce.
|
|
57
|
+
* `wait` **[number][6]** The number of milliseconds to delay.
|
|
58
|
+
* `immediate` **[boolean][7]** If true, execute `func` on the leading edge instead of the trailing. (optional, default `false`)
|
|
59
|
+
* `context` **[Object][2]** The context to bind to `func`. (optional, default `null`)
|
|
60
|
+
|
|
61
|
+
Returns **[Function][5]** The debounced function.
|
|
62
|
+
|
|
63
|
+
[1]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/utils.js#L53-L59 "Source code on GitHub"
|
|
64
|
+
|
|
65
|
+
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
66
|
+
|
|
67
|
+
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
68
|
+
|
|
69
|
+
[4]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/utils.js#L105-L129 "Source code on GitHub"
|
|
70
|
+
|
|
71
|
+
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
|
|
72
|
+
|
|
73
|
+
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
74
|
+
|
|
75
|
+
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
package/package.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webalternatif/js-core",
|
|
3
|
-
"
|
|
3
|
+
"repository": {
|
|
4
|
+
"type": "git",
|
|
5
|
+
"url": "https://github.com/webalternatif/js-core.git"
|
|
6
|
+
},
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/webalternatif/js-core/issues"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/webalternatif/js-core#readme",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Ludovic Tarit",
|
|
13
|
+
"email": "ludovic.tarit@webalternatif.com"
|
|
14
|
+
},
|
|
15
|
+
"version": "1.6.3",
|
|
4
16
|
"type": "module",
|
|
5
17
|
"types": "types/index.d.ts",
|
|
6
18
|
"main": "dist/cjs/index.js",
|
|
@@ -33,6 +45,7 @@
|
|
|
33
45
|
"@babel/core": "^7.26.0",
|
|
34
46
|
"@babel/plugin-transform-export-namespace-from": "^7.27.1",
|
|
35
47
|
"@babel/preset-env": "^7.26.0",
|
|
48
|
+
"@eslint/js": "^9.39.2",
|
|
36
49
|
"@testing-library/dom": "^10.4.1",
|
|
37
50
|
"@testing-library/jest-dom": "^6.9.1",
|
|
38
51
|
"@types/jest": "^29.5.14",
|
|
@@ -40,16 +53,29 @@
|
|
|
40
53
|
"babel-loader": "^9.2.1",
|
|
41
54
|
"cross-env": "^10.1.0",
|
|
42
55
|
"documentation": "^14.0.3",
|
|
56
|
+
"eslint": "^9.39.2",
|
|
57
|
+
"eslint-config-prettier": "^10.1.8",
|
|
58
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
59
|
+
"globals": "^17.2.0",
|
|
60
|
+
"husky": "^9.1.7",
|
|
43
61
|
"jest": "^29.7.0",
|
|
44
62
|
"jest-environment-jsdom": "^29.7.0",
|
|
63
|
+
"lint-staged": "^16.2.7",
|
|
45
64
|
"nodemon": "^3.1.9",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
65
|
+
"prettier": "^3.8.1",
|
|
66
|
+
"typescript": "^5.7.2"
|
|
48
67
|
},
|
|
49
68
|
"files": [
|
|
50
69
|
"dist",
|
|
51
70
|
"types",
|
|
52
71
|
"README.md",
|
|
72
|
+
"docs",
|
|
53
73
|
"LICENSE"
|
|
54
|
-
]
|
|
74
|
+
],
|
|
75
|
+
"lint-staged": {
|
|
76
|
+
"*.js": [
|
|
77
|
+
"eslint --fix",
|
|
78
|
+
"prettier --write"
|
|
79
|
+
]
|
|
80
|
+
}
|
|
55
81
|
}
|
package/types/array.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export function inArray(value: any, arr: Object | any[], index?: number, strict?: boolean): boolean;
|
|
2
2
|
export function indexOf(arr: Array<any> | string, elt: any, from?: number): number;
|
|
3
3
|
export function lastIndexOf(arr: Array<any> | string, elt: any, from?: number): number;
|
|
4
|
-
export function compareArray(a1: any, a2: any):
|
|
4
|
+
export function compareArray(a1: any[], a2: any[]): boolean;
|
|
5
5
|
export function arrayUnique(arr: any): any;
|
|
6
6
|
export function array_unique(arr: any): any;
|
|
7
7
|
export function arrayDiff(array1: any, array2: any, strict?: boolean): any;
|
|
8
|
-
export function array_diff(
|
|
8
|
+
export function array_diff(array1: any, array2: any, strict?: boolean): any;
|
|
9
9
|
export function range(size: any, startAt?: number, step?: number): any[];
|
package/types/dom.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ declare namespace dom {
|
|
|
7
7
|
/**
|
|
8
8
|
* @param {Element} el
|
|
9
9
|
* @param {string} [selector]
|
|
10
|
-
* @returns {NodeList}
|
|
10
|
+
* @returns {NodeList|Element[]}
|
|
11
11
|
*/
|
|
12
|
-
export function children(el: Element, selector?: string): NodeList;
|
|
12
|
+
export function children(el: Element, selector?: string): NodeList | Element[];
|
|
13
13
|
/**
|
|
14
14
|
* @param {Element} el
|
|
15
15
|
* @param {string} [selector]
|
|
@@ -25,9 +25,9 @@ declare namespace dom {
|
|
|
25
25
|
/**
|
|
26
26
|
* @param {Element|Document|string} refEl
|
|
27
27
|
* @param {string|Element|NodeList|Array<Element>} [selector]
|
|
28
|
-
* @returns {
|
|
28
|
+
* @returns {Element[]}
|
|
29
29
|
*/
|
|
30
|
-
export function find(refEl: Element | Document | string, selector?: string | Element | NodeList | Array<Element>):
|
|
30
|
+
export function find(refEl: Element | Document | string, selector?: string | Element | NodeList | Array<Element>): Element[];
|
|
31
31
|
/**
|
|
32
32
|
* @param {Element|string} el
|
|
33
33
|
* @param {string} data
|
package/types/index.d.ts
CHANGED
|
@@ -60,11 +60,11 @@ declare const webf: {
|
|
|
60
60
|
inArray: (value: any, arr: Object | any[], index?: number, strict?: boolean) => boolean;
|
|
61
61
|
indexOf: (arr: Array<any> | string, elt: any, from?: number) => number;
|
|
62
62
|
lastIndexOf: (arr: Array<any> | string, elt: any, from?: number) => number;
|
|
63
|
-
compareArray: (a1: any, a2: any) =>
|
|
63
|
+
compareArray: (a1: any[], a2: any[]) => boolean;
|
|
64
64
|
arrayUnique: (arr: any) => any;
|
|
65
65
|
array_unique: (arr: any) => any;
|
|
66
66
|
arrayDiff: (array1: any, array2: any, strict?: boolean) => any;
|
|
67
|
-
array_diff: (
|
|
67
|
+
array_diff: (array1: any, array2: any, strict?: boolean) => any;
|
|
68
68
|
range: (size: any, startAt?: number, step?: number) => any[];
|
|
69
69
|
trim: (str: any, char?: string) => any;
|
|
70
70
|
ltrim: (str: any, char?: string) => any;
|