@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/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
@@ -4,5 +4,5 @@
4
4
  export function plUral(singular: string, plural2: string, plural5: string, value: number): string;
5
5
 
6
6
  export namespace tests {
7
- function plUral(): void;
7
+ function plUral(expect: import("bun:test").Expect): void;
8
8
  }
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
- console.assert(auto(0) === 'aut')
27
- console.assert(auto(1) === 'auto')
28
- console.assert(auto(17) === 'aut')
29
- console.assert(auto(42) === 'auta')
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
- console.assert(car(0) === 'cars')
35
- console.assert(car(1) === 'car')
36
- console.assert(car(17) === 'cars')
37
- console.assert(car(42) === 'cars')
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
@@ -4,5 +4,5 @@
4
4
  export function pro(ref: any): any;
5
5
 
6
6
  export namespace tests {
7
- function pro(): void;
7
+ function pro(expect: import("bun:test").Expect): void;
8
8
  }
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
- console.assert(eq(ref, { one: { two: { 3: { 4: 1234 } } } }))
17
+ expect(ref).toEqual({ one: { two: { 3: { 4: 1234 } } } })
20
18
 
21
19
  pro(ref).one.two.tree = 123
22
20
 
23
- console.assert(eq(ref, { one: { two: { 3: { 4: 1234 }, tree: 123 } } }))
21
+ expect(ref).toEqual({ one: { two: { 3: { 4: 1234 }, tree: 123 } } })
24
22
 
25
23
  pro(ref).one.two = undefined
26
24
 
27
- console.assert(eq(ref, { one: { two: undefined } }))
25
+ expect(ref).toEqual({ one: { two: undefined } })
28
26
 
29
27
  delete pro(ref).one.two
30
28
 
31
- console.assert(eq(ref, { one: {} }))
29
+ expect(ref).toEqual({ one: {} })
32
30
 
33
31
  pro(ref).one.two.three.four
34
32
 
35
- console.assert(eq(ref, { one: { two: { three: { four: {} } } } }))
33
+ expect(ref).toEqual({ one: { two: { three: { four: {} } } } })
36
34
 
37
35
  pro(ref).one.two.three.four = 1234
38
36
 
39
- console.assert(eq(ref, { one: { two: { three: { four: 1234 } } } }))
37
+ expect(ref).toEqual({ one: { two: { three: { four: 1234 } } } })
40
38
  }
41
39
  }