@arcmantle/chronicle 1.0.2 → 1.0.3
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/nameof.d.ts +1 -2
- package/dist/nameof.d.ts.map +1 -1
- package/dist/nameof.js +38 -12
- package/dist/nameof.js.map +1 -1
- package/package.json +1 -1
- package/src/nameof.ts +51 -13
package/dist/nameof.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export type Nameof<T> = (m: T extends object ? T : any) => any;
|
|
2
2
|
/**
|
|
3
|
-
* Returns
|
|
4
|
-
* or dotted path if the fullPath flag is set to true.
|
|
3
|
+
* Returns the dot-separated property path captured from the selector expression.
|
|
5
4
|
*/
|
|
6
5
|
export declare const nameof: <const T>(expression: (instance: T) => any) => string;
|
|
7
6
|
/**
|
package/dist/nameof.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nameof.d.ts","sourceRoot":"","sources":["../src/nameof.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nameof.d.ts","sourceRoot":"","sources":["../src/nameof.ts"],"names":[],"mappings":"AA0BA,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,GAAG,KAAK,GAAG,CAAC;AAG/D;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,QAAQ,EAAE,CAAC,KAAK,GAAG,KAAG,MAoBlE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,QAAQ,EAAE,CAAC,KAAK,GAAG,KAAG,MAAM,EAqBhF,CAAC"}
|
package/dist/nameof.js
CHANGED
|
@@ -1,30 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//
|
|
3
|
-
const
|
|
4
|
-
//
|
|
1
|
+
import { getSymbolId } from "./symbol-id.js";
|
|
2
|
+
// Pre-allocated array to minimize allocations
|
|
3
|
+
const propertyPath = [];
|
|
4
|
+
// Fast path length tracking to avoid .length lookups
|
|
5
|
+
let pathLength = 0;
|
|
6
|
+
// Inline property key normalization for maximum speed
|
|
7
|
+
const normalizeKey = (prop) => typeof prop === 'symbol' ? getSymbolId(prop) : prop;
|
|
8
|
+
// Highly optimized proxy with minimal overhead
|
|
5
9
|
const proxy = new Proxy({}, {
|
|
6
10
|
get: (_, prop) => {
|
|
7
|
-
//
|
|
8
|
-
|
|
11
|
+
// Direct assignment instead of push for speed
|
|
12
|
+
propertyPath[pathLength++] = normalizeKey(prop);
|
|
9
13
|
return proxy;
|
|
10
14
|
},
|
|
11
15
|
});
|
|
12
16
|
/**
|
|
13
|
-
* Returns
|
|
14
|
-
* or dotted path if the fullPath flag is set to true.
|
|
17
|
+
* Returns the dot-separated property path captured from the selector expression.
|
|
15
18
|
*/
|
|
16
19
|
export const nameof = (expression) => {
|
|
17
|
-
|
|
20
|
+
pathLength = 0;
|
|
18
21
|
expression(proxy);
|
|
19
|
-
|
|
22
|
+
// Fast path for single property (most common case)
|
|
23
|
+
if (pathLength === 1)
|
|
24
|
+
return propertyPath[0];
|
|
25
|
+
// Fast path for 2-3 properties (very common)
|
|
26
|
+
if (pathLength === 2)
|
|
27
|
+
return propertyPath[0] + '.' + propertyPath[1];
|
|
28
|
+
if (pathLength === 3)
|
|
29
|
+
return propertyPath[0] + '.' + propertyPath[1] + '.' + propertyPath[2];
|
|
30
|
+
// General case: manual join for better performance than Array.join
|
|
31
|
+
let result = propertyPath[0];
|
|
32
|
+
for (let i = 1; i < pathLength; i++)
|
|
33
|
+
result += '.' + propertyPath[i];
|
|
34
|
+
return result;
|
|
20
35
|
};
|
|
21
36
|
/**
|
|
22
37
|
* Returns a fresh array of path segments captured from the selector expression.
|
|
23
38
|
* The returned array is a new copy to avoid external mutations affecting internals.
|
|
24
39
|
*/
|
|
25
40
|
export const nameofSegments = (expression) => {
|
|
26
|
-
|
|
41
|
+
pathLength = 0;
|
|
27
42
|
expression(proxy);
|
|
28
|
-
|
|
43
|
+
// Fast paths for common cases
|
|
44
|
+
if (pathLength === 1)
|
|
45
|
+
return [propertyPath[0]];
|
|
46
|
+
if (pathLength === 2)
|
|
47
|
+
return [propertyPath[0], propertyPath[1]];
|
|
48
|
+
if (pathLength === 3)
|
|
49
|
+
return [propertyPath[0], propertyPath[1], propertyPath[2]];
|
|
50
|
+
// General case: manual copy for better performance
|
|
51
|
+
const result = new Array(pathLength);
|
|
52
|
+
for (let i = 0; i < pathLength; i++)
|
|
53
|
+
result[i] = propertyPath[i];
|
|
54
|
+
return result;
|
|
29
55
|
};
|
|
30
56
|
//# sourceMappingURL=nameof.js.map
|
package/dist/nameof.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nameof.js","sourceRoot":"","sources":["../src/nameof.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"nameof.js","sourceRoot":"","sources":["../src/nameof.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,8CAA8C;AAC9C,MAAM,YAAY,GAAa,EAAE,CAAC;AAElC,qDAAqD;AACrD,IAAI,UAAU,GAAG,CAAC,CAAC;AAGnB,sDAAsD;AACtD,MAAM,YAAY,GAAG,CAAC,IAAiB,EAAU,EAAE,CAClD,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,IAAe,CAAC;AAGjE,+CAA+C;AAC/C,MAAM,KAAK,GAAQ,IAAI,KAAK,CAAC,EAAS,EAAE;IACvC,GAAG,EAAE,CAAC,CAAM,EAAE,IAAiB,EAAE,EAAE;QAClC,8CAA8C;QAC9C,YAAY,CAAC,UAAU,EAAE,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QA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AAC,CAAE,EAAE,YAAY,CAAC,CAAC,CAAE,EAAE,YAAY,CAAC,CAAC,CAAE,CAAE,CAAC;IAEjE,mDAAmD;IACnD,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;IACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE;QAClC,MAAM,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAE,CAAC;IAG9B,OAAO,MAAM,CAAC;AACf,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/nameof.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getSymbolId } from './symbol-id.ts';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
//
|
|
5
|
-
const
|
|
4
|
+
// Pre-allocated array to minimize allocations
|
|
5
|
+
const propertyPath: string[] = [];
|
|
6
6
|
|
|
7
|
+
// Fast path length tracking to avoid .length lookups
|
|
8
|
+
let pathLength = 0;
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
|
|
11
|
+
// Inline property key normalization for maximum speed
|
|
12
|
+
const normalizeKey = (prop: PropertyKey): string =>
|
|
13
|
+
typeof prop === 'symbol' ? getSymbolId(prop) : (prop as string);
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// Highly optimized proxy with minimal overhead
|
|
9
17
|
const proxy: any = new Proxy({} as any, {
|
|
10
|
-
get:
|
|
11
|
-
//
|
|
12
|
-
|
|
18
|
+
get: (_: any, prop: PropertyKey) => {
|
|
19
|
+
// Direct assignment instead of push for speed
|
|
20
|
+
propertyPath[pathLength++] = normalizeKey(prop);
|
|
13
21
|
|
|
14
22
|
return proxy;
|
|
15
23
|
},
|
|
@@ -20,14 +28,28 @@ export type Nameof<T> = (m: T extends object ? T : any) => any;
|
|
|
20
28
|
|
|
21
29
|
|
|
22
30
|
/**
|
|
23
|
-
* Returns
|
|
24
|
-
* or dotted path if the fullPath flag is set to true.
|
|
31
|
+
* Returns the dot-separated property path captured from the selector expression.
|
|
25
32
|
*/
|
|
26
33
|
export const nameof = <const T>(expression: (instance: T) => any): string => {
|
|
27
|
-
|
|
34
|
+
pathLength = 0;
|
|
28
35
|
expression(proxy);
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
// Fast path for single property (most common case)
|
|
38
|
+
if (pathLength === 1)
|
|
39
|
+
return propertyPath[0]!;
|
|
40
|
+
|
|
41
|
+
// Fast path for 2-3 properties (very common)
|
|
42
|
+
if (pathLength === 2)
|
|
43
|
+
return propertyPath[0]! + '.' + propertyPath[1]!;
|
|
44
|
+
if (pathLength === 3)
|
|
45
|
+
return propertyPath[0]! + '.' + propertyPath[1]! + '.' + propertyPath[2]!;
|
|
46
|
+
|
|
47
|
+
// General case: manual join for better performance than Array.join
|
|
48
|
+
let result = propertyPath[0]!;
|
|
49
|
+
for (let i = 1; i < pathLength; i++)
|
|
50
|
+
result += '.' + propertyPath[i]!;
|
|
51
|
+
|
|
52
|
+
return result;
|
|
31
53
|
};
|
|
32
54
|
|
|
33
55
|
/**
|
|
@@ -35,8 +57,24 @@ export const nameof = <const T>(expression: (instance: T) => any): string => {
|
|
|
35
57
|
* The returned array is a new copy to avoid external mutations affecting internals.
|
|
36
58
|
*/
|
|
37
59
|
export const nameofSegments = <const T>(expression: (instance: T) => any): string[] => {
|
|
38
|
-
|
|
60
|
+
pathLength = 0;
|
|
39
61
|
expression(proxy);
|
|
40
62
|
|
|
41
|
-
|
|
63
|
+
// Fast paths for common cases
|
|
64
|
+
if (pathLength === 1)
|
|
65
|
+
return [ propertyPath[0]! ];
|
|
66
|
+
|
|
67
|
+
if (pathLength === 2)
|
|
68
|
+
return [ propertyPath[0]!, propertyPath[1]! ];
|
|
69
|
+
|
|
70
|
+
if (pathLength === 3)
|
|
71
|
+
return [ propertyPath[0]!, propertyPath[1]!, propertyPath[2]! ];
|
|
72
|
+
|
|
73
|
+
// General case: manual copy for better performance
|
|
74
|
+
const result = new Array(pathLength);
|
|
75
|
+
for (let i = 0; i < pathLength; i++)
|
|
76
|
+
result[i] = propertyPath[i]!;
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
return result;
|
|
42
80
|
};
|