@twin.org/nameof 0.0.3-next.21 → 0.0.3-next.23
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 +1 -3
- package/docs/changelog.md +29 -1
- package/docs/examples.md +34 -48
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# TWIN Nameof
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
This package is used in conjunction with the `@twin.org/nameof-transformer` package, without using the transformer for compilation you will end up with an error string embedded in your code instead of the runtime name you are expecting.
|
|
3
|
+
This package is part of the framework workspace and provides the definitions for the methods which are processed by the nameof-transformer to support consistent development workflows across the ecosystem.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.3-next.23](https://github.com/twinfoundation/framework/compare/nameof-v0.0.3-next.22...nameof-v0.0.3-next.23) (2026-03-17)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **nameof:** Synchronize repo versions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* devDependencies
|
|
15
|
+
* @twin.org/nameof-transformer bumped from 0.0.3-next.22 to 0.0.3-next.23
|
|
16
|
+
|
|
17
|
+
## [0.0.3-next.22](https://github.com/twinfoundation/framework/compare/nameof-v0.0.3-next.21...nameof-v0.0.3-next.22) (2026-02-26)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Miscellaneous Chores
|
|
21
|
+
|
|
22
|
+
* **nameof:** Synchronize repo versions
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* devDependencies
|
|
29
|
+
* @twin.org/nameof-transformer bumped from 0.0.3-next.21 to 0.0.3-next.22
|
|
2
30
|
|
|
3
31
|
## [0.0.3-next.21](https://github.com/twinfoundation/framework/compare/nameof-v0.0.3-next.20...nameof-v0.0.3-next.21) (2026-02-26)
|
|
4
32
|
|
package/docs/examples.md
CHANGED
|
@@ -1,74 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Nameof Examples
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Use these snippets for strongly typed name extraction patterns that remain safe during refactors.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
We have many places in our code where we want to use the name of the class, we could do the following.
|
|
5
|
+
## `nameof`
|
|
8
6
|
|
|
9
7
|
```typescript
|
|
10
|
-
|
|
11
|
-
public static className(): string {
|
|
12
|
-
return 'MyClass';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
console.log(MyClass.className()); // Outputs "MyClass"
|
|
16
|
-
```
|
|
8
|
+
import { nameof } from '@twin.org/nameof';
|
|
17
9
|
|
|
18
|
-
|
|
10
|
+
class AccountState {
|
|
11
|
+
public id!: string;
|
|
12
|
+
}
|
|
19
13
|
|
|
20
|
-
|
|
14
|
+
nameof<AccountState>(); // 'AccountState'
|
|
15
|
+
```
|
|
21
16
|
|
|
22
17
|
```typescript
|
|
23
18
|
import { nameof } from '@twin.org/nameof';
|
|
24
19
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
interface Profile {
|
|
21
|
+
displayName: string;
|
|
22
|
+
stats?: {
|
|
23
|
+
loginCount: number;
|
|
24
|
+
};
|
|
29
25
|
}
|
|
30
|
-
console.log(MyClass.className()); // Outputs "MyClass"
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Now if we rename `MyClass` without updating the references in the `nameof` call we will get a compiler error, code auto refactoring would actually perform the rename for us.
|
|
34
26
|
|
|
35
|
-
|
|
27
|
+
const profile: Profile = {
|
|
28
|
+
displayName: 'Ari',
|
|
29
|
+
stats: {
|
|
30
|
+
loginCount: 12
|
|
31
|
+
}
|
|
32
|
+
};
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
static public className(): string {
|
|
40
|
-
return "MyClass";
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
console.log(MyClass.className()); // Outputs "MyClass"
|
|
34
|
+
nameof(profile.displayName); // 'displayName'
|
|
35
|
+
nameof(profile.stats?.loginCount); // 'stats.loginCount'
|
|
44
36
|
```
|
|
45
37
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
## `nameof(propName)`
|
|
49
|
-
|
|
50
|
-
The `nameof(propName)` transform behaves in much the same way as `nameof<T>`, but instead works on properties passed to it.
|
|
38
|
+
## `nameofKebabCase`
|
|
51
39
|
|
|
52
40
|
```typescript
|
|
53
|
-
import {
|
|
41
|
+
import { nameofKebabCase } from '@twin.org/nameof';
|
|
54
42
|
|
|
55
|
-
|
|
56
|
-
public
|
|
57
|
-
return nameof(aProp);
|
|
58
|
-
}
|
|
43
|
+
class ReportSummary {
|
|
44
|
+
public totalCount!: number;
|
|
59
45
|
}
|
|
60
|
-
|
|
46
|
+
|
|
47
|
+
nameofKebabCase<ReportSummary>(); // 'report-summary'
|
|
61
48
|
```
|
|
62
49
|
|
|
63
|
-
|
|
50
|
+
## `nameofCamelCase`
|
|
64
51
|
|
|
65
52
|
```typescript
|
|
66
|
-
import {
|
|
53
|
+
import { nameofCamelCase } from '@twin.org/nameof';
|
|
67
54
|
|
|
68
|
-
|
|
69
|
-
public
|
|
70
|
-
return nameof(aProp?.inner);
|
|
71
|
-
}
|
|
55
|
+
class UserProfileRecord {
|
|
56
|
+
public profileImageUrl!: string;
|
|
72
57
|
}
|
|
73
|
-
|
|
58
|
+
|
|
59
|
+
nameofCamelCase<UserProfileRecord>(); // 'userProfileRecord'
|
|
74
60
|
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/nameof",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.23",
|
|
4
|
+
"description": "The definitions for the methods which are processed by the nameof-transformer",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/twinfoundation/framework.git",
|