@guillaume-docquier/tools-ts 8.4.3 → 8.5.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/README.md CHANGED
@@ -106,13 +106,14 @@ consistent context, scopes, formatting, and redaction.
106
106
  Use these small utilities to keep common asynchronous and callback patterns
107
107
  consistent.
108
108
 
109
- | Export | What it is | Use it when |
110
- | ----------------- | ------------------------------------------ | ------------------------------------------------------------------------------- |
111
- | `setTimeoutAsync` | Promise-based timeout helper. | You want `await`-friendly delays that work in browser and Node environments. |
112
- | `debounce` | Creates a debounced callback. | A repeated event should trigger work only after calls have settled for a delay. |
113
- | `noop` | Synchronous no-op function. | You need a safe default callback that intentionally does nothing. |
114
- | `asyncNoop` | Asynchronous no-op function. | You need a safe default async callback or hook that resolves immediately. |
115
- | `omit` | Runtime equivalent of `Omit<TType, TKey>`. | You need to remove keys from an object. |
109
+ | Export | What it is | Use it when |
110
+ | ----------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------- |
111
+ | `setTimeoutAsync` | Promise-based timeout helper. | You want `await`-friendly delays that work in browser and Node environments. |
112
+ | `debounce` | Creates a debounced callback. | A repeated event should trigger work only after calls have settled for a delay. |
113
+ | `noop` | Synchronous no-op function. | You need a safe default callback that intentionally does nothing. |
114
+ | `asyncNoop` | Asynchronous no-op function. | You need a safe default async callback or hook that resolves immediately. |
115
+ | `omit` | Runtime equivalent of `Omit<TType, TKey>`. | You need to remove keys from an object. |
116
+ | `indexBy` | Indexes objects by a selected string-valued property. | You need to look up objects by a string key. |
116
117
 
117
118
  ### Profiling
118
119
 
@@ -38,3 +38,4 @@ export { Point2D, type XY } from "./measurements/Point2D.js";
38
38
  export { Point3D, type XYZ } from "./measurements/Point3D.js";
39
39
  export { Timer } from "./Timer.js";
40
40
  export { type Branded, branded, type Unbranded, type UnbrandedProperties, type DeepUnbranded } from "./Brand.js";
41
+ export { indexBy } from "./indexBy.js";
@@ -32,4 +32,5 @@ export { Point2D } from "./measurements/Point2D.js";
32
32
  export { Point3D } from "./measurements/Point3D.js";
33
33
  export { Timer } from "./Timer.js";
34
34
  export { branded } from "./Brand.js";
35
+ export { indexBy } from "./indexBy.js";
35
36
  //# sourceMappingURL=entry.tools-ts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"entry.tools-ts.js","sourceRoot":"","sources":["../src/entry.tools-ts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAI5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAA8B,MAAM,aAAa,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAA;AAC5E,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,OAAO,EAAW,MAAM,2BAA2B,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAY,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAgB,OAAO,EAAgE,MAAM,YAAY,CAAA;AAChH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Indexes objects by a string-valued property.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * const users = [{ id: "alice", age: 12 }, { id: "bob", age: 34 }]
7
+ * const usersById = indexBy("id", users)
8
+ * // {
9
+ * // alice: { id: "alice", age: 12 },
10
+ * // bob: { id: "bob", age: 34 },
11
+ * // }
12
+ * ```
13
+ */
14
+ export declare function indexBy<TProperty extends string, TElement extends Record<TProperty, string>>(property: TProperty, arrayOfObjects: readonly TElement[]): Record<TElement[TProperty], TElement>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Indexes objects by a string-valued property.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * const users = [{ id: "alice", age: 12 }, { id: "bob", age: 34 }]
7
+ * const usersById = indexBy("id", users)
8
+ * // {
9
+ * // alice: { id: "alice", age: 12 },
10
+ * // bob: { id: "bob", age: 34 },
11
+ * // }
12
+ * ```
13
+ */
14
+ export function indexBy(property, arrayOfObjects) {
15
+ // oxlint-disable-next-line typescript/consistent-type-assertions typescript/no-unsafe-type-assertion -- Strange TS quirk?
16
+ const indexed = {};
17
+ for (const obj of arrayOfObjects) {
18
+ indexed[obj[property]] = obj;
19
+ }
20
+ return indexed;
21
+ }
22
+ //# sourceMappingURL=indexBy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexBy.js","sourceRoot":"","sources":["../src/indexBy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,OAAO,CACrB,QAAmB,EACnB,cAAmC;IAEnC,0HAA0H;IAC1H,MAAM,OAAO,GAAG,EAA2C,CAAA;IAC3D,KAAK,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,GAAG,CAAA;IAC9B,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guillaume-docquier/tools-ts",
3
- "version": "8.4.3",
3
+ "version": "8.5.0",
4
4
  "description": "My personal collection of typescript tools",
5
5
  "homepage": "https://github.com/Guillaume-Docquier/tools-ts",
6
6
  "license": "MIT",