JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16869139
  • Score
    100M100P100Q228328F
  • License MIT

Information for HTML properties

Package Exports

  • property-information
  • property-information/find
  • property-information/html
  • property-information/normalize
  • property-information/svg

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (property-information) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

property-information Build Status Coverage Status

Information for properties and attributes on the web-platform (HTML, SVG, ARIA, XML, XMLNS, XLink).

Installation

npm:

npm install property-information

Usage

var info = require('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')

Yields:

{ 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 }

API

propertyInformation.find(schema, name)

Look up info on a property.

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 has hints about value of the property.

name can be a valid data attribute or property, in which case an Info object with the correctly cased attribute and property is returned.

name can be an unknown attribute, in which case an 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.

Parameters

  • schema (Schema) — Either propertyInformation.html or propertyInformation.svg
  • name (string) — An attribute-like or property-like name that is passed through normalize to find the correct info

Returns

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:

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

Yields:

{ attribute: 'data-date-of-birth', property: 'dataDateOfBirth' }

Unknown values are passed through untouched:

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

Yields:

{ 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.

Note

normalize can be accessed directly from require('property-information/normalize') as well.

Example

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

console.log(info.html.property.htmlFor)
console.log(info.svg.property.viewBox)
console.log(info.html.property.unknown)

Yields:

{ 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>) — Object mapping properties to info

Info

Info on a property.

  • space ('html', 'svg', 'xml', 'xlink', 'xmlns', optional) — Space 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')

License

MIT © Titus Wormer

Derivative work based on React licensed under BSD-3-Clause-Clear, © 2013-2015, Facebook, Inc.