
Security News
curl Shuts Down Bug Bounty Program After Flood of AI Slop Reports
A surge of AI-generated vulnerability reports has pushed open source maintainers to rethink bug bounties and tighten security disclosure processes.
parse-blocks
Advanced tools
Parse basic template blocks in a string, like Handlebars block expressions but returns an object. Delimiters are customizable.
Parse basic template blocks in a string, like Handlebars block expressions but returns an object. Delimiters are customizable.
npm i parse-blocks --save
npm test
var blocks = require('parse-blocks');
Given the following arbitrary blocks in fixtures/c.txt:
{{#definedoc "foo" a.b}}
This is content foo
{{/definedoc}}
{{#definedoc "bar" a.c}}
This is content bar
{{/definedoc}}
{{#definedoc "baz" a.d}}
This is content baz
{{/definedoc}}
The following:
var str = fs.readFileSync('fixtures/c.txt', 'utf8');
console.log(blocks(str));
Results in:
{ definedoc:
{ foo:
{ args: [ 'a.b' ],
content: 'This is content foo',
orig:
[ '{{#definedoc "foo" a.b}}',
'This is content foo',
'{{/definedoc}}' ] },
bar:
{ args: [ 'a.c' ],
content: 'This is content bar',
orig:
[ '{{#definedoc "bar" a.c}}',
'This is content bar',
'{{/definedoc}}' ] },
baz:
{ args: [ 'a.d' ],
content: 'This is content baz',
orig:
[ '{{#definedoc "baz" a.d}}',
'This is content baz',
'{{/definedoc}}' ] } } }
Context can be passed as thisArg when three arguments are passed, and/or on options.locals.
Example
blocks(str, {locals: {a: {name: 'AAA'}}});
And this block:
{{#apidoc "aaa" a}}
This is content <%= name %>
{{/apidoc}}
Results in the following object:
{ apidoc:
{ aaa:
{ args: [ 'a' ],
context: { name: 'AAA' },
content: 'This is content <%= name %>',
orig:
[ '{{#apidoc "aaa" a}}',
'This is content <%= name %>',
'{{/apidoc}}' ] }
The content can now be used to pass to any template engine with context as locals.
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright (c) 2014 Jon Schlinkert
Released under the MIT license
This file was generated by verb on December 02, 2014.
FAQs
Parse basic template blocks in a string, like Handlebars block expressions but returns an object. Delimiters are customizable.
We found that parse-blocks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A surge of AI-generated vulnerability reports has pushed open source maintainers to rethink bug bounties and tighten security disclosure processes.

Product
Scan results now load faster and remain consistent over time, with stable URLs and on-demand rescans for fresh security data.

Product
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.