mikel 0.9.1 → 0.10.0

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/README.md +17 -0
  2. package/index.js +3 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -219,6 +219,23 @@ The `ne` helper renders the block only if the two values provided as argument ar
219
219
  console.log(m(`{{#ne name "bob"}}Not bob{{/ne}}`, {name: "John"})); // --> 'Not bob'
220
220
  ```
221
221
 
222
+ #### with
223
+
224
+ > Added in `v0.10.0`.
225
+
226
+ The `with` helper allows to change the data context of the block.
227
+
228
+ ```javascript
229
+ const data = {
230
+ autor: {
231
+ name: "Bob",
232
+ email: "bob@email.com",
233
+ },
234
+ };
235
+
236
+ console.log(m("{{#with autor}}{{name}} <{{email}}>{{/with}}", data)); // --> 'Bob <bob@email.com>'
237
+ ```
238
+
222
239
  ### Custom Helpers
223
240
 
224
241
  > Added in `v0.5.0`.
package/index.js CHANGED
@@ -32,7 +32,8 @@ const yamlParser = (str = "") => {
32
32
  level = level - 1;
33
33
  }
34
34
  const isArrayItem = line.trim().startsWith("-");
35
- let [key, value] = line.trim().split(":").map(v => v.trim());
35
+ // TODO: improve the regex to capture the line structure
36
+ let [_, key, value] = (line.trim().match(/^([^:"]*):(.*)$/m) || ["", line]).map(v => v.trim());
36
37
  // Check if is a new item of the array
37
38
  if (isArrayItem) {
38
39
  key = key.replace(/^(- *)/m, "");
@@ -90,6 +91,7 @@ const defaultHelpers = {
90
91
  "unless": (value, opt) => !!!value ? opt.fn(opt.context) : "",
91
92
  "eq": (a, b, opt) => a === b ? opt.fn(opt.context) : "",
92
93
  "ne": (a, b, opt) => a !== b ? opt.fn(opt.context) : "",
94
+ "with": (value, opt) => opt.fn(value),
93
95
  };
94
96
 
95
97
  const compile = (tokens, output, context, partials, helpers, vars, fn = {}, index = 0, section = "") => {
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.9.1",
4
+ "version": "0.10.0",
5
5
  "type": "module",
6
6
  "author": {
7
7
  "name": "Josemi Juanes",