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

@ctx-core/html

Package Overview
Dependencies
Maintainers
1
Versions
801
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ctx-core/html - npm Package Compare versions

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, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;')
}
/**
* 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))}`
}

@@ -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

13

package.json
{
"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"
}
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