New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pxr

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pxr - npm Package Compare versions

Comparing version 5.0.0 to 6.0.0

.nvmrc

15

lib/core.js
'use strict';
var _ = require('lodash');
var Hogan = require('./hogan.js');
var async = require('async');
var urlLib = require('url');
function escapeVariables(obj) {
return Object.keys(obj)
.map(function (k){
return [k.replace(/\./g, '::'), obj[k]];
})
.reduce(function (acc, values) {
acc[values[0]] = values[1];
return acc;
}, {});
}
function render(text, data) {
if (!text) { return ''; }
var output = Hogan.compile(text).render(escapeVariables(data));
const template = (str, obj) => str.replace(/\${(.*?)}/g, (x,g)=> obj[g]);
const output = template(text, data);
return output;

@@ -23,0 +12,0 @@ }

@@ -164,4 +164,3 @@ var _ = require('lodash');

if((Date.now() - timeoutStart) > timeout) {
var errorMsg = 'Timeout exceeded, failed to respond in <%= timeout %>ms.',
error = _.template(errorMsg)({timeout:timeout});
var error = `Timeout exceeded, failed to respond in ${timeout}ms.`;
for (i = 0, len = state.fragmentOutput.length; i < len; i++) {

@@ -174,3 +173,3 @@ if(!state.fragmentOutput[i].done && state.fragmentOutput[i].attribs && state.fragmentOutput[i].attribs['cx-url']) {

} else {
setImmediate(checkDone);
setTimeout(checkDone, 0);
}

@@ -177,0 +176,0 @@ }

{
"name": "pxr",
"version": "5.0.0",
"version": "6.0.0",
"description": "HTML transformation library built on top of HTMLParser2, used by Compoxure.",

@@ -28,2 +28,3 @@ "main": "index.js",

"htmlparser2": "^3.7.3",
"kbn-handlebars": "^1.0.0",
"lodash": "~4.17.11"

@@ -30,0 +31,0 @@ },

@@ -5,9 +5,4 @@ module.exports = {

If: require('./lib/plugins/if'),
Bundle: require('./lib/plugins/bundle'),
Image: require('./lib/plugins/image'),
Content: require('./lib/plugins/content'),
ContentItem: require('./lib/plugins/content-item'),
Direct: require('./lib/plugins/direct'),
DefineSlot: require('./lib/plugins/define-slot'),
Library: require('./lib/plugins/library')
DefineSlot: require('./lib/plugins/define-slot')
};

@@ -29,3 +29,3 @@ 'use strict';

it('should parse test attributes', function(done) {
var input = "<html><div id='test' cx-test='{{environment:name}}'></div></html>";
var input = "<html><div id='test' cx-test='${environment:name}'></div></html>";
parxer({

@@ -32,0 +32,0 @@ plugins: [

@@ -12,3 +12,3 @@ 'use strict';

it('should parse if attributes and retain block if true', function(done) {
var input = "<html><div id='if' cx-if='{{server:name}}' cx-if-value='http://www.google.com'><h1>Hello</h1><span id='stillhere'>Rah!</span></div></html>";
var input = "<html><div id='if' cx-if='${server:name}' cx-if-value='http://www.google.com'><h1>Hello</h1><span id='stillhere'>Rah!</span></div></html>";
parxer({

@@ -29,3 +29,3 @@ plugins: [

it('should parse if attributes and remove block if false', function(done) {
var input = "<html><div id='if' cx-if='{{server:name}}' cx-if-value='http://www.tes.com'><h1>Hello</h1><span id='stillhere'>Rah!</span></div></html>";
var input = "<html><div id='if' cx-if='${server:name}' cx-if-value='http://www.tes.com'><h1>Hello</h1><span id='stillhere'>Rah!</span></div></html>";
parxer({

@@ -47,3 +47,3 @@ plugins: [

it('should parse if attributes and allow block if false, removing block if cx-replace-outer', function(done) {
var input = "<html><div id='if' cx-replace-outer='true' cx-if='{{environment:name}}' cx-if-value='test'><h1>Hello</h1><br/><!-- hello --><span id='stillhere'>Rah!</span></div></html>";
var input = "<html><div id='if' cx-replace-outer='true' cx-if='${environment:name}' cx-if-value='test'><h1>Hello</h1><br/><!-- hello --><span id='stillhere'>Rah!</span></div></html>";
parxer({

@@ -64,3 +64,3 @@ plugins: [

it('should parse if attributes and allow block if false, removing block if cx-replace-outer (using custom tag)', function(done) {
var input = "<html><compoxure id='if' cx-if='{{environment:name}}' cx-if-value='test'><h1>Hello</h1><br/><!-- hello --><span id='stillhere'>Rah!</span></compoxure></html>";
var input = "<html><compoxure id='if' cx-if='${environment:name}' cx-if-value='test'><h1>Hello</h1><br/><!-- hello --><span id='stillhere'>Rah!</span></compoxure></html>";
parxer({

@@ -81,3 +81,3 @@ plugins: [

it('should parse if attributes and retain block if true, including url declarations', function(done) {
var input = "<html><div id='if' cx-if='{{server:name}}' cx-if-value='http://www.google.com'><div cx-url='{{server:name}}'></div></div></html>";
var input = "<html><div id='if' cx-if='${server:name}' cx-if-value='http://www.google.com'><div cx-url='${server:name}'></div></div></html>";
parxer({

@@ -97,24 +97,2 @@ plugins: [

it('should parse bundle attributes within if blocks', function(done) {
var input = "<html><div id='if' cx-replace-outer='true' cx-if='{{server:name}}' cx-if-value='http://www.google.com'><div id='bundle' cx-bundles='service-name/top.js'></div></div></html>";
parxer({
plugins: [
require('../Plugins').If,
require('../Plugins').Bundle(function(fragment, next) { next(null, fragment.attribs['cx-url']); })
],
cdn: {
url: 'http://base.url.com/'
},
environment: 'test',
variables: {
'static:service-name':'50',
'server:name':'http://www.google.com'
}
}, input, function(err, fragmentCount, data) {
var $ = cheerio.load(data);
expect($('#bundle script')[0].attribs.src).to.be('http://base.url.com/service-name/50/js/top.js');
done();
});
});
});

@@ -12,3 +12,3 @@ 'use strict';

it('should parse url attributes', function (done) {
var input = "<html><div id='url' cx-url='{{server:name}}'>I am some default text</div></html>";
var input = "<html><div id='url' cx-url='${server:name}'>I am some default text</div></html>";
parxer({

@@ -29,3 +29,3 @@ plugins: [

it('should parse url attributes and replace complex default html as well as text', function (done) {
var input = "<html><div id='url' cx-url='{{server:name}}'><!-- comment --><h1>I am some default text</h1><span>Hello</span></div></html>";
var input = "<html><div id='url' cx-url='${server:name}'><!-- comment --><h1>I am some default text</h1><span>Hello</span></div></html>";
parxer({

@@ -46,3 +46,3 @@ plugins: [

it('should parse a mixture of attributes in a bigger document', function (done) {
var input = "<html><div id='test' cx-test='{{environment:name}}'></div><div id='url' cx-url='{{server:name}}'>I am some default text</div></html>";
var input = "<html><div id='test' cx-test='${environment:name}'></div><div id='url' cx-url='${server:name}'>I am some default text</div></html>";
parxer({

@@ -66,3 +66,3 @@ plugins: [

it('should allow you to define your own prefix', function (done) {
var input = "<html><div id='url' data-my-url='{{server:name}}'></div></html>";
var input = "<html><div id='url' data-my-url='${server:name}'></div></html>";
parxer({

@@ -84,3 +84,3 @@ prefix: 'data-my-',

it('should deal with managing overall timeout', function (done) {
var input = "<html><div id='url' cx-url='{{server:name}}'></div></html>";
var input = "<html><div id='url' cx-url='${server:name}'></div></html>";
parxer({

@@ -102,3 +102,3 @@ parserTimeout: 20,

it('should deal with a service that returns an error', function (done) {
var input = "<html><div id='url' cx-url='{{server:name}}'>Default Content</div></html>";
var input = "<html><div id='url' cx-url='${server:name}'>Default Content</div></html>";
parxer({

@@ -121,3 +121,3 @@ timeout: 100,

it('should replace outer when specified with url', function (done) {
var input = "<html><div id='url'><div cx-replace-outer='true' cx-url='{{server:name}}'>I am some default text</div></div></html>";
var input = "<html><div id='url'><div cx-replace-outer='true' cx-url='${server:name}'>I am some default text</div></div></html>";
parxer({

@@ -138,3 +138,3 @@ plugins: [

it('should replace outer when specified with url (with custom tag)', function (done) {
var input = "<html><div id='url'><compoxure cx-url='{{server:name}}'>I am some default text</compoxure></div></html>";
var input = "<html><div id='url'><compoxure cx-url='${server:name}'>I am some default text</compoxure></div></html>";
parxer({

@@ -155,3 +155,3 @@ plugins: [

it('should deal with a service that returns an error but show default text if configured to', function (done) {
var input = "<html><div id='url' cx-url='{{server:name}}'><h1>Default Content</h1><span>More content</span></div></html>";
var input = "<html><div id='url' cx-url='${server:name}'><h1>Default Content</h1><span>More content</span></div></html>";
parxer({

@@ -174,3 +174,3 @@ timeout: 100,

it('should deal with a service that returns an error but show default html if configured to', function (done) {
var input = "<html><div id='url' cx-url='{{server:name}}'><h1>HTML</h1><div>Hello</div></div></html>";
var input = "<html><div id='url' cx-url='${server:name}'><h1>HTML</h1><div>Hello</div></div></html>";
parxer({

@@ -194,3 +194,3 @@ timeout: 100,

it('should deal with a service that returns an error but show default html if configured to and replace outer', function (done) {
var input = "<html><div id='wrapper'><div id='url' cx-replace-outer='true' cx-url='{{server:name}}'><h1>HTML</h1><div>Hello</div></div></div></html>";
var input = "<html><div id='wrapper'><div id='url' cx-replace-outer='true' cx-url='${server:name}'><h1>HTML</h1><div>Hello</div></div></div></html>";
parxer({

@@ -214,3 +214,3 @@ timeout: 100,

it('should deal with a service that returns an error but show default html if configured to and survive malformed html', function (done) {
var input = "<html><div id='wrapper'><div id='url' cx-replace-outer='true' cx-url='{{server:name}}'><h1>HTML<div>Hello</div></div></html>";
var input = "<html><div id='wrapper'><div id='url' cx-replace-outer='true' cx-url='${server:name}'><h1>HTML<div>Hello</div></div></html>";
parxer({

@@ -233,3 +233,3 @@ timeout: 100,

it('should return stats about the fragments in the page', function (done) {
var input = "<html><div id='url' cx-url='{{server:name}}'>I am some default text</div></html>";
var input = "<html><div id='url' cx-url='${server:name}'>I am some default text</div></html>";
parxer({

@@ -250,3 +250,3 @@ plugins: [

it('should parse url attributes and return the first one', function (done) {
var input = "<html><div id='url' cx-url-1='{{server:name}}' cx-url-2='{{server:name2}}' cx-strategy='first-non-empty'>I am some default text</div></html>";
var input = "<html><div id='url' cx-url-1='${server:name}' cx-url-2='${server:name2}' cx-strategy='first-non-empty'>I am some default text</div></html>";
parxer({

@@ -268,3 +268,3 @@ plugins: [

it('should parse url attributes and return all of them', function (done) {
var input = "<html><div id='url' cx-url-1='{{server:name}}' cx-url-2='{{server:name2}}'>I am some default text</div></html>";
var input = "<html><div id='url' cx-url-1='${server:name}' cx-url-2='${server:name2}'>I am some default text</div></html>";
parxer({

@@ -286,3 +286,3 @@ plugins: [

it('should parse url attributes and return all them (2)', function (done) {
var input = "<html><div id='url' cx-url-1='{{server:name}}' cx-url-2='{{server:name2}}' cx-strategy='first-non-empty'>I am some default text</div></html>";
var input = "<html><div id='url' cx-url-1='${server:name}' cx-url-2='${server:name2}' cx-strategy='first-non-empty'>I am some default text</div></html>";
var contents = {

@@ -308,3 +308,3 @@ 'http://www.abc.com': ' ',

it('should parse url attributes and return the first non empty (we consider space to be empty)', function (done) {
var input = "<html><div id='url' cx-url-1='{{server:name}}' cx-url-2='{{server:name2}}'>I am some default text</div></html>";
var input = "<html><div id='url' cx-url-1='${server:name}' cx-url-2='${server:name2}'>I am some default text</div></html>";
var contents = {

@@ -311,0 +311,0 @@ 'http://www.abc.com': ' ',

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc