Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 3.2.0 to 4.0.0

find.js

264

index.js

@@ -1,260 +0,6 @@

'use strict';
'use strict'
/* Expose. */
module.exports = getPropertyInformation;
/* Constants. */
var USE_ATTRIBUTE = 0x1;
var USE_PROPERTY = 0x2;
var BOOLEAN_VALUE = 0x8;
var NUMERIC_VALUE = 0x10;
var POSITIVE_NUMERIC_VALUE = 0x20 | 0x10;
var OVERLOADED_BOOLEAN_VALUE = 0x40;
var SPACE_SEPARATED = 0x80;
var COMMA_SEPARATED = 0x100;
/* Map of properties. Names are camel-cased properties. */
var propertyConfig = {
/* Standard Properties. */
abbr: null,
accept: COMMA_SEPARATED,
acceptCharset: SPACE_SEPARATED,
accessKey: SPACE_SEPARATED,
action: null,
allowFullScreen: USE_ATTRIBUTE | BOOLEAN_VALUE,
allowTransparency: USE_ATTRIBUTE,
alt: null,
/* https://html.spec.whatwg.org/#attr-link-as */
as: null,
async: BOOLEAN_VALUE,
autoComplete: SPACE_SEPARATED,
autoFocus: BOOLEAN_VALUE,
autoPlay: BOOLEAN_VALUE,
capture: USE_ATTRIBUTE | BOOLEAN_VALUE,
cellPadding: null,
cellSpacing: null,
challenge: USE_ATTRIBUTE,
charSet: USE_ATTRIBUTE,
checked: USE_PROPERTY | BOOLEAN_VALUE,
cite: null,
/* To set className on SVG elements, it's necessary to
* use .setAttribute; this works on HTML elements too
* in all browsers except IE8. */
className: USE_ATTRIBUTE | SPACE_SEPARATED,
cols: USE_ATTRIBUTE | POSITIVE_NUMERIC_VALUE,
colSpan: null,
command: null,
content: null,
contentEditable: null,
contextMenu: USE_ATTRIBUTE,
controls: USE_PROPERTY | BOOLEAN_VALUE,
/* https://github.com/WICG/controls-list/blob/gh-pages/explainer.md */
controlsList: SPACE_SEPARATED,
coords: NUMERIC_VALUE | COMMA_SEPARATED,
crossOrigin: null,
/* For `<object />` acts as `src`. */
data: null,
dateTime: USE_ATTRIBUTE,
default: BOOLEAN_VALUE,
defer: BOOLEAN_VALUE,
dir: null,
dirName: null,
disabled: USE_ATTRIBUTE | BOOLEAN_VALUE,
download: OVERLOADED_BOOLEAN_VALUE,
draggable: null,
dropzone: SPACE_SEPARATED,
encType: null,
form: USE_ATTRIBUTE,
formAction: USE_ATTRIBUTE,
formEncType: USE_ATTRIBUTE,
formMethod: USE_ATTRIBUTE,
formNoValidate: BOOLEAN_VALUE,
formTarget: USE_ATTRIBUTE,
frameBorder: USE_ATTRIBUTE,
headers: SPACE_SEPARATED,
height: USE_ATTRIBUTE | POSITIVE_NUMERIC_VALUE,
hidden: USE_ATTRIBUTE | BOOLEAN_VALUE,
high: NUMERIC_VALUE,
href: null,
hrefLang: null,
htmlFor: SPACE_SEPARATED,
httpEquiv: SPACE_SEPARATED,
id: USE_PROPERTY,
inputMode: USE_ATTRIBUTE,
/* Web Components */
is: USE_ATTRIBUTE,
isMap: BOOLEAN_VALUE,
keyParams: USE_ATTRIBUTE,
keyType: USE_ATTRIBUTE,
kind: null,
label: null,
lang: null,
list: USE_ATTRIBUTE,
loop: USE_PROPERTY | BOOLEAN_VALUE,
low: NUMERIC_VALUE,
manifest: USE_ATTRIBUTE,
marginHeight: NUMERIC_VALUE,
marginWidth: NUMERIC_VALUE,
max: null,
maxLength: USE_ATTRIBUTE | POSITIVE_NUMERIC_VALUE,
media: USE_ATTRIBUTE,
mediaGroup: null,
menu: null,
method: null,
min: null,
minLength: USE_ATTRIBUTE | POSITIVE_NUMERIC_VALUE,
multiple: USE_PROPERTY | BOOLEAN_VALUE,
muted: USE_PROPERTY | BOOLEAN_VALUE,
name: null,
nonce: null,
noValidate: BOOLEAN_VALUE,
open: BOOLEAN_VALUE,
optimum: NUMERIC_VALUE,
pattern: null,
ping: SPACE_SEPARATED,
placeholder: null,
/* https://html.spec.whatwg.org/#attr-video-playsinline */
playsInline: BOOLEAN_VALUE,
poster: null,
preload: null,
/* https://html.spec.whatwg.org/#dom-head-profile */
profile: null,
radioGroup: null,
readOnly: USE_PROPERTY | BOOLEAN_VALUE,
/* https://html.spec.whatwg.org/#attr-link-referrerpolicy */
referrerPolicy: null,
/* `rel` is `relList` in DOM */
rel: SPACE_SEPARATED | USE_ATTRIBUTE,
required: BOOLEAN_VALUE,
reversed: BOOLEAN_VALUE,
role: USE_ATTRIBUTE,
rows: USE_ATTRIBUTE | POSITIVE_NUMERIC_VALUE,
rowSpan: POSITIVE_NUMERIC_VALUE,
sandbox: SPACE_SEPARATED,
scope: null,
scoped: BOOLEAN_VALUE,
scrolling: null,
seamless: USE_ATTRIBUTE | BOOLEAN_VALUE,
selected: USE_PROPERTY | BOOLEAN_VALUE,
shape: null,
size: USE_ATTRIBUTE | POSITIVE_NUMERIC_VALUE,
sizes: USE_ATTRIBUTE | SPACE_SEPARATED,
/* https://html.spec.whatwg.org/#attr-slot */
slot: null,
sortable: BOOLEAN_VALUE,
sorted: SPACE_SEPARATED,
span: POSITIVE_NUMERIC_VALUE,
spellCheck: null,
src: null,
srcDoc: USE_PROPERTY,
srcLang: null,
srcSet: USE_ATTRIBUTE | COMMA_SEPARATED,
start: NUMERIC_VALUE,
step: null,
style: null,
summary: null,
tabIndex: NUMERIC_VALUE,
target: null,
title: null,
translate: null,
type: null,
typeMustMatch: BOOLEAN_VALUE,
useMap: null,
value: USE_PROPERTY,
volume: POSITIVE_NUMERIC_VALUE,
width: USE_ATTRIBUTE | NUMERIC_VALUE,
wmode: USE_ATTRIBUTE,
wrap: null,
/* Non-standard Properties. */
/* `autoCapitalize` and `autoCorrect` are supported in
* Mobile Safari for keyboard hints. */
autoCapitalize: null,
autoCorrect: null,
/* `autoSave` allows WebKit/Blink to persist values of
* input fields on page reloads */
autoSave: null,
/* `itemProp`, `itemScope`, `itemType` are for Microdata
* support. See http://schema.org/docs/gs.html */
itemProp: USE_ATTRIBUTE | SPACE_SEPARATED,
itemScope: USE_ATTRIBUTE | BOOLEAN_VALUE,
itemType: USE_ATTRIBUTE | SPACE_SEPARATED,
/* `itemID` and `itemRef` are for Microdata support as well
* but only specified in the the WHATWG spec document.
* See https://html.spec.whatwg.org/multipage/
* microdata.html#microdata-dom-api */
itemID: USE_ATTRIBUTE,
itemRef: USE_ATTRIBUTE | SPACE_SEPARATED,
/* `property` is supported for OpenGraph in meta tags. */
property: null,
/* `results` show looking glass icon and recent searches
* on input search fields in WebKit/Blink */
results: null,
/* IE-only attribute that specifies security
* restrictions on an iframe as an alternative to the
* sandbox attribute on IE < 10 */
security: USE_ATTRIBUTE,
/* IE-only attribute that controls focus behavior */
unselectable: USE_ATTRIBUTE,
/* Ancient. */
xmlLang: USE_ATTRIBUTE,
xmlBase: USE_ATTRIBUTE
};
/* Map of properties to attributes.
* Names are lower-case properties.
* Values are HTML attributes. */
var propertyToAttributeMapping = {
xmlbase: 'xml:base',
xmllang: 'xml:lang',
classname: 'class',
htmlfor: 'for',
httpequiv: 'http-equiv',
acceptcharset: 'accept-charset'
};
/* Expand config. */
var information = {};
var property;
var name;
var config;
getPropertyInformation.all = information;
for (property in propertyConfig) {
name = lower(property);
name = propertyToAttributeMapping[name] || name;
config = propertyConfig[property];
information[name] = {
name: name,
propertyName: property,
mustUseAttribute: check(config, USE_ATTRIBUTE),
mustUseProperty: check(config, USE_PROPERTY),
boolean: check(config, BOOLEAN_VALUE),
overloadedBoolean: check(config, OVERLOADED_BOOLEAN_VALUE),
numeric: check(config, NUMERIC_VALUE),
positiveNumeric: check(config, POSITIVE_NUMERIC_VALUE),
commaSeparated: check(config, COMMA_SEPARATED),
spaceSeparated: check(config, SPACE_SEPARATED)
};
}
/* Get a config for a property. */
function getPropertyInformation(propertyName) {
var insensitive = lower(propertyName);
return information[propertyToAttributeMapping[insensitive] || insensitive];
}
/* Check a mask. */
function check(value, bitmask) {
return (value & bitmask) === bitmask;
}
/* Lower-case a string. */
function lower(value) {
return value.toLowerCase();
}
exports.html = require('./html')
exports.svg = require('./svg')
exports.normalize = require('./normalize')
exports.find = require('./find')
{
"name": "property-information",
"version": "3.2.0",
"version": "4.0.0",
"description": "Information for HTML properties",

@@ -13,3 +13,3 @@ "license": "MIT",

],
"repository": "https://github.com/wooorm/property-information",
"repository": "wooorm/property-information",
"bugs": "https://github.com/wooorm/property-information/issues",

