Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

block

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

block - npm Package Compare versions

Comparing version 0.0.5 to 0.1.0

62

index.js

@@ -1,3 +0,1 @@

var regex = /(\{\{\s*\w+\s*\}\})/
module.exports = Block

@@ -9,33 +7,19 @@

var blocks = this.blocks = string.split(regex)
var names = this.names = {}
var block
for (var i = 0, l = blocks.length; i < l; i++)
if (regex.test(block = blocks[i]))
names[i] = block.match(/(\w+)/)[0]
this.string = string
}
Block.prototype.locals =
Block.prototype.local = function (name, value) {
var names = this.names
var j
if (typeof name === 'object')
Object.keys(name).forEach(function (key) {
this.replace(key, name[key])
}, this)
else
this.replace(name, value)
for (var i in names)
if (names[i] === name && names.hasOwnProperty(i))
j = i
if (j == null)
throw new Error('Name ' + name + ' is not defined.')
delete names[j]
this.blocks[j] = value || ''
return this
}
Block.prototype.locals = function (object) {
for (var name in object)
if (object.hasOwnProperty(name))
this.local(name, object[name])
Block.prototype.replace = function (key, value) {
this.string = replace(this.string, key, value)

@@ -46,14 +30,11 @@ return this

Block.prototype.render = function (locals) {
locals = locals || {}
if (typeof locals === 'object') {
var string = this.string
Object.keys(locals).forEach(function (key) {
string = replace(string, key, locals[key])
})
return string
}
var blocks = this.blocks
var names = this.names
var html = ''
var name
for (var i = 0, l = blocks.length; i < l; i++)
html += (name = names[i]) ? locals[name] : blocks[i]
return html
return this.string
}

@@ -70,1 +51,8 @@

} catch (err) {}
function replace(string, key, value) {
return string.replace(
new RegExp('\\{\\{\\s*' + key + '\\s*\\}\\}', 'g'),
value
)
}
{
"name": "block",
"description": "Block-based HTML templating",
"version": "0.0.5",
"version": "0.1.0",
"devDependencies": {

@@ -27,2 +27,2 @@ "mocha": "*",

"license": "MIT"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc