diff --git a/index.js b/index.js new file mode 100644 index 0000000..259c15f --- /dev/null +++ b/index.js @@ -0,0 +1,31 @@ +exports.printVersion = () => { + console.log('Staples v0.0.1') +} + +exports.compile = (template, input) => { + let index = 0 + + while(index < template.length) { + const nextOpen = template.indexOf('{{', index + 1) + if(nextOpen == index || nextOpen == -1) { + index = template.length + } else { + index = nextOpen + const nextClose = template.indexOf('}}', index + 1) + if(nextClose == index || nextClose == -1) { + index = template.length + } else { + index = nextOpen+2 + const tagContent = template.substring(nextOpen+2, nextClose) + const tagContentSplit = tagContent.split('.') + let varLevel = input + tagContentSplit.forEach( (level) => { + const isIndex = Number.isInteger(parseInt(level)) + varLevel = isIndex ? varLevel[parseInt(level)] : varLevel[level] + }) + template = template.replace(tagContent, varLevel) + } + } + } + console.log(template) +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..280747a --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "@dslak/staples", + "version": "0.0.35", + "description": "Lightweight handlebars replacement for Angular", + "main": "index.js", + "scripts": { + "login": "npm login", + "publish": "npm publish --access public", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://git.dslak.it/dslak/staples.git" + }, + "keywords": [ + "brackets", + "handlebars", + "mustaches" + ], + "author": "Dslak", + "license": "ISC" +}