@dxos/util 0.8.4-main.e098934 → 0.8.4-main.ead640a
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/dist/lib/browser/index.mjs +4 -30
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +4 -30
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/di-key.d.ts +3 -3
- package/dist/types/src/di-key.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/string.d.ts +4 -0
- package/dist/types/src/string.d.ts.map +1 -1
- package/dist/types/src/to-fallback.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +1 -2
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/index.ts +0 -1
- package/src/string.ts +7 -0
- package/src/to-fallback.ts +5 -4
- package/src/types.ts +1 -2
- package/dist/types/src/first-two-chars.d.ts +0 -9
- package/dist/types/src/first-two-chars.d.ts.map +0 -1
- package/src/first-two-chars.ts +0 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/util",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.ead640a",
|
|
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/debug": "0.8.4-main.
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
32
|
+
"@dxos/debug": "0.8.4-main.ead640a",
|
|
33
|
+
"@dxos/keys": "0.8.4-main.ead640a",
|
|
34
|
+
"@dxos/invariant": "0.8.4-main.ead640a",
|
|
35
|
+
"@dxos/node-std": "0.8.4-main.ead640a"
|
|
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.
|
|
40
|
+
"@dxos/crypto": "0.8.4-main.ead640a"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
package/src/index.ts
CHANGED
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());
|
package/src/to-fallback.ts
CHANGED
|
@@ -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
|
@@ -47,9 +47,8 @@ export type Falsy = false | 0 | '' | null | undefined;
|
|
|
47
47
|
* Use with filter chaining instead of filter(Boolean) to preserve type.
|
|
48
48
|
* NOTE: To filter by type:
|
|
49
49
|
* items.filter((item: any): item is RangeSet<Decoration> => item instanceof RangeSet)
|
|
50
|
-
* @deprecated Replace with Predicate.isTruthy
|
|
51
50
|
*/
|
|
52
|
-
export const
|
|
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
|
|
|
55
54
|
// TODO(burdon): Replace use of setTimeout everywhere?
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the first two renderable characters from a string that are separated by non-word characters.
|
|
3
|
-
* Handles Unicode characters correctly.
|
|
4
|
-
*
|
|
5
|
-
* @param {string} label - The input string to process
|
|
6
|
-
* @returns {[string, string]} Array containing the two characters, or empty strings if not found
|
|
7
|
-
*/
|
|
8
|
-
export declare const getFirstTwoRenderableChars: (label: string) => string[];
|
|
9
|
-
//# sourceMappingURL=first-two-chars.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"first-two-chars.d.ts","sourceRoot":"","sources":["../../../src/first-two-chars.ts"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GAAI,OAAO,MAAM,aA2BvD,CAAC"}
|
package/src/first-two-chars.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// Regular expression to match renderable characters
|
|
6
|
-
// Excludes control characters, combining marks, and other non-renderable characters. Also excludes punctuation.
|
|
7
|
-
const renderableCharRegex =
|
|
8
|
-
/^(?![\p{Control}\p{Mark}\p{Separator}\p{Surrogate}\p{Unassigned}\p{P}])[\p{L}\p{N}\p{S}\p{Emoji}]$/u;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Returns the first two renderable characters from a string that are separated by non-word characters.
|
|
12
|
-
* Handles Unicode characters correctly.
|
|
13
|
-
*
|
|
14
|
-
* @param {string} label - The input string to process
|
|
15
|
-
* @returns {[string, string]} Array containing the two characters, or empty strings if not found
|
|
16
|
-
*/
|
|
17
|
-
export const getFirstTwoRenderableChars = (label: string) => {
|
|
18
|
-
// Convert string to array of Unicode characters
|
|
19
|
-
const characters = Array.from(label);
|
|
20
|
-
|
|
21
|
-
// Keep track of found renderable characters
|
|
22
|
-
const result = ['', ''];
|
|
23
|
-
let foundFirst = false;
|
|
24
|
-
|
|
25
|
-
for (let i = 0; i < characters.length; i++) {
|
|
26
|
-
const char = characters[i];
|
|
27
|
-
|
|
28
|
-
if (renderableCharRegex.test(char)) {
|
|
29
|
-
if (!foundFirst) {
|
|
30
|
-
result[0] = char;
|
|
31
|
-
foundFirst = true;
|
|
32
|
-
} else {
|
|
33
|
-
// Check if there's at least one non-word character between the first and current char
|
|
34
|
-
const textBetween = characters.slice(result[0].length, i).join('');
|
|
35
|
-
if (/[^\p{L}\p{N}_]/u.test(textBetween)) {
|
|
36
|
-
result[1] = char;
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return result;
|
|
44
|
-
};
|