-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtag-engine.js
More file actions
28 lines (24 loc) · 756 Bytes
/
tag-engine.js
File metadata and controls
28 lines (24 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
* @Author: Max Base
* @Date: 2021-08-31, 2021-09-04
* Repository: https://github.com/BaseMax/TinyTagEngineJS
*/
const tag_engine = (input, tags) => {
if(tags === undefined || tags === []) tags = {};
let res = input;
for( let tag in tags) {
const pattern = `\\[(\\s*|)${tag}(\\s*|)(\\:([^\\]]+)|)\\]`;
// console.log(tag, pattern);
const reg = new RegExp(pattern, 'g');
res = res.replace(reg, function(e) {
const id = e.split(reg);
// console.log("input", e);
// console.log("splits", id);
if(!id || id[4] === undefined) {
id[4] = "";
}
return tags[tag](String(id[4]).trim());
});
}
return res;
};