@jackens/nnn 2024.2.11 → 2024.2.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/eq.d.ts +1 -1
- package/eq.js +26 -26
- package/escape.d.ts +1 -1
- package/escape.js +2 -2
- package/fixTypography.d.ts +1 -1
- package/fixTypography.js +2 -2
- package/h.d.ts +5 -5
- package/h.js +29 -30
- package/has.d.ts +2 -2
- package/has.js +13 -13
- package/is.d.ts +2 -2
- package/is.js +27 -27
- package/jcss.d.ts +6 -6
- package/jcss.js +12 -12
- package/jsOnParse.d.ts +1 -1
- package/jsOnParse.js +2 -3
- package/locale.d.ts +1 -1
- package/locale.js +9 -9
- package/nanolightJs.d.ts +1 -1
- package/nanolightJs.js +2 -2
- package/nnn.d.ts +3 -1
- package/nnn.js +5 -1
- package/package.json +1 -1
- package/pick.d.ts +14 -0
- package/pick.js +57 -0
- package/plUral.d.ts +1 -1
- package/plUral.js +9 -9
- package/pro.d.ts +1 -1
- package/pro.js +7 -9
- package/readme.md +164 -130
- package/refsInfo.d.ts +2 -2
- package/refsInfo.js +4 -4
- package/uuid1.d.ts +3 -3
- package/uuid1.js +13 -13
- package/tests.d.ts +0 -30
- package/tests.js +0 -35
package/pick.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A helper that implements TypeScript’s `Omit` utility type.
|
|
3
|
+
*/
|
|
4
|
+
export const omit: <T extends Partial<Record<PropertyKey, any>>, K extends (keyof T)[]>(obj: T, keys: K) => Omit<T, K[number]>;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A helper that implements TypeScript’s `Pick` utility type.
|
|
8
|
+
*/
|
|
9
|
+
export const pick: <T extends Partial<Record<PropertyKey, any>>, K extends (keyof T)[]>(obj: T, keys: K) => Pick<T, K[number]>;
|
|
10
|
+
|
|
11
|
+
export namespace tests {
|
|
12
|
+
function pick(expect: import("bun:test").Expect): void;
|
|
13
|
+
function omit(expect: import("bun:test").Expect): void;
|
|
14
|
+
}
|
package/pick.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A helper that implements TypeScript’s `Pick` utility type.
|
|
3
|
+
*
|
|
4
|
+
* @type {<T extends Partial<Record<PropertyKey, any>>, K extends (keyof T)[]>(obj: T, keys: K) => Pick<T, K[number]>}
|
|
5
|
+
* @template {Partial<Record<PropertyKey, any>>} T
|
|
6
|
+
* @template {keyof T} K
|
|
7
|
+
*/
|
|
8
|
+
export const pick = (/** @type {T} */ obj, /** @type {K[]} */ keys) => {
|
|
9
|
+
const result = {}
|
|
10
|
+
|
|
11
|
+
for (const key in obj) {
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
if (keys.includes(key)) {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
result[key] = obj[key]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
return result
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A helper that implements TypeScript’s `Omit` utility type.
|
|
25
|
+
*
|
|
26
|
+
* @type {<T extends Partial<Record<PropertyKey, any>>, K extends (keyof T)[]>(obj: T, keys: K) => Omit<T, K[number]>}
|
|
27
|
+
* @template {Partial<Record<PropertyKey, any>>} T
|
|
28
|
+
* @template {keyof T} K
|
|
29
|
+
*/
|
|
30
|
+
export const omit = (/** @type {T} */ obj, /** @type {K[]} */ keys) => {
|
|
31
|
+
const result = {}
|
|
32
|
+
|
|
33
|
+
for (const key in obj) {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
if (!keys.includes(key)) {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
result[key] = obj[key]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
return result
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const tests = {
|
|
46
|
+
pick: (/** @type {import('bun:test').Expect} */ expect) => {
|
|
47
|
+
const obj = { a: 42, b: '42', c: 17 }
|
|
48
|
+
|
|
49
|
+
expect(pick(obj, ['a', 'b'])).toEqual({ a: 42, b: '42' })
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
omit: (/** @type {import('bun:test').Expect} */ expect) => {
|
|
53
|
+
const obj = { a: 42, b: '42', c: 17 }
|
|
54
|
+
|
|
55
|
+
expect(omit(obj, ['c'])).toEqual({ a: 42, b: '42' })
|
|
56
|
+
}
|
|
57
|
+
}
|
package/plUral.d.ts
CHANGED
package/plUral.js
CHANGED
|
@@ -19,21 +19,21 @@ export const plUral = (
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const tests = {
|
|
22
|
-
plUral: () => {
|
|
22
|
+
plUral: (/** @type {import('bun:test').Expect} */ expect) => {
|
|
23
23
|
// @ts-ignore
|
|
24
24
|
const auto = plUral.bind(null, 'auto', 'auta', 'aut')
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
expect(auto(0)).toEqual('aut')
|
|
27
|
+
expect(auto(1)).toEqual('auto')
|
|
28
|
+
expect(auto(17)).toEqual('aut')
|
|
29
|
+
expect(auto(42)).toEqual('auta')
|
|
30
30
|
|
|
31
31
|
// @ts-ignore
|
|
32
32
|
const car = plUral.bind(null, 'car', 'cars', 'cars')
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
expect(car(0)).toEqual('cars')
|
|
35
|
+
expect(car(1)).toEqual('car')
|
|
36
|
+
expect(car(17)).toEqual('cars')
|
|
37
|
+
expect(car(42)).toEqual('cars')
|
|
38
38
|
}
|
|
39
39
|
}
|
package/pro.d.ts
CHANGED
package/pro.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { eq } from './eq.js'
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* A helper that protects calls to nested properties by a `Proxy` that initializes non-existent values with an empty object.
|
|
5
3
|
*/
|
|
@@ -11,31 +9,31 @@ export const pro = (/** @type {any} */ ref) => new Proxy(ref, {
|
|
|
11
9
|
})
|
|
12
10
|
|
|
13
11
|
export const tests = {
|
|
14
|
-
pro: () => {
|
|
12
|
+
pro: (/** @type {import('bun:test').Expect} */ expect) => {
|
|
15
13
|
const ref = {}
|
|
16
14
|
|
|
17
15
|
pro(ref).one.two[3][4] = 1234
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
expect(ref).toEqual({ one: { two: { 3: { 4: 1234 } } } })
|
|
20
18
|
|
|
21
19
|
pro(ref).one.two.tree = 123
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
expect(ref).toEqual({ one: { two: { 3: { 4: 1234 }, tree: 123 } } })
|
|
24
22
|
|
|
25
23
|
pro(ref).one.two = undefined
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
expect(ref).toEqual({ one: { two: undefined } })
|
|
28
26
|
|
|
29
27
|
delete pro(ref).one.two
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
expect(ref).toEqual({ one: {} })
|
|
32
30
|
|
|
33
31
|
pro(ref).one.two.three.four
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
expect(ref).toEqual({ one: { two: { three: { four: {} } } } })
|
|
36
34
|
|
|
37
35
|
pro(ref).one.two.three.four = 1234
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
expect(ref).toEqual({ one: { two: { three: { four: 1234 } } } })
|
|
40
38
|
}
|
|
41
39
|
}
|