@jackens/nnn 2024.2.10 → 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 +8 -8
- package/h.js +32 -33
- 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 +7 -7
- package/jcss.js +13 -13
- package/jsOnParse.d.ts +2 -2
- package/jsOnParse.js +3 -4
- package/locale.d.ts +2 -2
- package/locale.js +10 -10
- 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 +170 -136
- 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/locale.js
CHANGED
|
@@ -4,7 +4,7 @@ import { is } from './is.js'
|
|
|
4
4
|
* Language translations helper.
|
|
5
5
|
*/
|
|
6
6
|
export const locale = (
|
|
7
|
-
/** @type {Partial<Record<
|
|
7
|
+
/** @type {Partial<Record<PropertyKey, Partial<Record<PropertyKey, string>>>>} */ map,
|
|
8
8
|
/** @type {string} */ defaultVersion
|
|
9
9
|
) => (
|
|
10
10
|
/** @type {string} */ text,
|
|
@@ -17,23 +17,23 @@ export const locale = (
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export const tests = {
|
|
20
|
-
locale: () => {
|
|
20
|
+
locale: (/** @type {import('bun:test').Expect} */ expect) => {
|
|
21
21
|
const _ = locale({
|
|
22
22
|
default: { Password: 'Hasło' },
|
|
23
23
|
button: { Login: 'Zaloguj' }
|
|
24
24
|
}, 'default')
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
expect(_('Login')).toEqual('Login')
|
|
27
|
+
expect(_('Password')).toEqual('Hasło')
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
expect(_('Undefined text')).toEqual('Undefined text')
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
expect(_('Login', 'button')).toEqual('Zaloguj')
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
expect(_('Password', 'undefined_version')).toEqual('Hasło')
|
|
34
|
+
expect(_('Undefined text', 'undefined_version')).toEqual('Undefined text')
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
expect(_('toString')).toEqual('toString')
|
|
37
|
+
expect(_('toString', 'undefined_version')).toEqual('toString')
|
|
38
38
|
}
|
|
39
39
|
}
|
package/nanolightJs.d.ts
CHANGED
package/nanolightJs.js
CHANGED
|
@@ -20,10 +20,10 @@ export const nanolightJs = nanolight.bind(0,
|
|
|
20
20
|
)
|
|
21
21
|
|
|
22
22
|
export const tests = {
|
|
23
|
-
nanolightJs: () => {
|
|
23
|
+
nanolightJs: (/** @type {import('bun:test').Expect} */ expect) => {
|
|
24
24
|
const codeJs = 'const answerToLifeTheUniverseAndEverything = 42'
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
expect(h('pre', ['code', ...nanolightJs(codeJs)]).outerHTML).toEqual(
|
|
27
27
|
'<pre><code><span class="keyword">const</span> <span class="literal">answerToLifeTheUniverseAndEverything</span> <span class="operator">=</span> <span class="number">42</span></code></pre>')
|
|
28
28
|
}
|
|
29
29
|
}
|
package/nnn.d.ts
CHANGED
|
@@ -11,9 +11,11 @@ import { jsOnParse } from './jsOnParse.js';
|
|
|
11
11
|
import { locale } from './locale.js';
|
|
12
12
|
import { nanolight } from './nanolight.js';
|
|
13
13
|
import { nanolightJs } from './nanolightJs.js';
|
|
14
|
+
import { omit } from './pick.js';
|
|
15
|
+
import { pick } from './pick.js';
|
|
14
16
|
import { plUral } from './plUral.js';
|
|
15
17
|
import { pro } from './pro.js';
|
|
16
18
|
import { refsInfo } from './refsInfo.js';
|
|
17
19
|
import { s } from './h.js';
|
|
18
20
|
import { uuid1 } from './uuid1.js';
|
|
19
|
-
export { chartable, eq, escape, escapeValues, fixTypography, h, has, is, jcss, jsOnParse, locale, nanolight, nanolightJs, plUral, pro, refsInfo, s, uuid1 };
|
|
21
|
+
export { chartable, eq, escape, escapeValues, fixTypography, h, has, is, jcss, jsOnParse, locale, nanolight, nanolightJs, omit, pick, plUral, pro, refsInfo, s, uuid1 };
|
package/nnn.js
CHANGED
|
@@ -10,6 +10,7 @@ import { jsOnParse } from './jsOnParse.js'
|
|
|
10
10
|
import { locale } from './locale.js'
|
|
11
11
|
import { nanolight } from './nanolight.js'
|
|
12
12
|
import { nanolightJs } from './nanolightJs.js'
|
|
13
|
+
import { omit, pick } from './pick.js'
|
|
13
14
|
import { plUral } from './plUral.js'
|
|
14
15
|
import { pro } from './pro.js'
|
|
15
16
|
import { refsInfo } from './refsInfo.js'
|
|
@@ -18,7 +19,8 @@ import { uuid1 } from './uuid1.js'
|
|
|
18
19
|
export {
|
|
19
20
|
chartable,
|
|
20
21
|
eq,
|
|
21
|
-
escape,
|
|
22
|
+
escape,
|
|
23
|
+
escapeValues,
|
|
22
24
|
fixTypography,
|
|
23
25
|
h,
|
|
24
26
|
has,
|
|
@@ -28,6 +30,8 @@ export {
|
|
|
28
30
|
locale,
|
|
29
31
|
nanolight,
|
|
30
32
|
nanolightJs,
|
|
33
|
+
omit,
|
|
34
|
+
pick,
|
|
31
35
|
plUral,
|
|
32
36
|
pro,
|
|
33
37
|
refsInfo,
|
package/package.json
CHANGED
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
|
}
|