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

preact-render-to-string

Package Overview
Dependencies
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

preact-render-to-string - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

.eslintrc

60

dist/index.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('pretty-format')) :
typeof define === 'function' && define.amd ? define(['pretty-format'], factory) :
(global.preactRenderToString = factory(global.prettyFormat));
}(this, function (prettyFormat) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.preactRenderToString = factory());
}(this, function () {
prettyFormat = 'default' in prettyFormat ? prettyFormat['default'] : prettyFormat;
var NON_DIMENSION_PROPS = {
boxFlex: 1, boxFlexGroup: 1, columnCount: 1, fillOpacity: 1, flex: 1, flexGrow: 1,
flexPositive: 1, flexShrink: 1, flexNegative: 1, fontWeight: 1, lineClamp: 1, lineHeight: 1,
opacity: 1, order: 1, orphans: 1, strokeOpacity: 1, widows: 1, zIndex: 1, zoom: 1
};
var SHALLOW = { shallow: true };
var ESC = {

@@ -18,14 +20,2 @@ '<': '&lt;',

var EMPTY = {};
var VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
var NON_DIMENSION_PROPS = {
boxFlex: 1, boxFlexGroup: 1, columnCount: 1, fillOpacity: 1, flex: 1, flexGrow: 1,
flexPositive: 1, flexShrink: 1, flexNegative: 1, fontWeight: 1, lineClamp: 1, lineHeight: 1,
opacity: 1, order: 1, orphans: 1, strokeOpacity: 1, widows: 1, zIndex: 1, zoom: 1
};
var UNNAMED = [];
var objectKeys = Object.keys || function (obj) {

@@ -101,15 +91,10 @@ var keys = [];

var preactPlugin = {
test: function (object) {
return object && typeof object === 'object' && 'nodeName' in object && 'attributes' in object && 'children' in object && !('nodeType' in object);
},
print: function (val, print, indent) {
return renderToString(val, preactPlugin.context, preactPlugin.opts, true);
}
};
var SHALLOW = { shallow: true };
var prettyFormatOpts = {
plugins: [preactPlugin]
};
var UNNAMED = [];
var EMPTY = {};
var VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
renderToString.render = renderToString;

@@ -177,14 +162,5 @@

if (opts.jsx) {
if (typeof v !== 'string') {
preactPlugin.context = context;
preactPlugin.opts = opts;
v = prettyFormat(v, prettyFormatOpts);
if (~v.indexOf('\n')) {
v = indent('\n' + v, indentChar) + '\n';
}
s += indent('\n' + name + '={' + v + '}', indentChar);
} else {
s += '\n' + indentChar + name + '="' + encodeEntities(v) + '"';
}
var hooked = opts.attributeHook && opts.attributeHook(name, v, context, opts);
if (hooked) {
s += hooked;
continue;

@@ -191,0 +167,0 @@ }

{
"name": "preact-render-to-string",
"amdName": "preactRenderToString",
"version": "3.0.0",
"version": "3.0.1",
"description": "Render JSX to an HTML string, with support for Preact components.",

@@ -9,3 +9,5 @@ "main": "dist/index.js",

"scripts": {
"build": "rollup -c rollup.config.js -m ${npm_package_main}.map -f umd -n $npm_package_amdName $npm_package_jsnext_main -o $npm_package_main",
"build": "npm run -s transpile && npm run -s transpile:jsx",
"transpile": "rollup -c rollup.config.js -m ${npm_package_main}.map -f umd -n $npm_package_amdName $npm_package_jsnext_main -o $npm_package_main",
"transpile:jsx": "ENTRY=jsx rollup -c rollup.config.js -m dist/jsx.js.map -f umd -n $npm_package_amdName src/jsx.js -o dist/jsx.js",
"test": "eslint {src,test} && mocha --compilers js:babel-register test/**/*.js",

@@ -46,8 +48,10 @@ "prepublish": "npm run build",

"chai": "^3.5.0",
"eslint": "^3.1.1",
"eslint": "^3.2.2",
"mocha": "^3.0.0",
"preact": "^5.5.0",
"rollup": "^0.34.2",
"rollup": "^0.34.3",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-commonjs": "^3.3.1",
"rollup-plugin-memory": "^1.0.0",
"rollup-plugin-node-resolve": "^2.0.0",
"sinon": "^1.17.5",

@@ -54,0 +58,0 @@ "sinon-chai": "^2.8.0"

import fs from 'fs';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import memory from 'rollup-plugin-memory';

@@ -7,4 +9,6 @@ import babel from 'rollup-plugin-babel';

let entry = process.env.ENTRY || 'index';
export default {
entry: 'src/index.js',
entry: 'src/'+entry+'.js',
exports: 'default',

@@ -15,5 +19,10 @@ useStrict: false,

memory({
path: 'src/index.js',
contents: "export { default } from './index';"
path: 'src/'+entry+'.js',
contents: "export { default } from './"+entry+"';"
}),
nodeResolve({
skip: ['preact'],
main: true
}),
commonjs(),
babel({

@@ -20,0 +29,0 @@ babelrc: false,

@@ -1,11 +0,7 @@

import prettyFormat from 'pretty-format';
import { objectKeys, encodeEntities, falsey, memoize, indent, isLargeString, styleObjToCss, assign, getNodeProps } from './util';
const SHALLOW = { shallow: true };
const ESC = {
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
'&': '&amp;'
};
// components without names, kept as a hash for later comparison to return consistent UnnamedComponentXX names.
const UNNAMED = [];

@@ -31,78 +27,3 @@ const EMPTY = {};

// DOM properties that should NOT have "px" added when numeric
export const NON_DIMENSION_PROPS = {
boxFlex:1, boxFlexGroup:1, columnCount:1, fillOpacity:1, flex:1, flexGrow:1,
flexPositive:1, flexShrink:1, flexNegative:1, fontWeight:1, lineClamp:1, lineHeight:1,
opacity:1, order:1, orphans:1, strokeOpacity:1, widows:1, zIndex:1, zoom:1
};
// components without names, kept as a hash for later comparison to return consistent UnnamedComponentXX names.
const UNNAMED = [];
const objectKeys = Object.keys || (obj => {
let keys = [];
for (let i in obj) if (obj.hasOwnProperty(i)) keys.push(i);
return keys;
});
let encodeEntities = s => String(s).replace(/[<>"&]/g, escapeChar);
let escapeChar = a => ESC[a] || a;
let falsey = v => v==null || v===false;
let memoize = (fn, mem={}) => v => mem[v] || (mem[v] = fn(v));
let indent = (s, char) => String(s).replace(/(\n+)/g, '$1' + (char || '\t'));
let isLargeString = (s, length, ignoreLines) => (String(s).length>(length || 40) || (!ignoreLines && String(s).indexOf('\n')!==-1) || String(s).indexOf('<')!==-1);
function styleObjToCss(s) {
let str = '';
for (let prop in s) {
let val = s[prop];
if (val!=null) {
if (str) str += ' ';
str += jsToCss(prop);
str += ': ';
str += val;
if (typeof val==='number' && !NON_DIMENSION_PROPS[prop]) {
str += 'px';
}
str += ';';
}
}
return str;
}
// Convert a JavaScript camel-case CSS property name to a CSS property name
let jsToCss = memoize( s => s.replace(/([A-Z])/g,'-$1').toLowerCase() );
function assign(obj, props) {
for (let i in props) obj[i] = props[i];
return obj;
}
function getNodeProps(vnode) {
let defaultProps = vnode.nodeName.defaultProps,
props = assign({}, defaultProps || vnode.attributes);
if (defaultProps) assign(props, vnode.attributes);
if (vnode.children) props.children = vnode.children;
return props;
}
// we have to patch in Array support, Possible issue in npm.im/pretty-format
let preactPlugin = {
test(object) {
return object && typeof object==='object' && 'nodeName' in object && 'attributes' in object && 'children' in object && !('nodeType' in object);
},
print(val, print, indent) {
return renderToString(val, preactPlugin.context, preactPlugin.opts, true);
}
};
let prettyFormatOpts = {
plugins: [preactPlugin]
};
/** Render Preact JSX + Components to an HTML string.

@@ -190,15 +111,5 @@ * @name render

if (opts.jsx) {
if (typeof v!=='string') {
preactPlugin.context = context;
preactPlugin.opts = opts;
v = prettyFormat(v, prettyFormatOpts);
if (~v.indexOf('\n')) {
v = `${indent('\n'+v, indentChar)}\n`;
}
s += indent(`\n${name}={${v}}`, indentChar);
}
else {
s += `\n${indentChar}${name}="${encodeEntities(v)}"`;
}
let hooked = opts.attributeHook && opts.attributeHook(name, v, context, opts);
if (hooked) {
s += hooked;
continue;

@@ -205,0 +116,0 @@ }

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