@peter.naydenov/morph 1.2.0 → 1.2.1
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/Changelog.md +6 -0
- package/package.json +3 -2
- package/src/methods/_defineData.js +0 -1
- package/src/methods/_setupActions.js +1 -1
- package/src/methods/build.js +2 -1
- package/types/index.d.ts +60 -0
package/Changelog.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
### 1.2.1 (2025-03-16)
|
|
6
|
+
- [x]Enhanced Error Handling in setupActions.js: Improved the error message to provide more context about the missing level markers, making it easier to debug;
|
|
7
|
+
- [x] Added TypeScript Type Definitions: Created a types directory with an index.d.ts file containing TypeScript definitions for the library, and added the "types" field to package.json for better TypeScript support;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
5
11
|
### 1.2.0 (2025-03-14)
|
|
6
12
|
- [x] Bug fix: Deeply nested data;
|
|
7
13
|
- [x] Improve: Error message if actions do not have deepness of the data (very difficult to debug);
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peter.naydenov/morph",
|
|
3
3
|
"description": "Template engine",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Peter Naydenov",
|
|
7
|
-
"main": "
|
|
7
|
+
"main": "./src/main.js",
|
|
8
8
|
"type": "module",
|
|
9
|
+
"types": "./types/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
12
|
"import": "./src/main.js",
|
|
@@ -8,7 +8,7 @@ function _setupActions ( actions, dataDeepLevel=10 ) {
|
|
|
8
8
|
;
|
|
9
9
|
|
|
10
10
|
actionList.forEach ( action => { if ( action === '#' ) countHashes++ })
|
|
11
|
-
if ( countHashes < dataDeepLevel ) console.error ( `Error:
|
|
11
|
+
if ( countHashes < dataDeepLevel ) console.error ( `Error: Not enough level markers (#) for data with depth level ${dataDeepLevel}. Found ${countHashes} level markers in actions: ${actions.join(', ')}` )
|
|
12
12
|
|
|
13
13
|
do {
|
|
14
14
|
actSetup[i] = []
|
package/src/methods/build.js
CHANGED
|
@@ -86,7 +86,8 @@ function build ( tpl, extra=false, buildDependencies={} ) {
|
|
|
86
86
|
|
|
87
87
|
if ( topLevelType !== 'array' ) d = [ d ]
|
|
88
88
|
|
|
89
|
-
//
|
|
89
|
+
// Handle null data case - just return the template without placeholders
|
|
90
|
+
if ( topLevelType === 'null' ) return cuts.join ( '' ).replace(/{{.*?}}/g, '')
|
|
90
91
|
|
|
91
92
|
d.forEach ( dElement => {
|
|
92
93
|
placeholders.forEach ( holder => { // Placeholders
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
declare module '@peter.naydenov/morph' {
|
|
2
|
+
/**
|
|
3
|
+
* Template description object
|
|
4
|
+
*/
|
|
5
|
+
interface TemplateDescription {
|
|
6
|
+
/**
|
|
7
|
+
* Template string with placeholders
|
|
8
|
+
*/
|
|
9
|
+
template: string;
|
|
10
|
+
/**
|
|
11
|
+
* Optional helper functions or templates
|
|
12
|
+
*/
|
|
13
|
+
helpers?: Record<string, any>;
|
|
14
|
+
/**
|
|
15
|
+
* Optional example data for rendering
|
|
16
|
+
*/
|
|
17
|
+
handshake?: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Build a component from template description
|
|
22
|
+
*/
|
|
23
|
+
function build(tpl: TemplateDescription, extra?: boolean, buildDependencies?: Record<string, any>): Function;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get a component from component storage
|
|
27
|
+
*/
|
|
28
|
+
function get(location: [string, string?]): Function;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Add a component to component storage
|
|
32
|
+
*/
|
|
33
|
+
function add(location: [string, string?], tplfn: Function | TemplateDescription, ...args: any[]): void;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* List the names of all components in the component storage
|
|
37
|
+
*/
|
|
38
|
+
function list(storageNames?: string[]): string[];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Clear up all the components in the storage
|
|
42
|
+
*/
|
|
43
|
+
function clear(): void;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Remove a template from component storage
|
|
47
|
+
*/
|
|
48
|
+
function remove(location: [string, string?]): void | string;
|
|
49
|
+
|
|
50
|
+
const morphAPI: {
|
|
51
|
+
build: typeof build;
|
|
52
|
+
get: typeof get;
|
|
53
|
+
add: typeof add;
|
|
54
|
+
list: typeof list;
|
|
55
|
+
clear: typeof clear;
|
|
56
|
+
remove: typeof remove;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default morphAPI;
|
|
60
|
+
}
|