@@ -21,22 +21,43 @@ "author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",

"files": [
"index.js"
"index.js",
"html.js",
"svg.js",
"normalize.js",
"find.js",
"lib/"
],
"dependencies": {
"xtend": "^4.0.1"
},
"devDependencies": {
"browserify": "^14.0.0",
"alpha-sort": "^2.0.1",
"arr-union": "^3.1.0",
"bail": "^1.0.3",
"browserify": "^16.0.0",
"concat-stream": "^1.6.2",
"esmangle": "^1.0.0",
"nyc": "^11.0.0",
"remark-cli": "^3.0.0",
"remark-preset-wooorm": "^3.0.0",
"html-element-attributes": "^2.0.0",
"mdast-util-to-string": "^1.0.4",
"nyc": "^12.0.0",
"object.values": "^1.0.4",
"prettier": "^1.13.7",
"remark-cli": "^5.0.0",
"remark-frontmatter": "^1.2.0",
"remark-parse": "^5.0.0",
"remark-preset-wooorm": "^4.0.0",
"svg-element-attributes": "^1.2.1",
"tape": "^4.2.0",
"xo": "^0.18.0"
"unified": "^7.0.0",
"unist-util-visit": "^1.3.1",
"xo": "^0.21.0"
},
"scripts": {
"build-md": "remark . -qfo",
"generate": "node build/generate-react",
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
"build-bundle": "browserify index.js --bare -s propertyInformation > property-information.js",
"build-mangle": "esmangle property-information.js > property-information.min.js",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint": "xo",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run build && npm run lint && npm run test-coverage"
"test": "npm run generate && npm run format && npm run build && npm run test-coverage"
},

@@ -49,4 +70,12 @@ "nyc": {

},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"space": true,
"prettier": true,
"esnext": false,

@@ -61,4 +90,6 @@ "rules": {

"remarkConfig": {
"plugins": ["preset-wooorm"]
"plugins": [
"preset-wooorm"
]
}
}
# property-information [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status]
Information for HTML properties.
Information for properties and attributes on the web-platform (HTML, SVG, ARIA,
XML, XMLNS, XLink).

@@ -16,5 +17,14 @@ ## Installation

```js
var info = require('property-information');
var info = require('property-information')
console.log(info('class'));
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')
```

@@ -24,15 +34,14 @@

```json
{
"name": "class",
"propertyName": "className",
"mustUseAttribute": true,
"mustUseProperty": false,
"boolean": false,
"overloadedBoolean": false,
"numeric": false,
"positiveNumeric": false,
"commaSeparated": false,
"spaceSeparated": true
}
```js
{ space: 'html',
attribute: 'class',
property: 'className',
spaceSeparated: true }
{ space: 'svg',
attribute: 'horiz-adv-x',
property: 'horizAdvX',
number: true }
{ space: 'xlink', attribute: 'xlink:arcrole', property: 'xLinkArcrole' }
{ space: 'xml', attribute: 'xml:lang', property: 'xmlLang' }
{ attribute: 'aria-valuenow', property: 'ariaValueNow', number: true }
```

@@ -42,60 +51,194 @@

### `propertyInformation(name)`
### `propertyInformation.find(schema, name)`
Get information for a DOM property by (case-insensitive) name.
Look up info on a property.
Returns an [`Information`][information] object, if available.
In most cases, the given `schema` contains info on the property.
All standard, most legacy, and some non-standard properties are supported.
For these cases, the returned [`Info`][info] has hints about value of the
property.
### `propertyInformation.all`
`name` can be a [valid data attribute or property][data], in which case an
[`Info`][info] object with the correctly cased `attribute` and `property` is
returned.
`Object` mapping case-insensitive names to [`Information`][information]
objects. This gives raw access to the information returned by
[`propertyInformation()`][property-information]: do not change the
objects.
`name` can be an unknown attribute, in which case an [`Info`][info] object
with `attribute` and `property` set to the given name is returned.
It is not recommended to provide unsupported legacy or recently specced
properties.
### `Information`
#### Parameters
`Object`:
* `schema` ([`Schema`][schema])
— Either `propertyInformation.html` or `propertyInformation.svg`
* `name` (`string`)
— Case-insensitive name
* `propertyName` (`string`)
— Case-sensitive IDL attribute (e.g., a `class` attribute is added in HTML
and a `className` is added in Web IDL)
* `mustUseAttribute` (`boolean`)
— Whether `setAttribute` must be used when patching a DOM node
* `mustUseProperty` (`boolean`)
— Whether `node[propertyName]` must be used when patching a DOM node
* `boolean` (`boolean`)
— Whether the value of the property is `boolean`
* `overloadedBoolean` (`boolean`)
— Whether the value of the property can be `boolean`
* `numeric` (`boolean`)
— Whether the value of the property is `number`
* `positiveNumeric` (`boolean`)
— Whether the value of the property is `number` and positive
* `spaceSeparated` (`boolean`)
— Whether the value of the property is a [space-separated][] list
* `commaSeparated` (`boolean`)
— Whether the value of the property is a [comma-separated][] list
— An attribute-like or property-like name that is passed through
[`normalize`][normalize] to find the correct info
Note that some values can be both `*Separated` _and_ a primitive, in that case
each of the tokens should be regarded as a primitive. For example, `itemScope`
is both `spaceSeparated` and `boolean`:
#### Returns
```json
{
"name": "itemscope",
"propertyName": "itemScope",
"mustUseAttribute": true,
"mustUseProperty": false,
"boolean": true,
"overloadedBoolean": false,
"numeric": false,
"positiveNumeric": false,
"commaSeparated": false,
"spaceSeparated": true
}
[`Info`][info].
#### Note
`find` can be accessed directly from `require('property-information/find')` as
well.
#### Example
Aside from the aforementioned example, which shows known HTML, SVG, XML, XLink,
and ARIA support, data properties and attributes are also supported:
```js
console.log(info.find(info.html, 'data-date-of-birth'))
// Or: info.find(info.html, 'dataDateOfBirth')
```
Yields:
```js
{ attribute: 'data-date-of-birth', property: 'dataDateOfBirth' }
```
Unknown values are passed through untouched:
```js
console.log(info.find(info.html, 'un-Known'))
```
Yields:
```js
{ attribute: 'un-Known', property: 'un-Known' }
```
### `propertyInformation.normalize(name)`
Get the cleaned case-insensitive form of an attribute or a property.
This removed all non-alphanumerical characters from `name`, and lowercases
the result.
#### Parameters
* `name` (`string`) — An attribute-like or property-like name
#### Returns
`string` that can be used to look up the properly cased property in a
[`Schema`][schema].
#### 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
```
### `propertyInformation.html`
### `propertyInformation.svg`
[`Schema`][schema] for either HTML or SVG, containing info on properties from
the primary space (HTML or SVG) and related embedded spaces (ARIA, XML, XMLNS,
XLink).
#### 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)
```
Yields:
```js
{ space: 'html',
attribute: 'for',
property: 'htmlFor',
spaceSeparated: true }
{ space: 'svg', attribute: 'viewBox', property: 'viewBox' }
undefined
```
#### `Schema`
A schema for a primary space.
* `space` (`'html'` or `'svg'`) — Primary space of the schema
* `normal` (`Object.<string>`) — Object mapping normalized attributes and
properties to properly cased properties
* `property` ([`Object.<Info>`][info]) — Object mapping properties to info
#### `Info`
Info on a property.
* `space` (`'html'`, `'svg'`, `'xml'`, `'xlink'`, `'xmlns'`, optional)
— [Space][namespace] of the property
* `attribute` (`string`) — Attribute name for the property that could be used
in markup (for example: `'aria-describedby'`, `'allowfullscreen'`,
`'xml:lang'`, `'for'`, or `'charoff'`)
* `property` (`string`) — JavaScript-style camel-cased name, based on the
DOM, but sometimes different (for example: `'ariaDescribedBy'`,
`'allowFullScreen'`, `'xmlLang'`, `'htmlFor'`, `'chOff'`)
* `boolean` (`boolean`) — The property is `boolean`.
The default value of this property is false, so it can be omitted
* `booleanish` (`boolean`) — The property is a `boolean`.
The default value of this property is something other than false, so
`false` must persist.
The value can hold a string (as is the case with `ariaChecked` and its
`'mixed'` value)
* `overloadedBoolean` (`boolean`) — The property is `boolean`.
The default value of this property is false, so it can be omitted.
The value can hold a string (as is the case with `download` as its value
reflects the name to use for the downloaded file)
* `number` (`boolean`) — The property is `number`.
These values can sometimes hold a string
* `spaceSeparated` (`boolean`) — The property is a list separated by spaces
(for example, `className`)
* `commaSeparated` (`boolean`) — The property is a list separated by commas
(for example, `srcSet`)
* `commaOrSpaceSeparated` (`boolean`) — The property is a list separated by
commas or spaces (for example, `strokeDashArray`)
* `mustUseProperty` (`boolean`) — If a DOM is used, setting the property
should be used for the change to take effect (this is true only for
`'checked'`, `'multiple'`, `'muted'`, and `'selected'`)
## Related
* [`web-namespaces`][namespace]
— List of web namespaces
* [`space-separated-tokens`](https://github.com/wooorm/space-separated-tokens)
— Parse/stringify space-separated tokens
* [`comma-separated-tokens`](https://github.com/wooorm/comma-separated-tokens)
— Parse/stringify comma-separated tokens
* [`html-tag-names`](https://github.com/wooorm/html-tag-names)
— List of HTML tags
* [`mathml-tag-names`](https://github.com/wooorm/mathml-tag-names)
— List of MathML tags
* [`svg-tag-names`](https://github.com/wooorm/svg-tag-names)
— List of SVG tags
* [`html-void-elements`](https://github.com/wooorm/html-void-elements)
— List of void HTML tag-names
* [`svg-element-attributes`](https://github.com/wooorm/svg-element-attributes)
— Map of SVG elements to allowed attributes
* [`html-element-attributes`](https://github.com/wooorm/html-element-attributes)
— Map of HTML elements to allowed attributes
* [`aria-attributes`](https://github.com/wooorm/aria-attributes)
— List of ARIA attributes
## License

@@ -126,8 +269,10 @@

[space-separated]: https://html.spec.whatwg.org/#space-separated-tokens
[data]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
[comma-separated]: https://html.spec.whatwg.org/#comma-separated-tokens
[namespace]: https://github.com/wooorm/web-namespaces
[information]: #information
[info]: #info
[property-information]: #propertyinformationname
[schema]: #schema
[normalize]: #propertyinformationnormalizename
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