@thi.ng/hiccup
Advanced tools
Comparing version 2.7.2 to 3.0.0
20
api.js
@@ -1,15 +0,13 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SVG_NS = "http://www.w3.org/2000/svg"; | ||
exports.XLINK_NS = "http://www.w3.org/1999/xlink"; | ||
exports.TAG_REGEXP = /^([^\s\.#]+)(?:#([^\s\.#]+))?(?:\.([^\s#]+))?$/; | ||
export const SVG_NS = "http://www.w3.org/2000/svg"; | ||
export const XLINK_NS = "http://www.w3.org/1999/xlink"; | ||
export const TAG_REGEXP = /^([^\s\.#]+)(?:#([^\s\.#]+))?(?:\.([^\s#]+))?$/; | ||
// tslint:disable-next-line | ||
exports.SVG_TAGS = "animate animateColor animateMotion animateTransform circle clipPath color-profile defs desc discard ellipse feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feDropShadow feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence filter font foreignObject g image line linearGradient marker mask metadata mpath path pattern polygon polyline radialGradient rect set stop style svg switch symbol text textPath title tref tspan use view" | ||
export const SVG_TAGS = "animate animateColor animateMotion animateTransform circle clipPath color-profile defs desc discard ellipse feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feDropShadow feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence filter font foreignObject g image line linearGradient marker mask metadata mpath path pattern polygon polyline radialGradient rect set stop style svg switch symbol text textPath title tref tspan use view" | ||
.split(" ") | ||
.reduce((acc, x) => (acc[x] = 1, acc), {}); | ||
// tslint:disable-next-line | ||
exports.VOID_TAGS = "area base br circle col command ellipse embed hr img input keygen line link meta param path polygon polyline rect source stop track use wbr" | ||
export const VOID_TAGS = "area base br circle col command ellipse embed hr img input keygen line link meta param path polygon polyline rect source stop track use wbr" | ||
.split(" ") | ||
.reduce((acc, x) => (acc[x] = 1, acc), {}); | ||
exports.ENTITIES = { | ||
export const ENTITIES = { | ||
"&": "&", | ||
@@ -21,4 +19,4 @@ "<": "<", | ||
}; | ||
exports.COMMENT = "__COMMENT__"; | ||
exports.NO_SPANS = { | ||
export const COMMENT = "__COMMENT__"; | ||
export const NO_SPANS = { | ||
button: 1, | ||
@@ -29,2 +27,2 @@ option: 1, | ||
}; | ||
exports.ENTITY_RE = new RegExp(`[${Object.keys(exports.ENTITIES)}]`, "g"); | ||
export const ENTITY_RE = new RegExp(`[${Object.keys(ENTITIES)}]`, "g"); |
@@ -6,2 +6,24 @@ # Change Log | ||
# [3.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/hiccup@2.7.2...@thi.ng/hiccup@3.0.0) (2019-01-21) | ||
### Build System | ||
* update package build scripts & outputs, imports in ~50 packages ([b54b703](https://github.com/thi-ng/umbrella/commit/b54b703)) | ||
### BREAKING CHANGES | ||
* enabled multi-outputs (ES6 modules, CJS, UMD) | ||
- build scripts now first build ES6 modules in package root, then call | ||
`scripts/bundle-module` to build minified CJS & UMD bundles in `/lib` | ||
- all imports MUST be updated to only refer to package level | ||
(not individual files anymore). tree shaking in user land will get rid of | ||
all unused imported symbols. | ||
## [2.7.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/hiccup@2.7.1...@thi.ng/hiccup@2.7.2) (2018-12-20) | ||
@@ -8,0 +30,0 @@ |
@@ -1,9 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const is_function_1 = require("@thi.ng/checks/is-function"); | ||
exports.css = (rules) => { | ||
import { isFunction } from "@thi.ng/checks"; | ||
export const css = (rules) => { | ||
let css = "", v; | ||
for (let r in rules) { | ||
v = rules[r]; | ||
if (is_function_1.isFunction(v)) { | ||
if (isFunction(v)) { | ||
v = v(rules); | ||
@@ -10,0 +8,0 @@ } |
@@ -1,4 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const implements_function_1 = require("@thi.ng/checks/implements-function"); | ||
import { implementsFunction } from "@thi.ng/checks"; | ||
/** | ||
@@ -13,3 +11,3 @@ * Takes an arbitrary `ctx` object and array of `keys`. Attempts to call | ||
*/ | ||
exports.derefContext = (ctx, keys) => { | ||
export const derefContext = (ctx, keys) => { | ||
if (ctx == null || !keys || !keys.length) | ||
@@ -20,5 +18,5 @@ return ctx; | ||
const v = res[k]; | ||
implements_function_1.implementsFunction(v, "deref") && (res[k] = v.deref()); | ||
implementsFunction(v, "deref") && (res[k] = v.deref()); | ||
} | ||
return res; | ||
}; |
@@ -1,4 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const api_1 = require("./api"); | ||
exports.escape = (x) => x.replace(api_1.ENTITY_RE, (y) => api_1.ENTITIES[y]); | ||
import { ENTITIES, ENTITY_RE } from "./api"; | ||
export const escape = (x) => x.replace(ENTITY_RE, (y) => ENTITIES[y]); |
15
index.js
@@ -1,10 +0,5 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./api")); | ||
__export(require("./css")); | ||
__export(require("./deref")); | ||
__export(require("./escape")); | ||
__export(require("./serialize")); | ||
export * from "./api"; | ||
export * from "./css"; | ||
export * from "./deref"; | ||
export * from "./escape"; | ||
export * from "./serialize"; |
{ | ||
"name": "@thi.ng/hiccup", | ||
"version": "2.7.2", | ||
"version": "3.0.0", | ||
"description": "HTML/SVG/XML serialization of nested data structures, iterables & closures", | ||
"main": "./index.js", | ||
"module": "./index.js", | ||
"main": "./lib/index.js", | ||
"umd:main": "./lib/index.umd.js", | ||
"typings": "./index.d.ts", | ||
@@ -15,11 +17,13 @@ "repository": { | ||
"scripts": { | ||
"build": "yarn clean && tsc --declaration", | ||
"clean": "rm -rf *.js *.d.ts .nyc_output build coverage doc", | ||
"build": "yarn clean && yarn build:es6 && yarn build:bundle", | ||
"build:es6": "tsc --declaration", | ||
"build:bundle": "../../scripts/bundle-module hiccup checks errors", | ||
"test": "rimraf build && tsc -p test/tsconfig.json && nyc mocha build/test/*.js", | ||
"clean": "rimraf *.js *.d.ts .nyc_output build coverage doc lib", | ||
"cover": "yarn test && nyc report --reporter=lcov", | ||
"doc": "node_modules/.bin/typedoc --mode modules --out doc src", | ||
"pub": "yarn build && yarn publish --access public", | ||
"test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js" | ||
"pub": "yarn build && yarn publish --access public" | ||
}, | ||
"devDependencies": { | ||
"@thi.ng/atom": "^1.5.8", | ||
"@thi.ng/atom": "^2.0.0", | ||
"@types/mocha": "^5.2.5", | ||
@@ -29,8 +33,8 @@ "@types/node": "^10.12.15", | ||
"nyc": "^13.1.0", | ||
"typedoc": "^0.13.0", | ||
"typedoc": "^0.14.0", | ||
"typescript": "^3.2.2" | ||
}, | ||
"dependencies": { | ||
"@thi.ng/checks": "^1.5.14", | ||
"@thi.ng/errors": "^0.1.12" | ||
"@thi.ng/checks": "^2.0.0", | ||
"@thi.ng/errors": "^1.0.0" | ||
}, | ||
@@ -54,3 +58,4 @@ "keywords": [ | ||
}, | ||
"gitHead": "f44070e47befd2de4303df7ce375ba4f8134b794" | ||
"sideEffects": false, | ||
"gitHead": "348e7303b8b4d2749a02dd43e3f78d711242e4fe" | ||
} |
@@ -1,12 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const implements_function_1 = require("@thi.ng/checks/implements-function"); | ||
const is_function_1 = require("@thi.ng/checks/is-function"); | ||
const is_not_string_iterable_1 = require("@thi.ng/checks/is-not-string-iterable"); | ||
const is_plain_object_1 = require("@thi.ng/checks/is-plain-object"); | ||
const is_string_1 = require("@thi.ng/checks/is-string"); | ||
const illegal_arguments_1 = require("@thi.ng/errors/illegal-arguments"); | ||
const api_1 = require("./api"); | ||
const css_1 = require("./css"); | ||
const escape_1 = require("./escape"); | ||
import { implementsFunction, isFunction, isNotStringAndIterable, isPlainObject, isString } from "@thi.ng/checks"; | ||
import { illegalArgs } from "@thi.ng/errors"; | ||
import { COMMENT, NO_SPANS, TAG_REGEXP, VOID_TAGS } from "./api"; | ||
import { css } from "./css"; | ||
import { escape } from "./escape"; | ||
/** | ||
@@ -120,3 +114,3 @@ * Recursively normalizes and serializes given tree as HTML/SVG/XML | ||
*/ | ||
exports.serialize = (tree, ctx, escape = false, span = false, keys = span, path = [0]) => _serialize(tree, ctx, escape, span, keys, path); | ||
export const serialize = (tree, ctx, escape = false, span = false, keys = span, path = [0]) => _serialize(tree, ctx, escape, span, keys, path); | ||
const _serialize = (tree, ctx, esc, span, keys, path) => { | ||
@@ -131,10 +125,10 @@ if (tree == null) { | ||
let tag = tree[0]; | ||
if (is_function_1.isFunction(tag)) { | ||
if (isFunction(tag)) { | ||
return _serialize(tag.apply(null, [ctx, ...tree.slice(1)]), ctx, esc, span, keys, path); | ||
} | ||
if (implements_function_1.implementsFunction(tag, "render")) { | ||
if (implementsFunction(tag, "render")) { | ||
return _serialize(tag.render.apply(null, [ctx, ...tree.slice(1)]), ctx, esc, span, keys, path); | ||
} | ||
if (is_string_1.isString(tag)) { | ||
if (tag === api_1.COMMENT) { | ||
if (isString(tag)) { | ||
if (tag === COMMENT) { | ||
return tree.length > 2 ? | ||
@@ -144,3 +138,3 @@ `\n<!--\n${tree.slice(1).map((x) => " " + x).join("\n")}\n-->\n` : | ||
} | ||
tree = exports.normalize(tree); | ||
tree = normalize(tree); | ||
tag = tree[0]; | ||
@@ -162,3 +156,3 @@ const attribs = tree[1]; | ||
if (v != null) { | ||
if (is_function_1.isFunction(v)) { | ||
if (isFunction(v)) { | ||
if (/^on\w+/.test(a) || (v = v(attribs)) == null) { | ||
@@ -174,3 +168,3 @@ continue; | ||
if (v.length) { | ||
res += ` ${a}="${esc ? escape_1.escape(v) : v}"`; | ||
res += ` ${a}="${esc ? escape(v) : v}"`; | ||
} | ||
@@ -182,7 +176,7 @@ } | ||
if (body) { | ||
if (api_1.VOID_TAGS[tag]) { | ||
illegal_arguments_1.illegalArgs(`No body allowed in tag: ${tag}`); | ||
if (VOID_TAGS[tag]) { | ||
illegalArgs(`No body allowed in tag: ${tag}`); | ||
} | ||
res += ">"; | ||
span = span && !api_1.NO_SPANS[tag]; | ||
span = span && !NO_SPANS[tag]; | ||
for (let i = 0, n = body.length; i < n; i++) { | ||
@@ -193,3 +187,3 @@ res += _serialize(body[i], ctx, esc, span, keys, [...path, i]); | ||
} | ||
else if (!api_1.VOID_TAGS[tag]) { | ||
else if (!VOID_TAGS[tag]) { | ||
return res += `></${tag}>`; | ||
@@ -199,20 +193,20 @@ } | ||
} | ||
if (is_not_string_iterable_1.isNotStringAndIterable(tree)) { | ||
if (isNotStringAndIterable(tree)) { | ||
return _serializeIter(tree, ctx, esc, span, keys, path); | ||
} | ||
illegal_arguments_1.illegalArgs(`invalid tree node: ${tree}`); | ||
illegalArgs(`invalid tree node: ${tree}`); | ||
} | ||
if (is_function_1.isFunction(tree)) { | ||
if (isFunction(tree)) { | ||
return _serialize(tree(ctx), ctx, esc, span, keys, path); | ||
} | ||
if (implements_function_1.implementsFunction(tree, "toHiccup")) { | ||
if (implementsFunction(tree, "toHiccup")) { | ||
return _serialize(tree.toHiccup(ctx), ctx, esc, span, keys, path); | ||
} | ||
if (implements_function_1.implementsFunction(tree, "deref")) { | ||
if (implementsFunction(tree, "deref")) { | ||
return _serialize(tree.deref(), ctx, esc, span, keys, path); | ||
} | ||
if (is_not_string_iterable_1.isNotStringAndIterable(tree)) { | ||
if (isNotStringAndIterable(tree)) { | ||
return _serializeIter(tree, ctx, esc, span, keys, path); | ||
} | ||
tree = esc ? escape_1.escape(tree.toString()) : tree; | ||
tree = esc ? escape(tree.toString()) : tree; | ||
return span ? | ||
@@ -231,9 +225,9 @@ `<span${keys ? ` key="${path.join("-")}"` : ""}>${tree}</span>` : | ||
}; | ||
exports.normalize = (tag) => { | ||
export const normalize = (tag) => { | ||
let el = tag[0]; | ||
let match, id, clazz; | ||
const hasAttribs = is_plain_object_1.isPlainObject(tag[1]); | ||
const hasAttribs = isPlainObject(tag[1]); | ||
const attribs = hasAttribs ? Object.assign({}, tag[1]) : {}; | ||
if (!is_string_1.isString(el) || !(match = api_1.TAG_REGEXP.exec(el))) { | ||
illegal_arguments_1.illegalArgs(`"${el}" is not a valid tag name`); | ||
if (!isString(el) || !(match = TAG_REGEXP.exec(el))) { | ||
illegalArgs(`"${el}" is not a valid tag name`); | ||
} | ||
@@ -256,4 +250,4 @@ el = match[1]; | ||
if (tag.length > 1) { | ||
if (is_plain_object_1.isPlainObject(attribs.style)) { | ||
attribs.style = css_1.css(attribs.style); | ||
if (isPlainObject(attribs.style)) { | ||
attribs.style = css(attribs.style); | ||
} | ||
@@ -260,0 +254,0 @@ tag = tag.slice(hasAttribs ? 2 : 1).filter((x) => x != null); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94831
20
873
+ Added@thi.ng/checks@2.9.11(transitive)
+ Added@thi.ng/errors@1.3.4(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@thi.ng/checks@1.5.14(transitive)
- Removed@thi.ng/errors@0.1.12(transitive)
Updated@thi.ng/checks@^2.0.0
Updated@thi.ng/errors@^1.0.0