aneka 0.7.4 → 0.9.0
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/CHANGES.md +6 -0
- package/index.js +9 -0
- package/package.json +2 -1
- package/src/fill-object.js +17 -0
- package/src/generate-id.js +35 -0
- package/src/random-range.js +15 -0
- package/src/titleize.js +2 -1
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2025-12-19
|
|
4
|
+
|
|
5
|
+
- [0.9.0] Add ```fillObject()```
|
|
6
|
+
|
|
3
7
|
## 2025-12-13
|
|
4
8
|
|
|
5
9
|
- [0.6.0] Export functions as named export as well as default export
|
|
@@ -14,6 +18,8 @@
|
|
|
14
18
|
- [0.7.2] Bug fix in ```parseArgsArgv()```
|
|
15
19
|
- [0.7.3] Rewrite options in ```parseObject()```
|
|
16
20
|
- [0.7.4] Bug fix in ```parseObject()```
|
|
21
|
+
- [0.8.0] Add ```randomRange()```
|
|
22
|
+
- [0.8.0] Add ```generateId()```
|
|
17
23
|
|
|
18
24
|
## 2025-12-11
|
|
19
25
|
|
package/index.js
CHANGED
|
@@ -25,6 +25,9 @@ import parseArgsArgv from './src/parse-args-argv.js'
|
|
|
25
25
|
import parseEnv from './src/parse-env.js'
|
|
26
26
|
import parseDuration from './src/parse-duration.js'
|
|
27
27
|
import parseObject from './src/parse-object.js'
|
|
28
|
+
import randomRange from './src/random-range.js'
|
|
29
|
+
import generateId from './src/generate-id.js'
|
|
30
|
+
import fillObject from './src/fill-object.js'
|
|
28
31
|
|
|
29
32
|
export {
|
|
30
33
|
arrangeArray,
|
|
@@ -33,8 +36,10 @@ export {
|
|
|
33
36
|
delay,
|
|
34
37
|
extractText,
|
|
35
38
|
formatText,
|
|
39
|
+
fillObject,
|
|
36
40
|
filterDuplicate,
|
|
37
41
|
filterIndex,
|
|
42
|
+
generateId,
|
|
38
43
|
getIndex,
|
|
39
44
|
getKeyByValue,
|
|
40
45
|
includes,
|
|
@@ -49,6 +54,7 @@ export {
|
|
|
49
54
|
parseEnv,
|
|
50
55
|
parseObject,
|
|
51
56
|
pascalCase,
|
|
57
|
+
randomRange,
|
|
52
58
|
resolvePath,
|
|
53
59
|
round,
|
|
54
60
|
secToHms,
|
|
@@ -64,8 +70,10 @@ export default {
|
|
|
64
70
|
delay,
|
|
65
71
|
extractText,
|
|
66
72
|
formatText,
|
|
73
|
+
fillObject,
|
|
67
74
|
filterDuplicate,
|
|
68
75
|
filterIndex,
|
|
76
|
+
generateId,
|
|
69
77
|
getIndex,
|
|
70
78
|
getKeyByValue,
|
|
71
79
|
includes,
|
|
@@ -80,6 +88,7 @@ export default {
|
|
|
80
88
|
parseEnv,
|
|
81
89
|
parseObject,
|
|
82
90
|
pascalCase,
|
|
91
|
+
randomRange,
|
|
83
92
|
resolvePath,
|
|
84
93
|
round,
|
|
85
94
|
secToHms,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aneka",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Some usefull function helper for daily use",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"flat": "^6.0.1",
|
|
29
29
|
"lodash-es": "^4.17.21",
|
|
30
30
|
"ms": "^2.1.3",
|
|
31
|
+
"nanoid": "^5.1.6",
|
|
31
32
|
"sprintf-js": "^1.1.3",
|
|
32
33
|
"yargs": "^18.0.0"
|
|
33
34
|
},
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fill object with keys. ```defValue``` is used if the corresponding key doesn't have value
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} obj - Object to fill
|
|
5
|
+
* @param {string[]} keys - Array of keys
|
|
6
|
+
* @param {any} defValue - Default value
|
|
7
|
+
* @returns {Object}
|
|
8
|
+
*/
|
|
9
|
+
function fillObject (obj = {}, keys = [], defValue) {
|
|
10
|
+
const newObj = {}
|
|
11
|
+
for (const key of keys) {
|
|
12
|
+
newObj[key] = obj[key] ?? defValue
|
|
13
|
+
}
|
|
14
|
+
return newObj
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default fillObject
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { customAlphabet } from 'nanoid'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate unique random characters that can be used as ID. Use {@link https://github.com/ai/nanoid|nanoid} under the hood
|
|
5
|
+
*
|
|
6
|
+
* @method
|
|
7
|
+
* @memberof module:Lib
|
|
8
|
+
* @param {(boolean|string|Object)} [options={}] - Options. If set to ```true``` or ```alpha```, it will generate alphaphet only characters. If set to ```int```, it will generate integer only characters. Otherwise:
|
|
9
|
+
* @param {string} [options.pattern] - Character pattern to use. Defaults to all available alphanumeric characters
|
|
10
|
+
* @param {number} [options.length=13] - Length of resulted characters
|
|
11
|
+
* @param {string} [options.case] - If set to ```lower``` to use lower cased pattern only. For upper cased pattern, set it to ```upper```
|
|
12
|
+
* @param {boolean} [options.returnInstance] - Set to ```true``` to return {@link https://github.com/ai/nanoid|nanoid} instance instead of string
|
|
13
|
+
* @returns {(string|Object)} Return string or instance of {@link https://github.com/ai/nanoid|nanoid}
|
|
14
|
+
*/
|
|
15
|
+
function generateId (options = {}) {
|
|
16
|
+
let type
|
|
17
|
+
if (options === true) options = 'alpha'
|
|
18
|
+
if (options === 'int') {
|
|
19
|
+
type = options
|
|
20
|
+
options = { pattern: '0123456789', length: 15 }
|
|
21
|
+
} else if (options === 'alpha') {
|
|
22
|
+
type = options
|
|
23
|
+
options = { pattern: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', length: 15 }
|
|
24
|
+
}
|
|
25
|
+
let { pattern, length = 13, returnInstance } = options
|
|
26
|
+
pattern = pattern ?? 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
|
27
|
+
if (options.case === 'lower') pattern = pattern.toLowerCase()
|
|
28
|
+
else if (options.case === 'upper') pattern = pattern.toUpperCase()
|
|
29
|
+
const nid = customAlphabet(pattern, length)
|
|
30
|
+
if (returnInstance) return nid
|
|
31
|
+
const value = nid()
|
|
32
|
+
return type === 'int' ? parseInt(value) : value
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default generateId
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate random value
|
|
3
|
+
*
|
|
4
|
+
* @param {number} min - Minimum value (inclusive)
|
|
5
|
+
* @param {number} max - Maximum value (inclusive)
|
|
6
|
+
* @param {boolean} alpha - Set ```true``` to return alphanumeric characters
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
function randomRange(min = 0, max = 65439, alpha = false) {
|
|
10
|
+
const num = Math.floor(Math.random() * (max - min + 1) + min)
|
|
11
|
+
if (!alpha) return num
|
|
12
|
+
return String.fromCharCode(96 + num)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default randomRange
|
package/src/titleize.js
CHANGED
|
@@ -4,12 +4,13 @@ import words from 'lodash-es/words.js'
|
|
|
4
4
|
import uniq from 'lodash-es/uniq.js'
|
|
5
5
|
import concat from 'lodash-es/concat.js'
|
|
6
6
|
import upperFirst from 'lodash-es/upperFirst.js'
|
|
7
|
+
import generateId from './generate-id.js'
|
|
7
8
|
|
|
8
9
|
function titleize (text = '', { ignores = [], replacement = {} } = {}) {
|
|
9
10
|
const defIgnores = ['or', 'and', 'of', 'with']
|
|
10
11
|
const replacer = {}
|
|
11
12
|
forOwn(replacement, (v, k) => {
|
|
12
|
-
const id =
|
|
13
|
+
const id = generateId()
|
|
13
14
|
replacer[id] = k
|
|
14
15
|
text = text.replace(k, ` ${id} `)
|
|
15
16
|
})
|