Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@smarterservices/hapi-json-view
Advanced tools
Readme
A view engine for the hapi framework.
npm install --save @ideapod/hapi-json-view
server.js:
const Hapi = require('hapi');
const HapiJsonView = require('@ideapod/hapi-json-view');
const Path = require('path');
const Vision = require('vision');
const server = new Hapi.Server();
server.connection({ port: 8080 });
server.register(Vision, (err) => {
if (err) throw err;
server.views({
engines: {
js: {
module: HapiJsonView.create(),
contentType: 'application/json',
}
},
path: Path.join(__dirname, 'templates'),
});
server.route({
method: 'GET',
path: '/article',
handler: function(request, reply) {
const article = {
_id: '507f1f77bcf86cd799439011',
title: 'Node.js',
author: {
_id: '507f191e810c19729de860ea',
name: 'John Doe',
},
};
reply.view('article', { article: article });
},
});
});
templates/article.js:
json.set('title', article.title);
json.set('author', (json) => {
json.set('name', article.author.name);
});
This template generates the following object:
{
title: 'Node.js',
author: {
name: 'John Doe'
}
}
It assigns a value to a key.
json.set('title', 'Node.js');
// => { title: 'Node.js' }
The value can be a function. If json.set()
is called with a key, it creates an object:
json.set('author', (json) => {
json.set('name', 'John Doe');
});
// => { author: { name: 'John Doe' } }
If json.set()
is called without a key, it assign the value to the parent key:
json.set('title', (json) => {
json.set('Node.js');
});
// => { title: 'Node.js' }
It creates a new array by iterating through an existing array:
const numbers = ['one', 'two'];
json.set('numbers', json.array(numbers, (json, number) => {
json.set('number', number);
}));
// => { numbers: [{ number: 'one' }, { number: 'two' }] }
It extracts values from an object and assigns them to the result object:
const numbers = { one: 'one', two: 'two', three: 'three' };
json.extract(numbers, ['two', 'three']);
// => { two: 'two', three: 'three' }
Helpers can be registered through the engine configuration:
const Hapi = require('hapi');
const HapiJsonView = require('@ideapod/hapi-json-view');
const Path = require('path');
const Vision = require('vision');
const server = new Hapi.Server();
server.connection({ port: 8080 });
server.register(Vision, (err) => {
if (err) throw err;
server.views({
engines: {
js: {
module: HapiJsonView.create(),
contentType: 'application/json',
}
},
path: Path.join(__dirname, 'templates'),
helpersPath: Path.join(__dirname, 'templates/helpers'),
});
});
They can then be used by their name:
json.set('title', json.helper('uppercase', article.title));
Partials can be registered through the engine configuration:
const Hapi = require('hapi');
const HapiJsonView = require('@ideapod/hapi-json-view');
const Path = require('path');
const Vision = require('vision');
const server = new Hapi.Server();
server.connection({ port: 8080 });
server.register(Vision, (err) => {
if (err) throw err;
server.views({
engines: {
js: {
module: HapiJsonView.create(),
contentType: 'application/json',
}
},
path: Path.join(__dirname, 'templates'),
partialsPath: Path.join(__dirname, 'templates/partials'),
});
});
They can then be used by their name:
json.set('author', json.partial('author', { author: article.author }));
FAQs
JSON view engine for hapi.
The npm package @smarterservices/hapi-json-view receives a total of 2 weekly downloads. As such, @smarterservices/hapi-json-view popularity was classified as not popular.
We found that @smarterservices/hapi-json-view demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.