property-information
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'))
console.log(info.find(info.svg, 'horiz-adv-x'))
console.log(info.find(info.svg, 'xlink:arcrole'))
console.log(info.find(info.html, 'xmlLang'))
console.log(info.find(info.html, 'ariaValueNow'))
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'))
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')]
info.svg.normal[info.normalize('VIEWBOX')]
info.html.normal[info.normalize('unknown')]
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 schemanormal
(Object.<string>
) — Object mapping normalized attributes and
properties to properly cased propertiesproperty
(Object.<Info>
) — Object mapping properties to info
Info
Info on a property.
space
('html'
, 'svg'
, 'xml'
, 'xlink'
, 'xmlns'
, optional)
— Space of the propertyattribute
(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 omittedbooleanish
(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 stringspaceSeparated
(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
License
MIT © Titus Wormer
Derivative work based on React licensed under
BSD-3-Clause-Clear, © 2013-2015, Facebook, Inc.