@twin.org/nameof-transformer 0.0.1-next.11 → 0.0.1-next.13

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.
@@ -116,27 +116,16 @@ function visitNode(node) {
116
116
  * @returns The content with the transformers replace.
117
117
  */
118
118
  function manual(content) {
119
- if (content.includes("nameof")) {
119
+ if (typeof content === "string" && content.includes("nameof")) {
120
120
  // Remove the import
121
121
  content = content.replace(/import.*from "@twin\.org\/nameof";/g, "");
122
122
  // Replace the nameof<IMyObject>() with "IMyObject"
123
- const nameRegEx = /nameof<(.*?)>\(\)/g;
124
- let matchName;
125
- do {
126
- matchName = nameRegEx.exec(content);
127
- if (matchName && matchName.length === 2) {
128
- content = content.replace(matchName[0], `"${matchName[1].replace(/\?/g, "")}"`);
129
- }
130
- } while (matchName);
123
+ // or the nameof<IMyObject<IType2>>() with "IMyObject"
124
+ const nameRegEx = /nameof<(.*?)(?:<.*>)?>\(\)/g;
125
+ content = content.replace(nameRegEx, '"$1"');
131
126
  // Replace the nameof(object?.prop) with "object.prop"
132
127
  const propRegEx = /nameof\((.*?)\)/g;
133
- let matchProp;
134
- do {
135
- matchProp = propRegEx.exec(content);
136
- if (matchProp && matchProp.length === 2) {
137
- content = content.replace(matchProp[0], `"${matchProp[1].replace(/\?/g, "")}"`);
138
- }
139
- } while (matchProp);
128
+ content = content.replace(propRegEx, '"$1"');
140
129
  }
141
130
  return content;
142
131
  }
@@ -173,7 +162,7 @@ const factory = () => transformerFactory;
173
162
  * Exports the factory version.
174
163
  * @returns The factory.
175
164
  */
176
- const version = "0.0.1-next.11";
165
+ const version = "0.0.1-next.13";
177
166
  /**
178
167
  * Exports the factory name.
179
168
  * @returns The factory.
@@ -93,27 +93,16 @@ function visitNode(node) {
93
93
  * @returns The content with the transformers replace.
94
94
  */
95
95
  function manual(content) {
96
- if (content.includes("nameof")) {
96
+ if (typeof content === "string" && content.includes("nameof")) {
97
97
  // Remove the import
98
98
  content = content.replace(/import.*from "@twin\.org\/nameof";/g, "");
99
99
  // Replace the nameof<IMyObject>() with "IMyObject"
100
- const nameRegEx = /nameof<(.*?)>\(\)/g;
101
- let matchName;
102
- do {
103
- matchName = nameRegEx.exec(content);
104
- if (matchName && matchName.length === 2) {
105
- content = content.replace(matchName[0], `"${matchName[1].replace(/\?/g, "")}"`);
106
- }
107
- } while (matchName);
100
+ // or the nameof<IMyObject<IType2>>() with "IMyObject"
101
+ const nameRegEx = /nameof<(.*?)(?:<.*>)?>\(\)/g;
102
+ content = content.replace(nameRegEx, '"$1"');
108
103
  // Replace the nameof(object?.prop) with "object.prop"
109
104
  const propRegEx = /nameof\((.*?)\)/g;
110
- let matchProp;
111
- do {
112
- matchProp = propRegEx.exec(content);
113
- if (matchProp && matchProp.length === 2) {
114
- content = content.replace(matchProp[0], `"${matchProp[1].replace(/\?/g, "")}"`);
115
- }
116
- } while (matchProp);
105
+ content = content.replace(propRegEx, '"$1"');
117
106
  }
118
107
  return content;
119
108
  }
@@ -150,7 +139,7 @@ const factory = () => transformerFactory;
150
139
  * Exports the factory version.
151
140
  * @returns The factory.
152
141
  */
153
- const version = "0.0.1-next.11";
142
+ const version = "0.0.1-next.13";
154
143
  /**
155
144
  * Exports the factory name.
156
145
  * @returns The factory.
@@ -0,0 +1,19 @@
1
+ import type * as ts from "typescript";
2
+ /**
3
+ * Exports the factory.
4
+ * @returns The factory.
5
+ */
6
+ export declare const factory: () => ts.TransformerFactory<ts.Node>;
7
+ /**
8
+ * Exports the factory version.
9
+ * @returns The factory.
10
+ */
11
+ export declare const version = "0.0.1-next.13";
12
+ /**
13
+ * Exports the factory name.
14
+ * @returns The factory.
15
+ */
16
+ export declare const name = "@twin.org/nameof-transformer";
17
+ export * from "./manual";
18
+ export * from "./svelte";
19
+ export default factory;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Replace the transformers manually.
3
+ * @param content The content to replace the transformers in.
4
+ * @returns The content with the transformers replace.
5
+ */
6
+ export declare function manual(content: string): string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Return a function that can be used as a svelte preprocessor.
3
+ * @returns The preprocessor.
4
+ */
5
+ export declare function tsTransformersPreProcess(): {
6
+ markup: unknown;
7
+ };
@@ -0,0 +1,13 @@
1
+ import * as ts from "typescript";
2
+ /**
3
+ * The transformer factory entry point.
4
+ * @param context The context for the factory.
5
+ * @returns The transformed node.
6
+ */
7
+ export declare const transformerFactory: ts.TransformerFactory<ts.Node>;
8
+ /**
9
+ * Transform all the nodes in a context.
10
+ * @param context The context to traverse.
11
+ * @returns A transformer for the context.
12
+ */
13
+ export declare function transformer(context: ts.TransformationContext): ts.Transformer<ts.Node>;
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/nameof-transformer - Changelog
2
2
 
3
- ## v0.0.1-next.11
3
+ ## v0.0.1-next.13
4
4
 
5
5
  - Initial Release
@@ -1,6 +1,6 @@
1
1
  # Variable: version
2
2
 
3
- > `const` **version**: `"0.0.1-next.11"` = `"0.0.1-next.11"`
3
+ > `const` **version**: `"0.0.1-next.13"` = `"0.0.1-next.13"`
4
4
 
5
5
  Exports the factory version.
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/nameof-transformer",
3
- "version": "0.0.1-next.11",
3
+ "version": "0.0.1-next.13",
4
4
  "description": "A TypeScript transformer which converts types and properties to their actual name for use at runtime",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,7 +21,8 @@
21
21
  "exports": {
22
22
  ".": {
23
23
  "require": "./dist/cjs/index.cjs",
24
- "import": "./dist/esm/index.mjs"
24
+ "import": "./dist/esm/index.mjs",
25
+ "types": "./dist/types/index.d.ts"
25
26
  }
26
27
  },
27
28
  "files": [