@dxos/util 0.8.4-main.a4bbb77 → 0.8.4-main.ae835ea

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/util",
3
- "version": "0.8.4-main.a4bbb77",
3
+ "version": "0.8.4-main.ae835ea",
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",
@@ -29,15 +29,15 @@
29
29
  "dependencies": {
30
30
  "lodash.get": "^4.4.2",
31
31
  "lodash.set": "^4.3.2",
32
- "@dxos/invariant": "0.8.4-main.a4bbb77",
33
- "@dxos/debug": "0.8.4-main.a4bbb77",
34
- "@dxos/keys": "0.8.4-main.a4bbb77",
35
- "@dxos/node-std": "0.8.4-main.a4bbb77"
32
+ "@dxos/debug": "0.8.4-main.ae835ea",
33
+ "@dxos/invariant": "0.8.4-main.ae835ea",
34
+ "@dxos/keys": "0.8.4-main.ae835ea",
35
+ "@dxos/node-std": "0.8.4-main.ae835ea"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/lodash.get": "^4.4.9",
39
39
  "@types/lodash.set": "^4.3.9",
40
- "@dxos/crypto": "0.8.4-main.a4bbb77"
40
+ "@dxos/crypto": "0.8.4-main.ae835ea"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"
package/src/string.ts CHANGED
@@ -41,3 +41,10 @@ export function trim(strings: TemplateStringsArray, ...values: any[]) {
41
41
  // Remove that indent from all lines.
42
42
  return lines.map((l) => l.slice(minIndent)).join('\n');
43
43
  }
44
+
45
+ // From https://stackoverflow.com/a/67243723/2804332
46
+ /**
47
+ * Converts a string to kebab case.
48
+ */
49
+ export const kebabize = (str: string) =>
50
+ str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
@@ -194,17 +194,18 @@ export const keyToFallback = (key: PublicKey) => hexToFallback(key.toHex());
194
194
  // TODO(wittjosiah): Support non-hex strings (e.g. DIDs, UUIDs, etc.)
195
195
  export const hexToFallback = (hex: string) => toFallback(parseInt(hex, 16));
196
196
 
197
+ // TODO(burdon): Rename?
197
198
  export const toFallback = (hash: number): FallbackValue => {
198
- // Calculate total possible combinations of emoji and hue pairs
199
+ // Calculate total possible combinations of emoji and hue pairs.
199
200
  const totalCombinations = idEmoji.length * idHue.length;
200
201
 
201
- // Get a deterministic index within the range of all possible combinations
202
+ // Get a deterministic index within the range of all possible combinations.
202
203
  const combinationIndex = hash % totalCombinations;
203
204
 
204
- // Calculate which emoji to use based on the combination index
205
+ // Calculate which emoji to use based on the combination index.
205
206
  const emojiIndex = Math.floor(combinationIndex / idHue.length);
206
207
 
207
- // Calculate which hue to use based on the combination index
208
+ // Calculate which hue to use based on the combination index.
208
209
  const hueIndex = combinationIndex % idHue.length;
209
210
 
210
211
  return {
package/src/types.ts CHANGED
@@ -48,7 +48,6 @@ export type Falsy = false | 0 | '' | null | undefined;
48
48
  * NOTE: To filter by type:
49
49
  * items.filter((item: any): item is RangeSet<Decoration> => item instanceof RangeSet)
50
50
  */
51
- // TODO(burdon): Replace with Predicate.isTruthy?
52
51
  export const isTruthy = <T>(value: T): value is Exclude<T, Falsy> => !!value;
53
52
  export const isNonNullable = <T>(value: T | null | undefined): value is T => value != null;
54
53