Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
edge-parser
Advanced tools
This repo is the parser to convert edge templates inside a self invoked Javascript function. Later you can invoke this function by providing a context.
Example:
Input
Hello {{ username }}
Output
(function (ctx) {
let out = ''
out += 'Hello '
out += `${ctx.escape(ctx.resolve('username'))}`
out += '\n'
return out
})(ctx)
Notice of use of ctx
in the function body. Parser doesn't provide the implementation of ctx
, the runtime of template engine should provide it.
The following expressions are supported by the parser.
The identifier is wrapped inside ctx.resolve
. The resolve
method job is to resolve the value.
In following statement username
is the identifier
Hello {{ username }}
A string literal
Hello {{ 'Guest' }}
The [1, 2, 3, 4]
is an array expression.
Evens are {{
[1, 2, 3, 4].filter((num) => num % 2 === 0)
}}
The { username: 'virk' }
is an Object expression
{{ toJSON({ username: 'virk' }) }}
Following are examples of UnaryExpression
.
{{ typeof(username) }}
{{ !!username }}
Here {{ 2 + 2 }}
is the binary expression
{{ 2 + 2 }} = 4
Following is the example of LogicalExpression
.
{{ username || admin.username }}
{{ username.toUpperCase() }}
{{ username ? username : 'Guest' }}
{{ upper(username) }}
Sequence is not supported in mustache blocks and instead used inside tags. For example:
Everything inside ()
is a sequence expression.
@component('button', text = 'Submit', type = 'Primary')
{{ Hello `${username}` }}
{{
users.map((user) => {
return user.username
})
}}
Context must have following methods to work with the core parser.
class Context {
// Resolve value for a key
resolve(key: string): any
// make input HTML safe
escape (input: string): string
}
FAQs
Parser for edge template engine
The npm package edge-parser receives a total of 10,515 weekly downloads. As such, edge-parser popularity was classified as popular.
We found that edge-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.