Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
npm install koa-jade --save
var koa = require('koa')
var jade = require('koa-jade')
var app = koa()
app.use(jade.middleware({
viewPath: __dirname + '/views',
debug: false,
pretty: false,
compileDebug: false,
locals: global_locals_for_all_pages,
basedir: 'path/for/jade/extends',
helperPath: [
'path/to/jade/helpers',
{ random: 'path/to/lib.js' },
{ _: require('lodash') }
]
}))
app.use(function* () {
this.render('index', locals_for_this_page, true)
})
app.listen(3000)
Normal function vs. generator function:
iojs 1.6.4
Normal function x 163,231 ops/sec ±1.33% (180 runs sampled)
Generator function x 74,904 ops/sec ±1.86% (173 runs sampled)
Fastest is Normal function
viewPath
: where Jade templates be stored. Default is process.cwd()
.
pretty
and compileDebug
: see Jade's docs. Default is false
.
debug
: shorthand for pretty
and compileDebug
. Default is false
.
locals
: variables that will be passed to Jade templates.
noCache
: use cache or not. Cache could make template rendering 100x faster than without cache. It useful for production, but useless for development (pages would not be updated untill Koa restarted). In most case, noCache: process.env === 'development'
should be enough. If wanna control it in production for specific page, use render()
's noCache
instead.
helperPath
: String or Array, where to load helpers, and make them available on all .jade
. In Array, you can use object to assgin name for module, eg: { random: './path/to/random.js' }
.
basedir
: help Jade to identify paths when using extends
with absolute
paths.
Configure and create a middleware.
Render template, and set rendered template to this.body
.
tpl
: the path of template that based on viewPath
, .jade
is optional.
locals
: locals for this page. Optional. If options
or noCache
presented, please use {}
, undefined
or null
for empty locals
.
options
: override global default options for this page. Only assigning an object
or a boolean
to it will take effects.
noCache
: use cache or not. Notes: 1. overrides global noCache
; 2. won't affect other pages.
If options
is set to true
or false
, it will be treated as noCache
, and noCache
will be ignored. For example, render(tpl, locals, true)
equals to render(tpl, locals, {}, true)
, and render(tpl, locals, true, false)
will skip cache and re-compile template.
options
and noCache
are optional.
If you encounter this error, Error: the "basedir" option is required to use "extends" with "absolute" paths
, try to set basedir
like this:
app.use(jade.middleware({
viewPath: 'path/to/views',
basedir: 'path/for/jade/extends'
}))
or
app.use(function* () {
this.render('index', locals, { basedir: 'path/for/jade/extends' })
})
Koa-jade sets content-type
to text/html
automatically. if wanna change it, do like this:
this.render('index')
this.type = 'text/plain'
By setting helperPath
, koa-jade will load all the modules that under sepecified folxder, and make them available on all templates.
helperPath
also could be an array including folders, files path, even moduleName: 'path/to/lib.js
mapping object. Also support node module as a helper, just like: '_': require('lodash')
// format-date.js
module.exports = function (input) {
if (input instanceof Date) {
return (input.getMonth() + 1) + '/' + input.getDate() + '/' + input.getFullYear()
}
return input
}
It equals to:
// whatever.js
module.exports = {
moduleName: 'formatDate',
moduleBody: function (input) {
if (input instanceof Date) {
return (input.getMonth() + 1) + '/' + input.getDate() + '/' + input.getFullYear()
}
return input
}
}
In Jade:
p= formatDate(new Date())
koa-jade
resolves viewsFor example, there's a folder structure like this:
- views
|--- foo.jade
|--- foo/
|--- index.jade
|--- bar/
|--- index.jade
|--- baz
For this.render('foo')
, koa-jade
will render foo.jade
, not foo/index.jade
(file has higher priority than directory). If you wanna render foo/index.jade
, you have to use explicit path: this.render('foo/index')
.
For this.render('bar')
, because bar.jade
doesn't exist and bar
is a directory, koa-jade
will search for bar/index.jade
and try to render it.
For this.render('baz')
, because baz
is a file, and not end with .jade
, koa-jade
will throw an ENOENT
error.
Via GitHub
FAQs
A Jade middleware for Koa
The npm package koa-jade receives a total of 6 weekly downloads. As such, koa-jade popularity was classified as not popular.
We found that koa-jade 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.