@nordcraft/core 1.0.41 → 1.0.42
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/types.d.ts +12 -0
- package/dist/utils/handlerUtils.d.ts +6 -0
- package/dist/utils/handlerUtils.js +13 -0
- package/dist/utils/handlerUtils.js.map +1 -0
- package/package.json +1 -1
- package/src/types.ts +14 -0
- package/src/utils/handlerUtils.test.ts +15 -0
- package/src/utils/handlerUtils.ts +14 -0
package/dist/types.d.ts
CHANGED
|
@@ -33,6 +33,18 @@ export interface PluginActionV2 extends PluginActionBase {
|
|
|
33
33
|
handler: ActionHandlerV2;
|
|
34
34
|
version: 2;
|
|
35
35
|
}
|
|
36
|
+
export interface PluginAction {
|
|
37
|
+
name: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
version?: 2 | never;
|
|
40
|
+
arguments: Array<{
|
|
41
|
+
name: string;
|
|
42
|
+
formula: Formula;
|
|
43
|
+
}>;
|
|
44
|
+
variableArguments: boolean | null;
|
|
45
|
+
handler: string;
|
|
46
|
+
exported?: boolean;
|
|
47
|
+
}
|
|
36
48
|
export type ArgumentInputDataFunction = (items: unknown[], index: number, input: any) => ComponentData;
|
|
37
49
|
export type CustomFormulaHandler = (name: string, packageName: string | undefined) => PluginFormula<FormulaHandlerV2> | undefined;
|
|
38
50
|
export type FormulaLookup = (name: string) => FormulaHandler | undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes non-alphanumeric characters except for _ from a function name
|
|
3
|
+
* @param name
|
|
4
|
+
* @returns "safe" function name only containing alphanumeric characters and _, e.g. "myFunction" or "my_function"
|
|
5
|
+
*/
|
|
6
|
+
export declare const safeFunctionName: (name: string) => string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes non-alphanumeric characters except for _ from a function name
|
|
3
|
+
* @param name
|
|
4
|
+
* @returns "safe" function name only containing alphanumeric characters and _, e.g. "myFunction" or "my_function"
|
|
5
|
+
*/
|
|
6
|
+
export const safeFunctionName = (name) => {
|
|
7
|
+
return (name
|
|
8
|
+
// Remove any non-alphanumeric characters
|
|
9
|
+
.replaceAll(/[^a-zA-Z0-9_]/g, '')
|
|
10
|
+
// Remove any leading numbers
|
|
11
|
+
.replace(/^[0-9]+/, ''));
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=handlerUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlerUtils.js","sourceRoot":"","sources":["../../src/utils/handlerUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,EAAE;IAC/C,OAAO,CACL,IAAI;QACF,yCAAyC;SACxC,UAAU,CAAC,gBAAgB,EAAE,EAAE,CAAC;QACjC,6BAA6B;SAC5B,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAC1B,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -58,6 +58,20 @@ export interface PluginActionV2 extends PluginActionBase {
|
|
|
58
58
|
version: 2
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
export interface PluginAction {
|
|
62
|
+
name: string
|
|
63
|
+
description?: string
|
|
64
|
+
version?: 2 | never
|
|
65
|
+
arguments: Array<{
|
|
66
|
+
name: string
|
|
67
|
+
formula: Formula
|
|
68
|
+
}>
|
|
69
|
+
variableArguments: boolean | null
|
|
70
|
+
handler: string
|
|
71
|
+
// exported indicates that an action is exported in a package
|
|
72
|
+
exported?: boolean
|
|
73
|
+
}
|
|
74
|
+
|
|
61
75
|
export type ArgumentInputDataFunction = (
|
|
62
76
|
items: unknown[],
|
|
63
77
|
index: number,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { safeFunctionName } from './handlerUtils'
|
|
2
|
+
|
|
3
|
+
describe('safeFunctionName', () => {
|
|
4
|
+
test('should remove any non-alphanumeric characters', () => {
|
|
5
|
+
const input = ' MyHandler!@# '
|
|
6
|
+
const result = safeFunctionName(input)
|
|
7
|
+
expect(result).toBe('MyHandler')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
test('should remove any leading numbers', () => {
|
|
11
|
+
const input = '123MyHandler123'
|
|
12
|
+
const result = safeFunctionName(input)
|
|
13
|
+
expect(result).toBe('MyHandler123')
|
|
14
|
+
})
|
|
15
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes non-alphanumeric characters except for _ from a function name
|
|
3
|
+
* @param name
|
|
4
|
+
* @returns "safe" function name only containing alphanumeric characters and _, e.g. "myFunction" or "my_function"
|
|
5
|
+
*/
|
|
6
|
+
export const safeFunctionName = (name: string) => {
|
|
7
|
+
return (
|
|
8
|
+
name
|
|
9
|
+
// Remove any non-alphanumeric characters
|
|
10
|
+
.replaceAll(/[^a-zA-Z0-9_]/g, '')
|
|
11
|
+
// Remove any leading numbers
|
|
12
|
+
.replace(/^[0-9]+/, '')
|
|
13
|
+
)
|
|
14
|
+
}
|