Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded libs #69

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var escape = require('lodash.escape')
var escape = require('./util/escape')
var parseSelector = require('parse-sel')
var VOID_ELEMENTS = require('./elements').VOID
var CONTAINER_ELEMENTS = require('./elements').CONTAINER
Expand Down
5 changes: 2 additions & 3 deletions modules/attributes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

var forOwn = require('lodash.forown')
var escape = require('lodash.escape')
var escape = require('../util/escape')

// data.attrs

module.exports = function attrsModule (vnode, attributes) {
var attrs = vnode.data.attrs || {}

forOwn(attrs, function (value, key) {
Object.entries(attrs).forEach(function ([key, value]) {
attributes.set(key, escape(value))
})
}
11 changes: 3 additions & 8 deletions modules/class.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@

var forOwn = require('lodash.forown')
var remove = require('lodash.remove')
var uniq = require('lodash.uniq')

// data.class

module.exports = function classModule (vnode, attributes) {
Expand All @@ -13,17 +9,16 @@ module.exports = function classModule (vnode, attributes) {
var existing = attributes.get('class')
existing = existing.length > 0 ? existing.split(' ') : []

forOwn(classes, function (value, key) {
Object.entries(classes).forEach(function ([key, value]) {
if (value) {
_add.push(key)
} else {
_remove.push(key)
}
})

values = remove(uniq(existing.concat(_add)), function (value) {
return _remove.indexOf(value) < 0
})
values = [...new Set(existing.concat(_add))]
.filter(function (value) { return _remove.indexOf(value) < 0 })

if (values.length) {
attributes.set('class', values.join(' '))
Expand Down
5 changes: 2 additions & 3 deletions modules/dataset.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

var forOwn = require('lodash.forown')
var escape = require('lodash.escape')
var escape = require('../util/escape')

// data.dataset

module.exports = function datasetModule (vnode, attributes) {
var dataset = vnode.data.dataset || {}

forOwn(dataset, function (value, key) {
Object.entries(dataset).forEach(function ([key, value]) {
attributes.set(`data-${key}`, escape(value))
})
}
5 changes: 2 additions & 3 deletions modules/props.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

var forOwn = require('lodash.forown')
var escape = require('lodash.escape')
var escape = require('../util/escape')

// https://developer.mozilla.org/en-US/docs/Web/API/element
var omit = [
Expand Down Expand Up @@ -71,7 +70,7 @@ var booleanAttributes = [
module.exports = function propsModule (vnode, attributes) {
var props = vnode.data.props || {}

forOwn(props, function (value, key) {
Object.entries(props).forEach(function ([key, value]) {
if (omit.indexOf(key) > -1) {
return
}
Expand Down
5 changes: 2 additions & 3 deletions modules/style.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

var assign = require('object-assign')
var forOwn = require('lodash.forown')
var escape = require('lodash.escape')
var escape = require('../util/escape')
var kebabCase = require('lodash.kebabcase')

// data.style
Expand All @@ -15,7 +14,7 @@ module.exports = function styleModule (vnode, attributes) {
assign(style, style.delayed)
}

forOwn(style, function (value, key) {
Object.entries(style).forEach(function ([key, value]) {
// omit hook objects
if (typeof value === 'string' || typeof value === 'number') {
var kebabKey = kebabCase(key)
Expand Down
45 changes: 1 addition & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
},
"homepage": "https://github.com/acstll/snabbdom-to-html#readme",
"dependencies": {
"lodash.escape": "^4.0.1",
"lodash.forown": "^4.4.0",
"lodash.kebabcase": "^4.1.1",
"lodash.remove": "^4.7.0",
"lodash.uniq": "^4.5.0",
"object-assign": "^4.1.0",
"parse-sel": "^1.0.0"
},
Expand Down
15 changes: 15 additions & 0 deletions util/escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

var escapes = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&apos;',
'`': '&#96;'
}

var re = new RegExp(`[${Object.keys(escapes).join('')}]`, 'g')

module.exports = function escape (value) {
return ('' + value).replace(re, function (s) { return escapes[s] })
}