@twin.org/nameof 0.0.2-next.8 → 0.0.2
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/dist/es/index.js +33 -0
- package/dist/es/index.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/docs/changelog.md +906 -42
- package/docs/examples.md +34 -48
- package/docs/reference/functions/nameofCamelCase.md +31 -0
- package/docs/reference/functions/nameofKebabCase.md +31 -0
- package/docs/reference/index.md +2 -0
- package/package.json +19 -10
- package/dist/cjs/index.cjs +0 -16
- package/dist/esm/index.mjs +0 -14
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
|
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Function: nameofCamelCase()
|
|
2
|
+
|
|
3
|
+
> **nameofCamelCase**\<`T`\>(`property?`, `replaceParent?`): `string`
|
|
4
|
+
|
|
5
|
+
Placeholder method which substitutes the type name as a string at runtime.
|
|
6
|
+
|
|
7
|
+
## Type Parameters
|
|
8
|
+
|
|
9
|
+
### T
|
|
10
|
+
|
|
11
|
+
`T`
|
|
12
|
+
|
|
13
|
+
## Parameters
|
|
14
|
+
|
|
15
|
+
### property?
|
|
16
|
+
|
|
17
|
+
`unknown`
|
|
18
|
+
|
|
19
|
+
The property to get the name of.
|
|
20
|
+
|
|
21
|
+
### replaceParent?
|
|
22
|
+
|
|
23
|
+
`string`
|
|
24
|
+
|
|
25
|
+
Optional object name to replace the top level object of a property path.
|
|
26
|
+
|
|
27
|
+
## Returns
|
|
28
|
+
|
|
29
|
+
`string`
|
|
30
|
+
|
|
31
|
+
The type name as a string.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Function: nameofKebabCase()
|
|
2
|
+
|
|
3
|
+
> **nameofKebabCase**\<`T`\>(`property?`, `replaceParent?`): `string`
|
|
4
|
+
|
|
5
|
+
Placeholder method which substitutes the type name as a string at runtime.
|
|
6
|
+
|
|
7
|
+
## Type Parameters
|
|
8
|
+
|
|
9
|
+
### T
|
|
10
|
+
|
|
11
|
+
`T`
|
|
12
|
+
|
|
13
|
+
## Parameters
|
|
14
|
+
|
|
15
|
+
### property?
|
|
16
|
+
|
|
17
|
+
`unknown`
|
|
18
|
+
|
|
19
|
+
The property to get the name of.
|
|
20
|
+
|
|
21
|
+
### replaceParent?
|
|
22
|
+
|
|
23
|
+
`string`
|
|
24
|
+
|
|
25
|
+
Optional object name to replace the top level object of a property path.
|
|
26
|
+
|
|
27
|
+
## Returns
|
|
28
|
+
|
|
29
|
+
`string`
|
|
30
|
+
|
|
31
|
+
The type name as a string.
|
package/docs/reference/index.md
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/nameof",
|
|
3
|
-
"version": "0.0.2
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "The definitions for the methods which are processed by the nameof-transformer",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/
|
|
7
|
+
"url": "git+https://github.com/iotaledger/framework.git",
|
|
8
8
|
"directory": "packages/nameof"
|
|
9
9
|
},
|
|
10
10
|
"author": "martyn.janes@iota.org",
|
|
@@ -13,21 +13,30 @@
|
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
|
-
"main": "./dist/
|
|
17
|
-
"module": "./dist/esm/index.mjs",
|
|
16
|
+
"main": "./dist/es/index.js",
|
|
18
17
|
"types": "./dist/types/index.d.ts",
|
|
19
18
|
"exports": {
|
|
20
19
|
".": {
|
|
21
20
|
"types": "./dist/types/index.d.ts",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
21
|
+
"import": "./dist/es/index.js",
|
|
22
|
+
"default": "./dist/es/index.js"
|
|
24
23
|
}
|
|
25
24
|
},
|
|
26
25
|
"files": [
|
|
27
|
-
"dist/
|
|
28
|
-
"dist/esm",
|
|
26
|
+
"dist/es",
|
|
29
27
|
"dist/types",
|
|
30
28
|
"locales",
|
|
31
29
|
"docs"
|
|
32
|
-
]
|
|
30
|
+
],
|
|
31
|
+
"keywords": [
|
|
32
|
+
"twin",
|
|
33
|
+
"trade",
|
|
34
|
+
"iota",
|
|
35
|
+
"framework",
|
|
36
|
+
"blockchain"
|
|
37
|
+
],
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "git+https://github.com/iotaledger/framework/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://twindev.org"
|
|
33
42
|
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Copyright 2024 IOTA Stiftung.
|
|
4
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
5
|
-
/**
|
|
6
|
-
* Placeholder method which substitutes the type name as a string at runtime.
|
|
7
|
-
* @param property The property to get the name of.
|
|
8
|
-
* @param replaceParent Optional object name to replace the top level object of a property path.
|
|
9
|
-
* @returns The type name as a string.
|
|
10
|
-
*/
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
-
function nameof(property, replaceParent) {
|
|
13
|
-
return "@twin.org/nameof-transformer is not in the build pipeline, you need to use a compiler that supports transformer plugins.";
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.nameof = nameof;
|
package/dist/esm/index.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 IOTA Stiftung.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
/**
|
|
4
|
-
* Placeholder method which substitutes the type name as a string at runtime.
|
|
5
|
-
* @param property The property to get the name of.
|
|
6
|
-
* @param replaceParent Optional object name to replace the top level object of a property path.
|
|
7
|
-
* @returns The type name as a string.
|
|
8
|
-
*/
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
-
function nameof(property, replaceParent) {
|
|
11
|
-
return "@twin.org/nameof-transformer is not in the build pipeline, you need to use a compiler that supports transformer plugins.";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { nameof };
|