@pluginjs/template
Advanced tools
Comparing version 0.2.19 to 0.6.1
@@ -1,88 +0,66 @@ | ||
/* Credit to https://github.com/jonschlinkert/get-value MIT */ | ||
function getValueByPath(obj, path) { | ||
if (Object(obj) !== obj || typeof path === 'undefined') { | ||
return obj; | ||
} | ||
import { getValueByPath } from '@pluginjs/utils'; | ||
if (path in obj) { | ||
return obj[path]; | ||
} | ||
/* Credit to https://github.com/Matt-Esch/string-template MIT */ | ||
const segs = path.split('.'); | ||
const length = segs.length; | ||
if (!length) { | ||
return undefined; | ||
const pattern = /\{\s*([.0-9a-zA-Z_]+)\s*\}/g; | ||
function render(string, ...args) { | ||
if (args.length === 1 && typeof args[0] === 'object') { | ||
args = args[0]; | ||
} | ||
let i = -1; | ||
while (obj && ++i < length) { | ||
let key = segs[i]; | ||
while (key[key.length - 1] === '\\') { | ||
key = `${key.slice(0, -1)}.${segs[++i]}`; | ||
} | ||
obj = obj[key]; | ||
if (!args || !args.hasOwnProperty) { | ||
args = {}; | ||
} | ||
return obj; | ||
} | ||
/* Credit to https://github.com/Matt-Esch/string-template MIT */ | ||
const template = function () { | ||
const pattern = /\{\s*([.0-9a-zA-Z_]+)\s*\}/g; | ||
return string.replace(pattern, (match, i, index) => { | ||
let result = null; | ||
function render(string, ...args) { | ||
if (args.length === 1 && typeof args[0] === 'object') { | ||
args = args[0]; | ||
if (string[index - 1] === '{' && string[index + match.length] === '}') { | ||
return i; | ||
} | ||
if (!args || !args.hasOwnProperty) { | ||
args = {}; | ||
if (Object.prototype.hasOwnProperty.call(args, i)) { | ||
result = args[i]; | ||
} else if (i.indexOf('.') !== -1) { | ||
result = getValueByPath(args, i); | ||
} | ||
return string.replace(pattern, (match, i, index) => { | ||
let result = null; | ||
if (result === null || typeof result === 'undefined') { | ||
return ''; | ||
} | ||
if (string[index - 1] === '{' && string[index + match.length] === '}') { | ||
return i; | ||
} | ||
return result; | ||
}); | ||
} | ||
if (args.hasOwnProperty(i)) { | ||
result = args[i]; | ||
} else if (i.indexOf('.') !== -1) { | ||
result = getValueByPath(args, i); | ||
} | ||
var main = { | ||
render, | ||
if (result === null || result === undefined) { | ||
return ''; | ||
} | ||
compile(str) { | ||
return function (...args) { | ||
return render(str, ...args); | ||
}; | ||
}, | ||
return result; | ||
}); | ||
} | ||
parse(str) { | ||
const matches = str.match(pattern); | ||
return { | ||
render, | ||
compile(str) { | ||
return function (...args) { | ||
return render(str, ...args); | ||
}; | ||
}, | ||
parse(str) { | ||
const matches = str.match(pattern); | ||
if (matches === null) { | ||
return false; | ||
} | ||
if (matches === null) { | ||
return false; | ||
} | ||
const parsed = []; | ||
const parsed = []; | ||
for (let i = 0; i < matches.length; i++) { | ||
if (!matches[i].match(/^\{\{.+\}\}$/g)) { | ||
parsed.push(matches[i].substring(1, matches[i].length - 1).trim()); | ||
} | ||
for (let i = 0; i < matches.length; i++) { | ||
if (!matches[i].match(/^\{\{.+\}\}$/g)) { | ||
parsed.push(matches[i].substring(1, matches[i].length - 1).trim()); | ||
} | ||
return parsed; | ||
} | ||
}; | ||
}(); | ||
export default template; | ||
return parsed; | ||
} | ||
}; | ||
export default main; |
{ | ||
"name": "@pluginjs/template", | ||
"title": "Plugin", | ||
"version": "0.2.19", | ||
"description": "A workflow for modern frontend development.", | ||
"author": "Creation Studio Limited", | ||
"homepage": "https://github.com/amazingSurge/plugin.js", | ||
"license": "GPL-v3", | ||
"main": "dist/template.js", | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"scripts": { | ||
"start": "gulp plugin", | ||
"build": "npm run prestart && gulp build", | ||
"deploy": "gulp deploy", | ||
"deploy:prepare": "gulp deploy:prepare", | ||
"test": "gulp test", | ||
"new": "cp -r ./plugins/sample ./plugins/$Component" | ||
}, | ||
"repository": { | ||
"url": "git@github.com:amazingSurge/plugin.js.git", | ||
"type": "git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/amazingSurge/plugin.js/issues" | ||
}, | ||
"engines": { | ||
"node": ">= 8", | ||
"npm": ">= 5" | ||
}, | ||
"category": "core", | ||
"min": "dist/template.min.js", | ||
"standalone": "dist/template.standalone.js", | ||
"module": "dist/template.esm.js", | ||
"dev-main": "src/main.js" | ||
"name": "@pluginjs/template", | ||
"description": "A workflow for modern frontend development.", | ||
"license": "GPL-3.0", | ||
"author": "Creation Studio Limited", | ||
"homepage": "https://github.com/pluginjs/pluginjs", | ||
"repository": { | ||
"url": "git@github.com:pluginjs/pluginjs.git", | ||
"type": "git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/pluginjs/pluginjs/issues" | ||
}, | ||
"version": "0.6.1", | ||
"category": "core", | ||
"main": "dist/template.umd.js", | ||
"module": "dist/template.esm.js", | ||
"source": "src/main.js", | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"scripts": { | ||
"build": "npm run build:js", | ||
"build:js": "plugin script build-js", | ||
"build:md": "plugin script build-md", | ||
"lint": "npm run lint:js", | ||
"lint:js": "eslint ./src/**/*.js --fix", | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"@pluginjs/utils": "^0.6.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.1.2", | ||
"@pluginjs/browserslist-config": "^1.1.1", | ||
"@pluginjs/cli": "^0.6.1", | ||
"babel-jest": "*", | ||
"jest": "*", | ||
"jest-extended": "*", | ||
"rollup": "*", | ||
"rollup-plugin-babel": "*", | ||
"rollup-plugin-commonjs": "*", | ||
"rollup-plugin-node-resolve": "*" | ||
}, | ||
"engines": { | ||
"node": ">= 8", | ||
"npm": ">= 5" | ||
}, | ||
"jest": { | ||
"setupTestFrameworkScriptFile": "jest-extended", | ||
"verbose": true, | ||
"testURL": "http://localhost", | ||
"testPathIgnorePatterns": [ | ||
"fixtures" | ||
] | ||
}, | ||
"browserslist": [ | ||
"extends @pluginjs/browserslist-config" | ||
], | ||
"title": "Plugin", | ||
"gitHead": "353b9f7a27eb7306aecd38b475a479616e7db55d" | ||
} |
import { getValueByPath } from '@pluginjs/utils' | ||
/* Credit to https://github.com/Matt-Esch/string-template MIT */ | ||
const template = (function() { | ||
const pattern = /\{\s*([.0-9a-zA-Z_]+)\s*\}/g | ||
const pattern = /\{\s*([.0-9a-zA-Z_]+)\s*\}/g | ||
function render(string, ...args) { | ||
if (args.length === 1 && typeof args[0] === 'object') { | ||
args = args[0] | ||
} | ||
function render(string, ...args) { | ||
if (args.length === 1 && typeof args[0] === 'object') { | ||
args = args[0] | ||
} | ||
if (!args || !args.hasOwnProperty) { | ||
args = {} | ||
} | ||
if (!args || !args.hasOwnProperty) { | ||
args = {} | ||
} | ||
return string.replace(pattern, (match, i, index) => { | ||
let result = null | ||
return string.replace(pattern, (match, i, index) => { | ||
let result = null | ||
if (string[index - 1] === '{' && string[index + match.length] === '}') { | ||
return i | ||
} | ||
if (string[index - 1] === '{' && string[index + match.length] === '}') { | ||
return i | ||
} | ||
if (args.hasOwnProperty(i)) { | ||
result = args[i] | ||
} else if (i.indexOf('.') !== -1) { | ||
result = getValueByPath(args, i) | ||
} | ||
if (Object.prototype.hasOwnProperty.call(args, i)) { | ||
result = args[i] | ||
} else if (i.indexOf('.') !== -1) { | ||
result = getValueByPath(args, i) | ||
} | ||
if (result === null || result === undefined) { | ||
return '' | ||
} | ||
if (result === null || typeof result === 'undefined') { | ||
return '' | ||
} | ||
return result | ||
}) | ||
} | ||
return result | ||
}) | ||
} | ||
return { | ||
render, | ||
compile(str) { | ||
return function(...args) { | ||
return render(str, ...args) | ||
} | ||
}, | ||
parse(str) { | ||
const matches = str.match(pattern) | ||
export default { | ||
render, | ||
compile(str) { | ||
return function(...args) { | ||
return render(str, ...args) | ||
} | ||
}, | ||
parse(str) { | ||
const matches = str.match(pattern) | ||
if (matches === null) { | ||
return false | ||
} | ||
if (matches === null) { | ||
return false | ||
} | ||
const parsed = [] | ||
for (let i = 0; i < matches.length; i++) { | ||
if (!matches[i].match(/^\{\{.+\}\}$/g)) { | ||
parsed.push(matches[i].substring(1, matches[i].length - 1).trim()) | ||
} | ||
const parsed = [] | ||
for (let i = 0; i < matches.length; i++) { | ||
if (!matches[i].match(/^\{\{.+\}\}$/g)) { | ||
parsed.push(matches[i].substring(1, matches[i].length - 1).trim()) | ||
} | ||
} | ||
return parsed | ||
} | ||
return parsed | ||
} | ||
})() | ||
export default template | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
0
1
102
9401
1
10
5
166
2
+ Added@pluginjs/utils@^0.6.1
+ Added@pluginjs/is@0.6.5(transitive)
+ Added@pluginjs/utils@0.6.5(transitive)