Socket
Socket
Sign inDemoInstall

property-information

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

property-information - npm Package Compare versions

Comparing version 5.6.0 to 6.0.0

index.d.ts

17

index.js

@@ -1,6 +0,13 @@

'use strict'
import {merge} from './lib/util/merge.js'
import {xlink} from './lib/xlink.js'
import {xml} from './lib/xml.js'
import {xmlns} from './lib/xmlns.js'
import {aria} from './lib/aria.js'
import {html as htmlBase} from './lib/html.js'
import {svg as svgBase} from './lib/svg.js'
exports.html = require('./html')
exports.svg = require('./svg')
exports.normalize = require('./normalize')
exports.find = require('./find')
export {find} from './lib/find.js'
export {hastToReact} from './lib/hast-to-react.js'
export {normalize} from './lib/normalize.js'
export var html = merge([xml, xlink, xmlns, aria, htmlBase], 'html')
export var svg = merge([xml, xlink, xmlns, aria, svgBase], 'svg')

@@ -1,11 +0,5 @@

'use strict'
import {booleanish, number, spaceSeparated} from './util/types.js'
import {create} from './util/create.js'
var types = require('./util/types')
var create = require('./util/create')
var booleanish = types.booleanish
var number = types.number
var spaceSeparated = types.spaceSeparated
module.exports = create({
export var aria = create({
transform: ariaTransform,

@@ -65,4 +59,9 @@ properties: {

/**
* @param {unknown} _
* @param {string} prop
* @returns {string}
*/
function ariaTransform(_, prop) {
return prop === 'role' ? prop : 'aria-' + prop.slice(4).toLowerCase()
}

@@ -1,15 +0,13 @@

'use strict'
import {
boolean,
overloadedBoolean,
booleanish,
number,
spaceSeparated,
commaSeparated
} from './util/types.js'
import {create} from './util/create.js'
import {caseInsensitiveTransform} from './util/case-insensitive-transform.js'
var types = require('./util/types')
var create = require('./util/create')
var caseInsensitiveTransform = require('./util/case-insensitive-transform')
var boolean = types.boolean
var overloadedBoolean = types.overloadedBoolean
var booleanish = types.booleanish
var number = types.number
var spaceSeparated = types.spaceSeparated
var commaSeparated = types.commaSeparated
module.exports = create({
export var html = create({
space: 'html',

@@ -16,0 +14,0 @@ attributes: {

@@ -1,14 +0,12 @@

'use strict'
import {
boolean,
number,
spaceSeparated,
commaSeparated,
commaOrSpaceSeparated
} from './util/types.js'
import {create} from './util/create.js'
import {caseSensitiveTransform} from './util/case-sensitive-transform.js'
var types = require('./util/types')
var create = require('./util/create')
var caseSensitiveTransform = require('./util/case-sensitive-transform')
var boolean = types.boolean
var number = types.number
var spaceSeparated = types.spaceSeparated
var commaSeparated = types.commaSeparated
var commaOrSpaceSeparated = types.commaOrSpaceSeparated
module.exports = create({
export var svg = create({
space: 'svg',

@@ -15,0 +13,0 @@ attributes: {

@@ -1,9 +0,10 @@

'use strict'
import {caseSensitiveTransform} from './case-sensitive-transform.js'
var caseSensitiveTransform = require('./case-sensitive-transform')
module.exports = caseInsensitiveTransform
function caseInsensitiveTransform(attributes, property) {
/**
* @param {Object.<string, string>} attributes
* @param {string} property
* @returns {string}
*/
export function caseInsensitiveTransform(attributes, property) {
return caseSensitiveTransform(attributes, property.toLowerCase())
}

@@ -1,7 +0,8 @@

'use strict'
module.exports = caseSensitiveTransform
function caseSensitiveTransform(attributes, attribute) {
/**
* @param {Object.<string, string>} attributes
* @param {string} attribute
* @returns {string}
*/
export function caseSensitiveTransform(attributes, attribute) {
return attribute in attributes ? attributes[attribute] : attribute
}

@@ -1,39 +0,62 @@

'use strict'
import {normalize} from '../normalize.js'
import {Schema} from './schema.js'
import {DefinedInfo} from './defined-info.js'
var normalize = require('../../normalize')
var Schema = require('./schema')
var DefinedInfo = require('./defined-info')
/**
* @typedef {import('./schema.js').Properties} Properties
* @typedef {import('./schema.js').Normal} Normal
* @typedef {import('./info.js').Info} Info
*/
module.exports = create
/**
* @typedef {Object.<string, string>} Attributes
*
* @typedef {Object} Definition
* @property {Object.<string, number|null>} properties
* @property {(attributes: Attributes, property: string) => string} transform
* @property {string} [space]
* @property {Attributes} [attributes]
* @property {Array.<string>} [mustUseProperty]
*/
function create(definition) {
var space = definition.space
var mustUseProperty = definition.mustUseProperty || []
var attributes = definition.attributes || {}
var props = definition.properties
var transform = definition.transform
var own = {}.hasOwnProperty
/**
* @param {Definition} definition
* @returns {import('./schema.js').Schema}
*/
export function create(definition) {
/** @type {Properties} */
var property = {}
/** @type {Normal} */
var normal = {}
/** @type {string} */
var prop
/** @type {Info} */
var info
for (prop in props) {
info = new DefinedInfo(
prop,
transform(attributes, prop),
props[prop],
space
)
for (prop in definition.properties) {
if (own.call(definition.properties, prop)) {
info = new DefinedInfo(
prop,
definition.transform(definition.attributes, prop),
definition.properties[prop],
definition.space
)
if (mustUseProperty.indexOf(prop) !== -1) {
info.mustUseProperty = true
}
if (
definition.mustUseProperty &&
definition.mustUseProperty.includes(prop)
) {
info.mustUseProperty = true
}
property[prop] = info
property[prop] = info
normal[normalize(prop)] = prop
normal[normalize(info.attribute)] = prop
normal[normalize(prop)] = prop
normal[normalize(info.attribute)] = prop
}
}
return new Schema(property, normal, space)
return new Schema(property, normal, definition.space)
}

@@ -1,36 +0,38 @@

'use strict'
import {Info} from './info.js'
import * as types from './types.js'
var Info = require('./info')
var types = require('./types')
var checks = Object.keys(types)
module.exports = DefinedInfo
export class DefinedInfo extends Info {
/**
* @constructor
* @param {string} property
* @param {string} attribute
* @param {number} [mask]
* @param {string} [space]
*/
constructor(property, attribute, mask, space) {
var index = -1
DefinedInfo.prototype = new Info()
DefinedInfo.prototype.defined = true
super(property, attribute)
var checks = [
'boolean',
'booleanish',
'overloadedBoolean',
'number',
'commaSeparated',
'spaceSeparated',
'commaOrSpaceSeparated'
]
var checksLength = checks.length
mark(this, 'space', space)
function DefinedInfo(property, attribute, mask, space) {
var index = -1
var check
mark(this, 'space', space)
Info.call(this, property, attribute)
while (++index < checksLength) {
check = checks[index]
mark(this, check, (mask & types[check]) === types[check])
while (++index < checks.length) {
mark(
this,
checks[index],
(mask & types[checks[index]]) === types[checks[index]]
)
}
}
}
DefinedInfo.prototype.defined = true
/**
* @param {InstanceType<typeof DefinedInfo>} values
* @param {string} key
* @param {unknown} value
*/
function mark(values, key, value) {

@@ -37,0 +39,0 @@ if (value) {

@@ -1,23 +0,25 @@

'use strict'
export class Info {
/**
* @constructor
* @param {string} property
* @param {string} attribute
*/
constructor(property, attribute) {
this.property = property
this.attribute = attribute
}
}
module.exports = Info
var proto = Info.prototype
proto.space = null
proto.attribute = null
proto.property = null
proto.boolean = false
proto.booleanish = false
proto.overloadedBoolean = false
proto.number = false
proto.commaSeparated = false
proto.spaceSeparated = false
proto.commaOrSpaceSeparated = false
proto.mustUseProperty = false
proto.defined = false
function Info(property, attribute) {
this.property = property
this.attribute = attribute
}
/** @type {string|null} */
Info.prototype.space = null
Info.prototype.attribute = null
Info.prototype.property = null
Info.prototype.boolean = false
Info.prototype.booleanish = false
Info.prototype.overloadedBoolean = false
Info.prototype.number = false
Info.prototype.commaSeparated = false
Info.prototype.spaceSeparated = false
Info.prototype.commaOrSpaceSeparated = false
Info.prototype.mustUseProperty = false
Info.prototype.defined = false

@@ -1,28 +0,26 @@

'use strict'
import {Schema} from './schema.js'
var xtend = require('xtend')
var Schema = require('./schema')
/**
* @typedef {import('./schema.js').Properties} Properties
* @typedef {import('./schema.js').Normal} Normal
*/
module.exports = merge
function merge(definitions) {
var length = definitions.length
var property = []
var normal = []
/**
* @param {import('./schema.js').Schema[]} definitions
* @param {string} space
* @returns {import('./schema.js').Schema}
*/
export function merge(definitions, space) {
/** @type {Properties} */
var property = {}
/** @type {Normal} */
var normal = {}
var index = -1
var info
var space
while (++index < length) {
info = definitions[index]
property.push(info.property)
normal.push(info.normal)
space = info.space
while (++index < definitions.length) {
Object.assign(property, definitions[index].property)
Object.assign(normal, definitions[index].normal)
}
return new Schema(
xtend.apply(null, property),
xtend.apply(null, normal),
space
)
return new Schema(property, normal, space)
}

@@ -1,18 +0,28 @@

'use strict'
/**
* @typedef {import('./info.js').Info} Info
* @typedef {Object.<string, Info>} Properties
* @typedef {Object.<string, string>} Normal
*/
module.exports = Schema
var proto = Schema.prototype
proto.space = null
proto.normal = {}
proto.property = {}
function Schema(property, normal, space) {
this.property = property
this.normal = normal
if (space) {
this.space = space
export class Schema {
/**
* @constructor
* @param {Properties} property
* @param {Normal} normal
* @param {string} [space]
*/
constructor(property, normal, space) {
this.property = property
this.normal = normal
if (space) {
this.space = space
}
}
}
/** @type {Properties} */
Schema.prototype.property = {}
/** @type {Normal} */
Schema.prototype.normal = {}
/** @type {string|null} */
Schema.prototype.space = null

@@ -1,15 +0,13 @@

'use strict'
var powers = 0
exports.boolean = increment()
exports.booleanish = increment()
exports.overloadedBoolean = increment()
exports.number = increment()
exports.spaceSeparated = increment()
exports.commaSeparated = increment()
exports.commaOrSpaceSeparated = increment()
export var boolean = increment()
export var booleanish = increment()
export var overloadedBoolean = increment()
export var number = increment()
export var spaceSeparated = increment()
export var commaSeparated = increment()
export var commaOrSpaceSeparated = increment()
function increment() {
return Math.pow(2, ++powers)
return 2 ** ++powers
}

@@ -1,6 +0,4 @@

'use strict'
import {create} from './util/create.js'
var create = require('./util/create')
module.exports = create({
export var xlink = create({
space: 'xlink',

@@ -19,4 +17,9 @@ transform: xlinkTransform,

/**
* @param {unknown} _
* @param {string} prop
* @returns {string}
*/
function xlinkTransform(_, prop) {
return 'xlink:' + prop.slice(5).toLowerCase()
}

@@ -1,17 +0,16 @@

'use strict'
import {create} from './util/create.js'
var create = require('./util/create')
module.exports = create({
export var xml = create({
space: 'xml',
transform: xmlTransform,
properties: {
xmlLang: null,
xmlBase: null,
xmlSpace: null
}
properties: {xmlLang: null, xmlBase: null, xmlSpace: null}
})
/**
* @param {unknown} _
* @param {string} prop
* @returns {string}
*/
function xmlTransform(_, prop) {
return 'xml:' + prop.slice(3).toLowerCase()
}

@@ -1,16 +0,9 @@

'use strict'
import {create} from './util/create.js'
import {caseInsensitiveTransform} from './util/case-insensitive-transform.js'
var create = require('./util/create')
var caseInsensitiveTransform = require('./util/case-insensitive-transform')
module.exports = create({
export var xmlns = create({
space: 'xmlns',
attributes: {
xmlnsxlink: 'xmlns:xlink'
},
attributes: {xmlnsxlink: 'xmlns:xlink'},
transform: caseInsensitiveTransform,
properties: {
xmlns: null,
xmlnsXLink: null
}
properties: {xmlns: null, xmlnsXLink: null}
})
{
"name": "property-information",
"version": "5.6.0",
"version": "6.0.0",
"description": "Information for HTML properties",

@@ -25,51 +25,45 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.js",
"hast-to-react.json",
"html.js",
"svg.js",
"normalize.js",
"find.js",
"lib/"
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"xtend": "^4.0.0"
},
"devDependencies": {
"alpha-sort": "^3.0.0",
"arr-union": "^3.0.0",
"bail": "^1.0.0",
"browserify": "^17.0.0",
"@types/concat-stream": "^1.0.0",
"@types/mdast": "^3.0.0",
"@types/node": "^14.0.0",
"@types/tape": "^4.0.0",
"@types/unist": "^2.0.0",
"alpha-sort": "^4.0.0",
"bail": "^2.0.0",
"c8": "^7.0.0",
"concat-stream": "^2.0.0",
"html-element-attributes": "^2.0.0",
"html-event-attributes": "^1.0.0",
"html-element-attributes": "^3.0.0",
"html-event-attributes": "^2.0.0",
"mdast-zone": "^4.0.0",
"nyc": "^15.0.0",
"object.values": "^1.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0-alpha.1",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"svg-element-attributes": "^1.0.0",
"svg-event-attributes": "^1.0.0",
"rimraf": "^3.0.0",
"svg-element-attributes": "^2.0.0",
"svg-event-attributes": "^2.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-builder": "^2.0.0",
"xo": "^0.33.0"
"xo": "^0.38.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"{lib/**/,script/**,}*.d.ts\" && tsc && type-coverage",
"generate": "node script/generate-react && node script/generate-exceptions",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify index.js -s propertyInformation > property-information.js",
"build-mangle": "browserify index.js -s propertyInformation -p tinyify > property-information.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run generate && npm run format && npm run build && npm run test-coverage"
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run generate && npm run format && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {

@@ -87,18 +81,18 @@ "tabWidth": 2,

"rules": {
"unicorn/no-fn-reference-in-iterator": "off",
"unicorn/prefer-exponentiation-operator": "off",
"unicorn/prefer-includes": "off",
"guard-for-in": "off",
"prefer-exponentiation-operator": "off"
},
"ignore": [
"property-information.js"
]
"import/no-mutable-exports": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
"to do: add the following plugin back when `unified-engine` supports ESM": "./script/list",
"plugins": [
"./script/list",
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}

@@ -15,2 +15,5 @@ # property-information

This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
instead of `require`d.
[npm][]:

@@ -26,6 +29,6 @@

* [API](#api)
* [`propertyInformation.find(schema, name)`](#propertyinformationfindschema-name)
* [`propertyInformation.normalize(name)`](#propertyinformationnormalizename)
* [`propertyInformation.html`](#propertyinformationhtml)
* [`propertyInformation.svg`](#propertyinformationsvg)
* [`find(schema, name)`](#findschema-name)
* [`normalize(name)`](#normalizename)
* [`html`](#html)
* [`svg`](#svg)
* [`hastToReact`](#hasttoreact)

@@ -39,14 +42,14 @@ * [Support](#support)

```js
var info = require('property-information')
import {html, svg, find, normalize} from 'property-information'
console.log(info.find(info.html, 'className'))
// Or: info.find(info.html, 'class')
console.log(info.find(info.svg, 'horiz-adv-x'))
// Or: info.find(info.svg, 'horizAdvX')
console.log(info.find(info.svg, 'xlink:arcrole'))
// Or: info.find(info.svg, 'xLinkArcRole')
console.log(info.find(info.html, 'xmlLang'))
// Or: info.find(info.html, 'xml:lang')
console.log(info.find(info.html, 'ariaValueNow'))
// Or: info.find(info.html, 'aria-valuenow')
console.log(find(html, 'className'))
// Or: find(html, 'class')
console.log(find(svg, 'horiz-adv-x'))
// Or: find(svg, 'horizAdvX')
console.log(find(svg, 'xlink:arcrole'))
// Or: find(svg, 'xLinkArcRole')
console.log(find(html, 'xmlLang'))
// Or: find(html, 'xml:lang')
console.log(find(html, 'ariaValueNow'))
// Or: find(html, 'aria-valuenow')
```

@@ -72,4 +75,8 @@

### `propertyInformation.find(schema, name)`
This package exports the following identifiers: `html`, `svg`, `find`,
`normalize`, `hastToReact`.
There is no default export.
### `find(schema, name)`
Look up info on a property.

@@ -79,6 +86,6 @@

All standard, most legacy, and some non-standard properties are supported.
For these cases, the returned [`Info`][info] has hints about value of the
For these cases, the returned [`Info`][info] has hints about the value of the
property.
`name` can be a [valid data attribute or property][data], in which case an
`name` can also be a [valid data attribute or property][data], in which case an
[`Info`][info] object with the correctly cased `attribute` and `property` is

@@ -95,3 +102,3 @@ returned.

* `schema` ([`Schema`][schema])
— Either `propertyInformation.html` or `propertyInformation.svg`
— Either `html` or `svg`
* `name` (`string`)

@@ -105,7 +112,2 @@ — An attribute-like or property-like name that is passed through

#### Note
`find` can be accessed directly from `require('property-information/find')` as
well.
#### Example

@@ -117,4 +119,4 @@

```js
console.log(info.find(info.html, 'data-date-of-birth'))
// Or: info.find(info.html, 'dataDateOfBirth')
console.log(find(html, 'data-date-of-birth'))
// Or: find(html, 'dataDateOfBirth')
```

@@ -131,3 +133,3 @@

```js
console.log(info.find(info.html, 'un-Known'))
console.log(find(html, 'un-Known'))
```

@@ -141,3 +143,3 @@

### `propertyInformation.normalize(name)`
### `normalize(name)`

@@ -155,19 +157,14 @@ Get the cleaned case-insensitive form of an attribute or a property.

#### Note
`normalize` can be accessed directly from
`require('property-information/normalize')` as well.
#### Example
```js
info.html.normal[info.normalize('for')] // => 'htmlFor'
info.svg.normal[info.normalize('VIEWBOX')] // => 'viewBox'
info.html.normal[info.normalize('unknown')] // => undefined
info.html.normal[info.normalize('accept-charset')] // => 'acceptCharset'
html.normal[normalize('for')] // => 'htmlFor'
svg.normal[normalize('VIEWBOX')] // => 'viewBox'
html.normal[normalize('unknown')] // => undefined
html.normal[normalize('accept-charset')] // => 'acceptCharset'
```
### `propertyInformation.html`
### `html`
### `propertyInformation.svg`
### `svg`

@@ -178,14 +175,8 @@ [`Schema`][schema] for either HTML or SVG, containing info on properties from

#### Note
`html` and `svg` can be accessed directly from
`require('property-information/html')` and `require('property-information/svg')`
as well.
#### Example
```js
console.log(info.html.property.htmlFor)
console.log(info.svg.property.viewBox)
console.log(info.html.property.unknown)
console.log(html.property.htmlFor)
console.log(svg.property.viewBox)
console.log(html.property.unknown)
```

@@ -254,8 +245,6 @@

> Accessible through `require('property-information/hast-to-react.json')`
[hast][] is close to [React][], but differs in a couple of cases.
To get a React property from a hast property, check if it is in
[`hast-to-react`][hast-to-react] (`Object.<string>`), if it is, then use the
corresponding value, otherwise, use the hast property.
To get a React property from a hast property, check if it is in `hastToReact`
(`Object.<string>`), if it is, then use the corresponding value, otherwise, use
the hast property.

@@ -916,5 +905,5 @@ ## Support

[build-badge]: https://img.shields.io/travis/wooorm/property-information.svg
[build-badge]: https://github.com/wooorm/property-information/workflows/main/badge.svg
[build]: https://travis-ci.org/wooorm/property-information
[build]: https://github.com/wooorm/property-information/actions

@@ -951,8 +940,6 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/property-information.svg

[normalize]: #propertyinformationnormalizename
[normalize]: #normalizename
[react]: https://github.com/facebook/react
[hast-to-react]: hast-to-react.json
[hast]: https://github.com/syntax-tree/hast#propertyname
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