mikel 0.17.0 → 0.17.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.
Files changed (3) hide show
  1. package/index.d.ts +48 -0
  2. package/index.js +0 -13
  3. package/package.json +4 -3
package/index.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ declare type HelperFunction = (params: {
2
+ args: any[];
3
+ opt: Record<string, any>;
4
+ context: Record<string, any>;
5
+ fn: (context?: Record<string, any>, vars?: Record<string, any>, output?: string[]) => string;
6
+ }) => string;
7
+
8
+ declare interface Helpers {
9
+ [key: string]: HelperFunction;
10
+ }
11
+
12
+ declare interface Partials {
13
+ [key: string]: string;
14
+ }
15
+
16
+ declare interface Functions {
17
+ [key: string]: (params: {
18
+ args: any[];
19
+ opt: Record<string, any>;
20
+ context: Record<string, any>;
21
+ }) => string | void;
22
+ }
23
+
24
+ declare interface MikelOptions {
25
+ helpers?: Helpers;
26
+ partials?: Partials;
27
+ functions?: Functions;
28
+ }
29
+
30
+ declare interface MikelTemplate {
31
+ (data?: any): string;
32
+ addHelper(name: string, fn: HelperFunction): void;
33
+ removeHelper(name: string): void;
34
+ addFunction(name: string, fn: (params: any) => string | void): void;
35
+ removeFunction(name: string): void;
36
+ addPartial(name: string, partial: string): void;
37
+ removePartial(name: string): void;
38
+ }
39
+
40
+ declare const mikel: {
41
+ (template: string, data?: any, options?: Partial<MikelOptions>): string;
42
+ create(template: string, options?: Partial<MikelOptions>): MikelTemplate;
43
+ escape(str: string): string;
44
+ get(context: any, path: string): any;
45
+ parse(value: string, context?: any, vars?: any): any;
46
+ };
47
+
48
+ export default mikel;
package/index.js CHANGED
@@ -35,18 +35,6 @@ const parse = (v, context = {}, vars = {}) => {
35
35
  return (v || "").startsWith("@") ? get(vars, v.slice(1)) : get(context, v || ".");
36
36
  };
37
37
 
38
- // @description tiny front-matter parser
39
- const frontmatter = (str = "", parser = null) => {
40
- let body = (str || "").trim(), data = {};
41
- const matches = Array.from(body.matchAll(/^(--- *)/gm))
42
- if (matches?.length === 2 && matches[0].index === 0) {
43
- const front = body.substring(0 + matches[0][1].length, matches[1].index).trim();
44
- body = body.substring(matches[1].index + matches[1][1].length).trim();
45
- data = typeof parser === "function" ? parser(front) : front;
46
- }
47
- return {body, data};
48
- };
49
-
50
38
  // @description default helpers
51
39
  const defaultHelpers = {
52
40
  "each": p => {
@@ -183,6 +171,5 @@ mikel.create = create;
183
171
  mikel.escape = escape;
184
172
  mikel.get = get;
185
173
  mikel.parse = parse;
186
- mikel.frontmatter = frontmatter;
187
174
 
188
175
  export default mikel;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mikel",
3
3
  "description": "Micro templating library with zero dependencies",
4
- "version": "0.17.0",
4
+ "version": "0.17.1",
5
5
  "type": "module",
6
6
  "author": {
7
7
  "name": "Josemi Juanes",
@@ -12,12 +12,12 @@
12
12
  "bugs": "https://github.com/jmjuanes/mikel/issues",
13
13
  "main": "index.js",
14
14
  "module": "index.js",
15
+ "types": "index.d.ts",
15
16
  "exports": {
16
17
  ".": "./index.js",
17
18
  "./package.json": "./package.json"
18
19
  },
19
20
  "scripts": {
20
- "release": "node scripts/release.js",
21
21
  "test": "node test.js"
22
22
  },
23
23
  "keywords": [
@@ -27,6 +27,7 @@
27
27
  "files": [
28
28
  "README.md",
29
29
  "LICENSE",
30
- "index.js"
30
+ "index.js",
31
+ "index.d.ts"
31
32
  ]
32
33
  }