
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Moduled and Embedded JavaScript templates, run in node.js and all browsers.
includeimport(Moduled)layout in server side<%: 'Scriptlet' tag, for control-flow, no output<%_: 'Whitespace Slurping' Scriptlet tag, strips all whitespace before it<%=: Outputs the value into the template (escaped)<%-: Outputs the unescaped value into the template<%#: Comment tag, no execution, no output<%%: Outputs a literal '<%'%%>: Outputs a literal '%>'%>: Plain ending tag-%>: Trim-mode ('newline slurp') tag, trims following newline_%>: 'Whitespace Slurping' ending tag, removes all whitespace after itImplementations:
npm install mejs
const mejsCompile = require('mejs')
Mejs ClassCompile ejs templates to a Mejs Class.
patternOrMejsfile: Glob pattern to read template files. Or mejs file object.options.glob: Glob optionsoptions.base: Everything before a glob (same as tplName) starts.options.delimiter: Character to use with angle brackets for open/close, default is %.options.rmWhitespace: Remove all safe-to-remove whitespace, including leading and trailing whitespace in compiling. It also enables a safer version of -%> line slurping for all scriptlet tags (it does not strip new lines of tags in the middle of a line).options.rmComment: Remove comment before compiling (/<!--([\s\S]*?)-->/g).options.rmLinefeed: Remove linefeed and trailing whitespace before compiling (/\n+[\s]*/g).const Mejs = mejsCompile('views/**/*.html') // options.base == 'views/'
mejs objectmejs object have renderEx method that support layout, it is useful in server side.
pattern: pattern is same as above.options: options is same as above, and have options.locals, options.layout and options.sandbox apply for Mejs class.View classIt is implemented for express. arguments is same as mejsCompile.initMejs.
const app = express()
app.set('view', mejs.initView('views/**/*.ejs', {
layout: 'layout',
locals: app.locals
}))
//... render with layout
res.render('index', {user: req.user})
//... disable layout for 'login' view
res.render('login', {layout: false})
mejs file objectPrecompile ejs templates to a file object, then you can write it to a JS file.
files: Template files array, the file in array must have path and contents.options: options is same as above. but one more:
options.mini: Precompile a minimum templates module, it is not a Mejs class, should be imported to Mejs class by Mejs.importconst mejsSource = mejsCompile.precompile([{
path: 'index.html',
contents: 'index content...'
}, {
path: 'layout.html',
contents: 'layout content...'
}, {
path: 'lib/index',
contents: 'lib index content...'
}
], {base: 'views'})
mejs file objectPrecompile ejs teamplates to a file object, then you can write it to a JS file.
pattern: glob pattern.options: options is same as above.const mejsSource = mejsCompile.precompileFromGlob('views/**/*.js', {base: 'views'})
Ejs template engine.
mejs file Class. It is similar to vinyl, AKA gulp file
mejs objectlocals: global locals object, default is {}.// add config, moment and node-i18n to global locals
const mejs = new Mejs({
config: {
host: 'www.mejs.com',
apiHost: 'www.mejs.com/api'
},
moment: moment,
locale: function() {
return this.locale
},
__: function() {
return this.__.apply(this, arguments)
}
})
Import templates to global from a templates module.
const Mejs = require('Mejs')
const tplsA = require('tplsA')
const tplsB = require('tplsB')
Mejs.import(tplsA).import(tplsB)
Render a template with data
tplName: a full template namedata: data object filled to templatemejs.render('index', userObj)
mejs.render('global/header', headerDate)
//...
import another mejs object object to mejs, then mejs will have the templates that from mejsX.
namespace: namespace stringmejsX: mejs object for importmejs.import('common', mejsA)
Add a template function to current mejs.
Get a template function from current mejs.
Remove a template function from current mejs.
Resolve template path.
escape function for templates function. You can overwrite it.
FAQs
Moduled and Embedded JavaScript templates, run in node.js and all browsers
The npm package mejs receives a total of 5 weekly downloads. As such, mejs popularity was classified as not popular.
We found that mejs 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.