Skip to content

Commit 6da4d7a

Browse files
committed
[template] every, some
1 parent 621a188 commit 6da4d7a

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rightech/utils",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"description": "",
55
"main": "index.js",
66
"private": false,

src/template.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ const nanoid = require('nanoid');
2323
const format = require('./format');
2424
const safe = require('./safe');
2525

26+
function every(input, value) {
27+
if (!input || !input.every) {
28+
return false;
29+
}
30+
if (!value || !value.includes) {
31+
return false;
32+
}
33+
return input.every(one => value.includes(one));
34+
}
35+
36+
function some(input, value) {
37+
if (!input || !input.some) {
38+
return false;
39+
}
40+
if (!value || !value.includes) {
41+
return false;
42+
}
43+
return input.some(one => value.includes(one));
44+
}
45+
2646
Object.assign(expressions.filters, {
2747
date: format.date,
2848
time: format.time,
@@ -31,7 +51,9 @@ Object.assign(expressions.filters, {
3151
timeSpan: format.timeSpan,
3252
number: format.number,
3353
currency: format.currency,
34-
percent: format.percent
54+
percent: format.percent,
55+
every,
56+
some
3557
});
3658

3759
function normalizePath(path) {
@@ -67,7 +89,9 @@ module.exports = function parseTemplate(text = '', context = {}, opts = {}) {
6789
for (let tpl of parsed) {
6890
let [type, value] = tpl;
6991
if (type === 'name') {
70-
value = normalizePath(value);
92+
if (opts.normalizePaths) {
93+
value = normalizePath(value);
94+
}
7195
try {
7296
const evaluate = expressions.compile(value);
7397
value = evaluate(context);

0 commit comments

Comments
 (0)