snabbdom-virtualize
Advanced tools
| "use strict"; | ||
| module.exports = { | ||
| entry: './src/index.js', | ||
| output: { | ||
| filename: 'index.js', | ||
| library: 'index.js', | ||
| libraryTarget: 'umd' | ||
| }, | ||
| module: { | ||
| loaders: [{ | ||
| test: /\.js$/, | ||
| exclude: /node_modules/, | ||
| loader: 'babel' | ||
| }] | ||
| }, | ||
| externals: [ | ||
| 'snabbdom/h', | ||
| 'snabbdom/vnode' | ||
| ] | ||
| }; |
+202
-102
@@ -1,119 +0,219 @@ | ||
| 'use strict'; | ||
| (function webpackUniversalModuleDefinition(root, factory) { | ||
| if(typeof exports === 'object' && typeof module === 'object') | ||
| module.exports = factory(require("snabbdom/h"), require("snabbdom/vnode")); | ||
| else if(typeof define === 'function' && define.amd) | ||
| define(["snabbdom/h", "snabbdom/vnode"], factory); | ||
| else if(typeof exports === 'object') | ||
| exports["index.js"] = factory(require("snabbdom/h"), require("snabbdom/vnode")); | ||
| else | ||
| root["index.js"] = factory(root["snabbdom/h"], root["snabbdom/vnode"]); | ||
| })(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_2__) { | ||
| return /******/ (function(modules) { // webpackBootstrap | ||
| /******/ // The module cache | ||
| /******/ var installedModules = {}; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.default = snabbdomVirtualize; | ||
| /******/ // The require function | ||
| /******/ function __webpack_require__(moduleId) { | ||
| var _h = require('snabbdom/h'); | ||
| /******/ // Check if module is in cache | ||
| /******/ if(installedModules[moduleId]) | ||
| /******/ return installedModules[moduleId].exports; | ||
| var _h2 = _interopRequireDefault(_h); | ||
| /******/ // Create a new module (and put it into the cache) | ||
| /******/ var module = installedModules[moduleId] = { | ||
| /******/ exports: {}, | ||
| /******/ id: moduleId, | ||
| /******/ loaded: false | ||
| /******/ }; | ||
| var _vnode = require('snabbdom/vnode'); | ||
| /******/ // Execute the module function | ||
| /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
| var _vnode2 = _interopRequireDefault(_vnode); | ||
| /******/ // Flag the module as loaded | ||
| /******/ module.loaded = true; | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| /******/ // Return the exports of the module | ||
| /******/ return module.exports; | ||
| /******/ } | ||
| function snabbdomVirtualize(element) { | ||
| if (!element) { | ||
| return null; | ||
| } | ||
| // First thing to check is if a string is passed in. | ||
| if (typeof element === 'string') { | ||
| // General strategy here: | ||
| // Throw the string inside an element as innerHTML to get it parsed into | ||
| // DOM nodes. Then go and pull out the parsed nodes. | ||
| var el = document.createElement('div'); | ||
| el.innerHTML = element; | ||
| /******/ // expose the modules object (__webpack_modules__) | ||
| /******/ __webpack_require__.m = modules; | ||
| // There should only be one top-level node in the string. Throw an error | ||
| // otherwise. | ||
| if (el.childNodes.length > 1) { | ||
| throw new Error('Cannot virtualize multiple top-level nodes.'); | ||
| } else if (el.childNodes.length === 1) { | ||
| // Pull out the top-level node and run it through the virtualize fn. | ||
| return snabbdomVirtualize(el.childNodes.item(0)); | ||
| } | ||
| } | ||
| /******/ // expose the module cache | ||
| /******/ __webpack_require__.c = installedModules; | ||
| // If our node is a text node, then we only want to set the `text` part of | ||
| // the VNode. | ||
| if (element.nodeType === Node.TEXT_NODE) { | ||
| return (0, _vnode2.default)(undefined, undefined, undefined, element.textContent); | ||
| } | ||
| /******/ // __webpack_public_path__ | ||
| /******/ __webpack_require__.p = ""; | ||
| // If not a text node, then build up a VNode based on the element's tag | ||
| // name, class and style attributes, and remaining attributes. | ||
| /******/ // Load entry module and return exports | ||
| /******/ return __webpack_require__(0); | ||
| /******/ }) | ||
| /************************************************************************/ | ||
| /******/ ([ | ||
| /* 0 */ | ||
| /***/ function(module, exports, __webpack_require__) { | ||
| // Special values: style, class. We don't include these in the attrs hash | ||
| // of the VNode. | ||
| var data = {}; | ||
| var classes = getClasses(element); | ||
| if (Object.keys(classes).length !== 0) { | ||
| data.class = classes; | ||
| } | ||
| var style = getStyle(element); | ||
| if (Object.keys(style).length !== 0) { | ||
| data.style = style; | ||
| } | ||
| 'use strict'; | ||
| // Build up set of attributes on the element. | ||
| var attributes = element.attributes; | ||
| for (var _i = 0; _i < attributes.length; _i++) { | ||
| var attr = attributes.item(_i); | ||
| var name = attr.name; | ||
| if (name !== 'style' && name !== 'class') { | ||
| if (!data.attrs) { | ||
| data.attrs = {}; | ||
| } | ||
| data.attrs[name] = attr.value; | ||
| } | ||
| } | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.default = snabbdomVirtualize; | ||
| // Build up set of children. | ||
| var childNodes = null; | ||
| var children = element.childNodes; | ||
| if (children.length > 0) { | ||
| childNodes = []; | ||
| for (var i = 0; i < children.length; i++) { | ||
| childNodes.push(snabbdomVirtualize(children.item(i))); | ||
| } | ||
| } | ||
| return (0, _h2.default)(element.tagName.toLowerCase(), data, childNodes); | ||
| } | ||
| var _h = __webpack_require__(1); | ||
| // Builds the class object for the VNode. | ||
| function getClasses(element) { | ||
| var className = element.className; | ||
| var classes = {}; | ||
| if (className !== null && className.length > 0) { | ||
| className.split(' ').forEach(function (className) { | ||
| classes[className] = true; | ||
| }); | ||
| } | ||
| return classes; | ||
| } | ||
| var _h2 = _interopRequireDefault(_h); | ||
| // Builds the style object for the VNode. | ||
| function getStyle(element) { | ||
| var style = element.style; | ||
| var styles = {}; | ||
| for (var i = 0; i < style.length; i++) { | ||
| var name = style.item(i); | ||
| var transformedName = transformName(name); | ||
| styles[transformedName] = style.getPropertyValue(name); | ||
| } | ||
| return styles; | ||
| } | ||
| var _vnode = __webpack_require__(2); | ||
| function transformName(name) { | ||
| // Replace -a with A to help camel case style property names. | ||
| name = name.replace(/-(\w)/g, function _replace($1, $2) { | ||
| return $2.toUpperCase(); | ||
| }); | ||
| // Handle properties that start with a -. | ||
| var firstChar = name.charAt(0).toLowerCase(); | ||
| return '' + firstChar + name.substring(1); | ||
| } | ||
| var _vnode2 = _interopRequireDefault(_vnode); | ||
| var _eventListeners = __webpack_require__(3); | ||
| var _eventListeners2 = _interopRequireDefault(_eventListeners); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function snabbdomVirtualize(element) { | ||
| if (!element) { | ||
| return null; | ||
| } | ||
| // First thing to check is if a string is passed in. | ||
| if (typeof element === 'string') { | ||
| // General strategy here: | ||
| // Throw the string inside an element as innerHTML to get it parsed into | ||
| // DOM nodes. Then go and pull out the parsed nodes. | ||
| var el = document.createElement('div'); | ||
| el.innerHTML = element; | ||
| // There should only be one top-level node in the string. Throw an error | ||
| // otherwise. | ||
| if (el.childNodes.length > 1) { | ||
| throw new Error('Cannot virtualize multiple top-level nodes.'); | ||
| } else if (el.childNodes.length === 1) { | ||
| // Pull out the top-level node and run it through the virtualize fn. | ||
| return snabbdomVirtualize(el.childNodes.item(0)); | ||
| } | ||
| } | ||
| // If our node is a text node, then we only want to set the `text` part of | ||
| // the VNode. | ||
| if (element.nodeType === Node.TEXT_NODE) { | ||
| return (0, _vnode2.default)(undefined, undefined, undefined, element.textContent); | ||
| } | ||
| // If not a text node, then build up a VNode based on the element's tag | ||
| // name, class and style attributes, and remaining attributes. | ||
| // Special values: style, class. We don't include these in the attrs hash | ||
| // of the VNode. | ||
| var data = {}; | ||
| var classes = getClasses(element); | ||
| if (Object.keys(classes).length !== 0) { | ||
| data.class = classes; | ||
| } | ||
| var style = getStyle(element); | ||
| if (Object.keys(style).length !== 0) { | ||
| data.style = style; | ||
| } | ||
| // Build up set of attributes on the element. | ||
| var attributes = element.attributes; | ||
| for (var _i = 0; _i < attributes.length; _i++) { | ||
| var attr = attributes.item(_i); | ||
| var name = attr.name; | ||
| if (name !== 'style' && name !== 'class') { | ||
| if (!data.attrs) { | ||
| data.attrs = {}; | ||
| } | ||
| data.attrs[name] = attr.value; | ||
| } | ||
| } | ||
| // Check for event listeners. | ||
| var on = {}; | ||
| _eventListeners2.default.forEach(function (key) { | ||
| if (element[key]) { | ||
| on[key.substring(2)] = element[key]; | ||
| } | ||
| }); | ||
| if (Object.keys(on).length > 0) { | ||
| data.on = on; | ||
| } | ||
| // Build up set of children. | ||
| var childNodes = null; | ||
| var children = element.childNodes; | ||
| if (children.length > 0) { | ||
| childNodes = []; | ||
| for (var i = 0; i < children.length; i++) { | ||
| childNodes.push(snabbdomVirtualize(children.item(i))); | ||
| } | ||
| } | ||
| return (0, _h2.default)(element.tagName.toLowerCase(), data, childNodes); | ||
| } | ||
| // Builds the class object for the VNode. | ||
| function getClasses(element) { | ||
| var className = element.className; | ||
| var classes = {}; | ||
| if (className !== null && className.length > 0) { | ||
| className.split(' ').forEach(function (className) { | ||
| classes[className] = true; | ||
| }); | ||
| } | ||
| return classes; | ||
| } | ||
| // Builds the style object for the VNode. | ||
| function getStyle(element) { | ||
| var style = element.style; | ||
| var styles = {}; | ||
| for (var i = 0; i < style.length; i++) { | ||
| var name = style.item(i); | ||
| var transformedName = transformName(name); | ||
| styles[transformedName] = style.getPropertyValue(name); | ||
| } | ||
| return styles; | ||
| } | ||
| function transformName(name) { | ||
| // Replace -a with A to help camel case style property names. | ||
| name = name.replace(/-(\w)/g, function _replace($1, $2) { | ||
| return $2.toUpperCase(); | ||
| }); | ||
| // Handle properties that start with a -. | ||
| var firstChar = name.charAt(0).toLowerCase(); | ||
| return '' + firstChar + name.substring(1); | ||
| } | ||
| /***/ }, | ||
| /* 1 */ | ||
| /***/ function(module, exports) { | ||
| module.exports = __WEBPACK_EXTERNAL_MODULE_1__; | ||
| /***/ }, | ||
| /* 2 */ | ||
| /***/ function(module, exports) { | ||
| module.exports = __WEBPACK_EXTERNAL_MODULE_2__; | ||
| /***/ }, | ||
| /* 3 */ | ||
| /***/ function(module, exports) { | ||
| 'use strict'; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| // List from https://html.spec.whatwg.org/multipage/webappapis.html#globaleventhandlers. | ||
| exports.default = ['onabort', 'onautocomplete', 'onautocompleteerror', 'onblur', 'oncancel', 'oncanplay', 'oncanplaythrough', 'onchange', 'onclick', 'onclose', 'oncontextmenu', 'oncuechange', 'ondblclick', 'ondrag', 'ondragend', 'ondragenter', 'ondragexit', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'ondurationchange', 'onemptied', 'onended', 'onerror', 'onfocus', 'oninput', 'oninvalid', 'onkeydown', 'onkeypress', 'onkeyup', 'onload', 'onloadeddata', 'onloadedmetadata', 'onloadstart', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onwheel', 'onpause', 'onplay', 'onplaying', 'onprogress', 'onratechange', 'onreset', 'onresize', 'onscroll', 'onseeked', 'onseeking', 'onselect', 'onshow', 'onstalled', 'onsubmit', 'onsuspend', 'ontimeupdate', 'ontoggle', 'onvolumechange', 'onwaiting']; | ||
| /***/ } | ||
| /******/ ]) | ||
| }); | ||
| ; |
+5
-3
| { | ||
| "name": "snabbdom-virtualize", | ||
| "version": "0.1.0", | ||
| "version": "0.2.0", | ||
| "description": "Library for turning strings and DOM nodes into virtual DOM nodes compatible with snabbdom.", | ||
@@ -17,4 +17,4 @@ "author": { | ||
| "prepublish": "npm run build", | ||
| "build": "babel src/index.js --out-file index.js", | ||
| "watch": "babel src/index.js --watch --out-file index.js", | ||
| "build": "webpack --config webpack.config.js", | ||
| "watch": "webpack --watch --config webpack.config.js", | ||
| "test": "karma start test/karma.conf.js" | ||
@@ -34,5 +34,7 @@ }, | ||
| "karma-sauce-launcher": "^0.3.0", | ||
| "karma-sinon": "^1.0.4", | ||
| "karma-sourcemap-loader": "^0.3.7", | ||
| "karma-webpack": "^1.7.0", | ||
| "mocha": "^2.4.5", | ||
| "sinon": "^1.17.3", | ||
| "snabbdom": "^0.3.0", | ||
@@ -39,0 +41,0 @@ "webpack": "^1.12.12" |
| "use strict"; | ||
| var webpackConfig = require('../webpack.config.js'); | ||
| module.exports = function (config) { | ||
@@ -7,3 +9,3 @@ var isCI = process.env['CI']; | ||
| var baseConfig = { | ||
| frameworks: ['mocha', 'chai'], | ||
| frameworks: ['mocha', 'sinon', 'chai'], | ||
@@ -20,9 +22,3 @@ files: [ | ||
| devtool: 'inline-source-map', | ||
| module: { | ||
| loaders: [{ | ||
| test: /\.js$/, | ||
| exclude: /node_modules/, | ||
| loader: 'babel' | ||
| }] | ||
| } | ||
| module: webpackConfig.module | ||
| }, | ||
@@ -29,0 +25,0 @@ |
@@ -134,2 +134,18 @@ import virtualize from '../../src/index'; | ||
| }); | ||
| it("should handle on* event listeners", () => { | ||
| const spy = sinon.spy(); | ||
| const spy2 = sinon.spy(); | ||
| const el = createElement('div'); | ||
| el.onclick = spy; | ||
| el.onblur = spy2; | ||
| expect(virtualize(el)).to.deep.equal( | ||
| h('div', { | ||
| on: { | ||
| click: spy, | ||
| blur: spy2 | ||
| } | ||
| }) | ||
| ); | ||
| }); | ||
| }); | ||
@@ -136,0 +152,0 @@ |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
19028
31.45%9
12.5%430
33.96%17
13.33%