@ctx-core/html
Advanced tools
Comparing version 4.1.2 to 5.0.0
199
lib.js
@@ -1,2 +0,197 @@ | ||
require = require('esm')(module) | ||
module.exports = require('./lib.mjs') | ||
/** | ||
* @module @ctx-core/html/lib | ||
*/ | ||
import { assign } from '@ctx-core/object/lib.js' | ||
import { _version } from '@ctx-core/version__app/lib.js' | ||
import { log, debug } from '@ctx-core/logger/lib.js' | ||
const logPrefix = '@ctx-core/html/lib.js' | ||
/** | ||
* Returns a string of attrs for an html element | ||
* @param {Object} obj - Key/Value pairs of the attrs | ||
* @returns {String} The attrs for an html element | ||
*/ | ||
export function _attrs(obj) { | ||
if (!obj) return '' | ||
let attrs = [] | ||
for (let key in obj) { | ||
attrs.push(`${key}=${_html(obj[key])}`) | ||
} | ||
return attrs.join(' ') | ||
} | ||
/** | ||
* Returns class html attribute from obj | ||
* @param {Object} obj - key/value pairs of classes. Truthy values will have key class added. Falsy values will have key class ignored. | ||
* @returns {string} List of classes | ||
* @example | ||
* _class({class_1: true, class_2: false, class_3: true}) // returns 'class_1 class_3' | ||
*/ | ||
export function _class(obj, ...ARR__class) { | ||
const ARR = [] | ||
ARR.push(...ARR__class) | ||
for (let key in obj) { | ||
if (obj[key]) ARR.push(key) | ||
} | ||
return ARR.join(' ') | ||
} | ||
/** | ||
* Assigns additional styles to the style attribute on the HTMLElement el. | ||
* @param {module:ctx-core/dom/lib~HTMLElement} el - Element to set style on. Existing styles are kept unless overwritten by obj. | ||
* @param {Object} styles - key/value pairs of the styles | ||
* @returns {module:ctx-core/dom/lib~HTMLElement} | ||
*/ | ||
export function assign__style(el, styles) { | ||
const style__el = el.getAttribute('style') || '' | ||
const OBJ__styles = _OBJ__styles(style__el) | ||
el.setAttribute( | ||
'style', | ||
_style(assign(OBJ__styles, styles)) | ||
) | ||
return el | ||
} | ||
/** | ||
* Returns class style attribute from obj | ||
* @param {Object} obj - key/value pairs of styles | ||
* @returns {string} style | ||
* @example | ||
* _style({position: 'absolute, left: '5px'}) // returns 'position: absolute; left: 5px;' | ||
*/ | ||
export function _style(obj, ...ARR__style) { | ||
const ARR = [] | ||
ARR.push(...ARR__style) | ||
for (let key in obj) { | ||
const value = obj[key] | ||
ARR.push(`${key}: ${value};`) | ||
} | ||
return ARR.join(' ') | ||
} | ||
/** | ||
* Parses a style string & returns an object with each style | ||
* @param {string} STR__style | ||
* @returns {Object} key/value pair of styles | ||
* @example | ||
* $styles__obj('position: absolute; left: 5px;') // returns {position: 'absolute, left: '5px'} | ||
*/ | ||
export function _OBJ__styles(STR__style) { | ||
const ARR__STR__style = (STR__style || '').split(/ *; */) | ||
const OBJ__styles = {} | ||
for (let i = 0; i < ARR__STR__style.length; i++) { | ||
const STR__style__i = ARR__STR__style[i] | ||
if (!STR__style__i) continue | ||
const [name__style, value__style] = STR__style__i.split(/ *: */) | ||
OBJ__styles[name__style] = value__style | ||
} | ||
return OBJ__styles | ||
} | ||
/** | ||
* Returns a string of escaped html | ||
* @param {string} unsafe | ||
* @returns {XML|string} - Escaped HTML | ||
*/ | ||
export function _html(unsafe) { | ||
return unsafe | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
} | ||
/** | ||
* html for css link tags | ||
* @returns {string} | ||
*/ | ||
export function _html__links() { | ||
log(`${logPrefix}|$html__links`) | ||
const ctx = assign({ | ||
css: [], | ||
indentation: '', | ||
indentFirstLine: true | ||
}, ...arguments) | ||
const { | ||
css, | ||
indentation, | ||
indentFirstLine | ||
} = ctx | ||
let ARR__html__links = [] | ||
for (let i = 0; i < css.length; i++) { | ||
const cssFile = css[i] | ||
ARR__html__links.push( | ||
`${ | ||
(i || indentFirstLine) ? indentation : '' | ||
}<link rel="stylesheet" type="text/css" href="${cssFile}">` | ||
) | ||
} | ||
return ARR__html__links.join('\n') | ||
} | ||
/** | ||
* html for js script tags | ||
* @returns {string} | ||
*/ | ||
export function _html__js() { | ||
log(`${logPrefix}|_html__js`) | ||
const ctx = | ||
assign( | ||
{ | ||
js: [], | ||
indentation: '', | ||
indentFirstLine: true | ||
}, | ||
...arguments) | ||
const { indentation } = ctx | ||
const script = ctx.script || ctx.js | ||
let ARR__html__js = [] | ||
for (let i = 0; i < script.length; i++) { | ||
const jsFile = script[i] | ||
ARR__html__js.push( | ||
`${indentation}<script type="text/javascript" src="${jsFile}"></script>` | ||
) | ||
} | ||
return ARR__html__js.join('\n') | ||
} | ||
/** | ||
* versioned css file url | ||
* @param src__script | ||
*/ | ||
export function _css__path__versioned(src__script) { | ||
log(`${logPrefix}|$js$path__versioned`) | ||
const extName = '.css' | ||
return _versioned(`${src__script}${extName}`) | ||
} | ||
/** | ||
* | ||
* @param {module:ctx-core/object/lib~ctx} | ||
* @param src__script | ||
* @param opts | ||
* @returns {string} | ||
*/ | ||
export function _versioned__js(ctx, src__script, opts = {}) { | ||
const extName = (!opts.debug && ctx.minify) ? '.min.js' : '.js' | ||
return _versioned(ctx, `${src__script}${extName}`) | ||
} | ||
/** | ||
* versioned file | ||
* @param {module:ctx-core/object/lib~ctx} | ||
* @param {string} url | ||
* @returns {string} | ||
*/ | ||
export function _versioned(ctx, url) { | ||
log(`${logPrefix}|versioned`) | ||
return `${url}?${_query__version(ctx)}` | ||
} | ||
/** | ||
* _versioned with ctx | ||
* @param {module:ctx-core/object/lib~ctx} | ||
* @returns {string} | ||
*/ | ||
export function __versioned(ctx) { | ||
log(`${logPrefix}|$$versioned`) | ||
return function _versioned__versioned() { | ||
return _versioned(ctx, ...arguments) | ||
} | ||
} | ||
/** | ||
* version query param | ||
* @returns {string} | ||
*/ | ||
export function _query__version(ctx) { | ||
return `v=${encodeURIComponent(_version(ctx))}` | ||
} |
42
node.js
@@ -1,2 +0,40 @@ | ||
require = require('esm')(module) | ||
module.exports = require('./node.mjs') | ||
import { assign } from '@ctx-core/object/lib.js' | ||
import env from '@ctx-core/env/env.js' | ||
import { _version } from '@ctx-core/version__app/node.js' | ||
import { _versioned__js as _versioned__js__ } from './lib.js' | ||
import { log, debug } from '@ctx-core/logger/lib.js' | ||
const logPrefix = '@ctx-core/html/node.js' | ||
export function _versioned__js(src__script, opts = {}) { | ||
return _versioned__js__(env, src__script, opts) | ||
} | ||
/** | ||
* versioned file | ||
* @param {string} url | ||
* @returns {string} | ||
*/ | ||
export function _versioned(url) { | ||
return `${url}?${_query__version()}` | ||
} | ||
/** | ||
* version query param | ||
* @returns {string} | ||
*/ | ||
export function _query__version() { | ||
return `v=${encodeURIComponent(_version())}` | ||
} | ||
/** | ||
* Returns a new ctx__html | ||
* @param ctx | ||
* @param ARR__ctx__html | ||
* @returns {{}} | ||
*/ | ||
export function _ctx__html(ctx, ...ARR__ctx__html) { | ||
log(`${logPrefix}|_ctx__html`) | ||
const ctx__html = | ||
assign({ | ||
CACHE_VERSION: _version(), | ||
VERSION: ctx.VERSION | ||
}, ...ARR__ctx__html) | ||
return ctx__html | ||
} | ||
export const _ctx__html__core = _ctx__html |
{ | ||
"name": "@ctx-core/html", | ||
"version": "4.1.2", | ||
"version": "5.0.0", | ||
"description": "ctx-core html", | ||
@@ -24,9 +24,8 @@ "main": "lib.js", | ||
"dependencies": { | ||
"@ctx-core/env": "^3.1.21", | ||
"@ctx-core/logger": "^2.2.12", | ||
"@ctx-core/object": "^2.6.0", | ||
"@ctx-core/version__app": "^3.1.18", | ||
"esm": "^3.0.84" | ||
"@ctx-core/env": "^4.0.0", | ||
"@ctx-core/logger": "^3.0.0", | ||
"@ctx-core/object": "^3.0.0", | ||
"@ctx-core/version__app": "^4.0.0" | ||
}, | ||
"gitHead": "ef8c06c1b6e6183cce5b0836c59761cce170a6e9" | ||
"gitHead": "7d0d73495e67101da1ad8aeb87a7b9918b4689c1" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
4
6900
3
237
1
+ Added@ctx-core/array@15.5.2917.0.5(transitive)
+ Added@ctx-core/atob@3.0.41(transitive)
+ Added@ctx-core/cli-args@4.1.8(transitive)
+ Added@ctx-core/combinators@4.2.26(transitive)
+ Added@ctx-core/data@1.1.81(transitive)
+ Added@ctx-core/dom@5.13.42(transitive)
+ Added@ctx-core/env@4.0.195.0.0(transitive)
+ Added@ctx-core/error@4.0.25(transitive)
+ Added@ctx-core/function@13.2.514.0.46.0.09.1.5(transitive)
+ Added@ctx-core/html@6.1.125(transitive)
+ Added@ctx-core/logger@3.1.28(transitive)
+ Added@ctx-core/object@10.0.53.3.05.4.68.1.6(transitive)
+ Added@ctx-core/package@3.1.88(transitive)
+ Added@ctx-core/set@6.1.57(transitive)
+ Added@ctx-core/store@15.1.1(transitive)
+ Added@ctx-core/time@3.0.2(transitive)
+ Added@ctx-core/version__app@4.0.21(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedatob-lite@2.0.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedsvelte@3.59.2(transitive)
- Removedesm@^3.0.84
- Removed@ctx-core/atob@2.0.42(transitive)
- Removed@ctx-core/dom@3.2.9(transitive)
- Removed@ctx-core/env@3.1.21(transitive)
- Removed@ctx-core/error@3.0.10(transitive)
- Removed@ctx-core/function@4.2.0(transitive)
- Removed@ctx-core/logger@2.2.12(transitive)
- Removed@ctx-core/object@2.6.0(transitive)
- Removed@ctx-core/package@2.3.2(transitive)
- Removed@ctx-core/time@2.0.14(transitive)
- Removed@ctx-core/version__app@3.1.18(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedsupports-color@5.5.0(transitive)
Updated@ctx-core/env@^4.0.0
Updated@ctx-core/logger@^3.0.0
Updated@ctx-core/object@^3.0.0