@dxos/util 0.5.0 → 0.5.1-main.0ec204c

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.
@@ -1 +1 @@
1
- {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../../src/range.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK,MAAO,MAAM,aAAgC,CAAC;AAEhE,eAAO,MAAM,WAAW,SAAU,MAAM,MAAM,MAAM,aAA0C,CAAC"}
1
+ {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../../src/range.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK,EAAE;IAClB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtB,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;CAI7C,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE;IACxB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACrC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;CAG5D,CAAC;AAEF,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/util",
3
- "version": "0.5.0",
3
+ "version": "0.5.1-main.0ec204c",
4
4
  "description": "Temporary bucket for misc functions, which should graduate into separate packages.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -16,13 +16,13 @@
16
16
  "src"
17
17
  ],
18
18
  "dependencies": {
19
- "@dxos/debug": "0.5.0",
20
- "@dxos/keys": "0.5.0",
21
- "@dxos/node-std": "0.5.0",
22
- "@dxos/invariant": "0.5.0"
19
+ "@dxos/debug": "0.5.1-main.0ec204c",
20
+ "@dxos/keys": "0.5.1-main.0ec204c",
21
+ "@dxos/invariant": "0.5.1-main.0ec204c",
22
+ "@dxos/node-std": "0.5.1-main.0ec204c"
23
23
  },
24
24
  "devDependencies": {
25
- "@dxos/crypto": "0.5.0"
25
+ "@dxos/crypto": "0.5.1-main.0ec204c"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
package/src/complex.ts CHANGED
@@ -209,6 +209,13 @@ export class ComplexMap<K, V> implements Map<K, V> {
209
209
  return this._values.values();
210
210
  }
211
211
 
212
+ mapValues<R>(mapper: (v: V, k: K) => R): ComplexMap<K, R> {
213
+ return new ComplexMap(
214
+ this._keyProjection,
215
+ [...this.entries()].map(([key, value]) => [key, mapper(value, key)]),
216
+ );
217
+ }
218
+
212
219
  get [Symbol.toStringTag](): string {
213
220
  return 'ComplexMap';
214
221
  }
package/src/range.ts CHANGED
@@ -2,6 +2,19 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- export const range = (n: number) => Array.from(Array(n).keys());
5
+ export const range: {
6
+ (n: number): number[];
7
+ <T>(n: number, mapper: RangeMapper<T>): T[];
8
+ } = <T>(n: number, mapper?: RangeMapper<T>) => {
9
+ const range = Array.from(Array(n).keys());
10
+ return mapper == null ? range : range.map(mapper);
11
+ };
6
12
 
7
- export const rangeFromTo = (from: number, to: number) => range(to - from).map((i) => i + from);
13
+ export const rangeFromTo: {
14
+ (from: number, to: number): number[];
15
+ <T>(from: number, to: number, mapper: RangeMapper<T>): T[];
16
+ } = <T = number>(from: number, to: number, mapper?: RangeMapper<T>) => {
17
+ return mapper == null ? range(to - from, (i) => i + from) : range(to - from, (i) => mapper(i + from));
18
+ };
19
+
20
+ type RangeMapper<T> = (n: number) => T;