property-information
Advanced tools
| export {find} from './lib/find.js' | ||
| export {hastToReact} from './lib/hast-to-react.js' | ||
| export {normalize} from './lib/normalize.js' | ||
| export var html: import('./lib/util/schema.js').Schema | ||
| export var svg: import('./lib/util/schema.js').Schema |
| export var aria: import('./util/schema.js').Schema |
| /** | ||
| * @param {import('./util/schema.js').Schema} schema | ||
| * @param {string} value | ||
| * @returns {import('./util/info.js').Info} | ||
| */ | ||
| export function find( | ||
| schema: import('./util/schema.js').Schema, | ||
| value: string | ||
| ): import('./util/info.js').Info |
+80
| import {normalize} from './normalize.js' | ||
| import {DefinedInfo} from './util/defined-info.js' | ||
| import {Info} from './util/info.js' | ||
| var valid = /^data[-\w.:]+$/i | ||
| var dash = /-[a-z]/g | ||
| var cap = /[A-Z]/g | ||
| /** | ||
| * @param {import('./util/schema.js').Schema} schema | ||
| * @param {string} value | ||
| * @returns {import('./util/info.js').Info} | ||
| */ | ||
| export function find(schema, value) { | ||
| var normal = normalize(value) | ||
| var prop = value | ||
| var Type = Info | ||
| if (normal in schema.normal) { | ||
| return schema.property[schema.normal[normal]] | ||
| } | ||
| if (normal.length > 4 && normal.slice(0, 4) === 'data' && valid.test(value)) { | ||
| // Attribute or property. | ||
| if (value.charAt(4) === '-') { | ||
| prop = datasetToProperty(value) | ||
| } else { | ||
| value = datasetToAttribute(value) | ||
| } | ||
| Type = DefinedInfo | ||
| } | ||
| return new Type(prop, value) | ||
| } | ||
| /** | ||
| * @param {string} attribute | ||
| * @returns {string} | ||
| */ | ||
| function datasetToProperty(attribute) { | ||
| var value = attribute.slice(5).replace(dash, camelcase) | ||
| return 'data' + value.charAt(0).toUpperCase() + value.slice(1) | ||
| } | ||
| /** | ||
| * @param {string} property | ||
| * @returns {string} | ||
| */ | ||
| function datasetToAttribute(property) { | ||
| var value = property.slice(4) | ||
| if (dash.test(value)) { | ||
| return property | ||
| } | ||
| value = value.replace(cap, kebab) | ||
| if (value.charAt(0) !== '-') { | ||
| value = '-' + value | ||
| } | ||
| return 'data' + value | ||
| } | ||
| /** | ||
| * @param {string} $0 | ||
| * @returns {string} | ||
| */ | ||
| function kebab($0) { | ||
| return '-' + $0.toLowerCase() | ||
| } | ||
| /** | ||
| * @param {string} $0 | ||
| * @returns {string} | ||
| */ | ||
| function camelcase($0) { | ||
| return $0.charAt(1).toUpperCase() | ||
| } |
| export namespace hastToReact { | ||
| const classId: string | ||
| const dataType: string | ||
| const itemId: string | ||
| const strokeDashArray: string | ||
| const strokeDashOffset: string | ||
| const strokeLineCap: string | ||
| const strokeLineJoin: string | ||
| const strokeMiterLimit: string | ||
| const typeOf: string | ||
| const xLinkActuate: string | ||
| const xLinkArcRole: string | ||
| const xLinkHref: string | ||
| const xLinkRole: string | ||
| const xLinkShow: string | ||
| const xLinkTitle: string | ||
| const xLinkType: string | ||
| const xmlnsXLink: string | ||
| } |
| export var hastToReact = { | ||
| classId: 'classID', | ||
| dataType: 'datatype', | ||
| itemId: 'itemID', | ||
| strokeDashArray: 'strokeDasharray', | ||
| strokeDashOffset: 'strokeDashoffset', | ||
| strokeLineCap: 'strokeLinecap', | ||
| strokeLineJoin: 'strokeLinejoin', | ||
| strokeMiterLimit: 'strokeMiterlimit', | ||
| typeOf: 'typeof', | ||
| xLinkActuate: 'xlinkActuate', | ||
| xLinkArcRole: 'xlinkArcrole', | ||
| xLinkHref: 'xlinkHref', | ||
| xLinkRole: 'xlinkRole', | ||
| xLinkShow: 'xlinkShow', | ||
| xLinkTitle: 'xlinkTitle', | ||
| xLinkType: 'xlinkType', | ||
| xmlnsXLink: 'xmlnsXlink' | ||
| } |
| export var html: import('./util/schema.js').Schema |
| /** | ||
| * @param {string} value | ||
| * @returns {string} | ||
| */ | ||
| export function normalize(value: string): string |
| /** | ||
| * @param {string} value | ||
| * @returns {string} | ||
| */ | ||
| export function normalize(value) { | ||
| return value.toLowerCase() | ||
| } |
| export var svg: import('./util/schema.js').Schema |
| /** | ||
| * @param {Object.<string, string>} attributes | ||
| * @param {string} property | ||
| * @returns {string} | ||
| */ | ||
| export function caseInsensitiveTransform( | ||
| attributes: { | ||
| [x: string]: string | ||
| }, | ||
| property: string | ||
| ): string |
| /** | ||
| * @param {Object.<string, string>} attributes | ||
| * @param {string} attribute | ||
| * @returns {string} | ||
| */ | ||
| export function caseSensitiveTransform( | ||
| attributes: { | ||
| [x: string]: string | ||
| }, | ||
| attribute: string | ||
| ): string |
| /** | ||
| * @param {Definition} definition | ||
| * @returns {import('./schema.js').Schema} | ||
| */ | ||
| export function create(definition: Definition): import('./schema.js').Schema | ||
| export type Properties = import('./schema.js').Properties | ||
| export type Normal = import('./schema.js').Normal | ||
| export type Info = import('./info.js').Info | ||
| export type Attributes = { | ||
| [x: string]: string | ||
| } | ||
| export type Definition = { | ||
| properties: { | ||
| [x: string]: number | null | ||
| } | ||
| transform: (attributes: Attributes, property: string) => string | ||
| space?: string | ||
| attributes?: Attributes | ||
| mustUseProperty?: Array<string> | ||
| } |
| export class DefinedInfo extends Info { | ||
| /** | ||
| * @constructor | ||
| * @param {string} property | ||
| * @param {string} attribute | ||
| * @param {number} [mask] | ||
| * @param {string} [space] | ||
| */ | ||
| constructor( | ||
| property: string, | ||
| attribute: string, | ||
| mask?: number, | ||
| space?: string | ||
| ) | ||
| } | ||
| import {Info} from './info.js' |
| export class Info { | ||
| /** | ||
| * @constructor | ||
| * @param {string} property | ||
| * @param {string} attribute | ||
| */ | ||
| constructor(property: string, attribute: string) | ||
| property: string | ||
| attribute: string | ||
| /** @type {string|null} */ | ||
| space: string | null | ||
| boolean: boolean | ||
| booleanish: boolean | ||
| overloadedBoolean: boolean | ||
| number: boolean | ||
| commaSeparated: boolean | ||
| spaceSeparated: boolean | ||
| commaOrSpaceSeparated: boolean | ||
| mustUseProperty: boolean | ||
| defined: boolean | ||
| } |
| /** | ||
| * @typedef {import('./schema.js').Properties} Properties | ||
| * @typedef {import('./schema.js').Normal} Normal | ||
| */ | ||
| /** | ||
| * @param {import('./schema.js').Schema[]} definitions | ||
| * @param {string} space | ||
| * @returns {import('./schema.js').Schema} | ||
| */ | ||
| export function merge( | ||
| definitions: import('./schema.js').Schema[], | ||
| space: string | ||
| ): import('./schema.js').Schema | ||
| export type Properties = import('./schema.js').Properties | ||
| export type Normal = import('./schema.js').Normal |
| /** | ||
| * @typedef {import('./info.js').Info} Info | ||
| * @typedef {Object.<string, Info>} Properties | ||
| * @typedef {Object.<string, string>} Normal | ||
| */ | ||
| export class Schema { | ||
| /** | ||
| * @constructor | ||
| * @param {Properties} property | ||
| * @param {Normal} normal | ||
| * @param {string} [space] | ||
| */ | ||
| constructor(property: Properties, normal: Normal, space?: string) | ||
| property: Properties | ||
| normal: Normal | ||
| space: string | null | ||
| } | ||
| export type Info = import('./info.js').Info | ||
| export type Properties = { | ||
| [x: string]: Info | ||
| } | ||
| export type Normal = { | ||
| [x: string]: string | ||
| } |
| export var boolean: number | ||
| export var booleanish: number | ||
| export var overloadedBoolean: number | ||
| export var number: number | ||
| export var spaceSeparated: number | ||
| export var commaSeparated: number | ||
| export var commaOrSpaceSeparated: number |
| export var xlink: import('./util/schema.js').Schema |
| export var xml: import('./util/schema.js').Schema |
| export var xmlns: import('./util/schema.js').Schema |
+12
-5
@@ -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') |
+8
-9
@@ -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() | ||
| } |
+11
-13
@@ -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: { |
+10
-12
@@ -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 | ||
| } |
+48
-25
@@ -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) | ||
| } |
+29
-27
@@ -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) { |
+24
-22
@@ -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 |
+19
-21
@@ -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) | ||
| } |
+25
-15
@@ -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 |
+8
-10
@@ -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 | ||
| } |
+7
-4
@@ -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() | ||
| } |
+8
-9
@@ -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() | ||
| } |
+5
-12
@@ -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} | ||
| }) |
+40
-46
| { | ||
| "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 | ||
| } | ||
| } |
+45
-58
@@ -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 |
-65
| 'use strict' | ||
| var normalize = require('./normalize') | ||
| var DefinedInfo = require('./lib/util/defined-info') | ||
| var Info = require('./lib/util/info') | ||
| var data = 'data' | ||
| module.exports = find | ||
| var valid = /^data[-\w.:]+$/i | ||
| var dash = /-[a-z]/g | ||
| var cap = /[A-Z]/g | ||
| function find(schema, value) { | ||
| var normal = normalize(value) | ||
| var prop = value | ||
| var Type = Info | ||
| if (normal in schema.normal) { | ||
| return schema.property[schema.normal[normal]] | ||
| } | ||
| if (normal.length > 4 && normal.slice(0, 4) === data && valid.test(value)) { | ||
| // Attribute or property. | ||
| if (value.charAt(4) === '-') { | ||
| prop = datasetToProperty(value) | ||
| } else { | ||
| value = datasetToAttribute(value) | ||
| } | ||
| Type = DefinedInfo | ||
| } | ||
| return new Type(prop, value) | ||
| } | ||
| function datasetToProperty(attribute) { | ||
| var value = attribute.slice(5).replace(dash, camelcase) | ||
| return data + value.charAt(0).toUpperCase() + value.slice(1) | ||
| } | ||
| function datasetToAttribute(property) { | ||
| var value = property.slice(4) | ||
| if (dash.test(value)) { | ||
| return property | ||
| } | ||
| value = value.replace(cap, kebab) | ||
| if (value.charAt(0) !== '-') { | ||
| value = '-' + value | ||
| } | ||
| return data + value | ||
| } | ||
| function kebab($0) { | ||
| return '-' + $0.toLowerCase() | ||
| } | ||
| function camelcase($0) { | ||
| return $0.charAt(1).toUpperCase() | ||
| } |
| { | ||
| "classId": "classID", | ||
| "dataType": "datatype", | ||
| "itemId": "itemID", | ||
| "strokeDashArray": "strokeDasharray", | ||
| "strokeDashOffset": "strokeDashoffset", | ||
| "strokeLineCap": "strokeLinecap", | ||
| "strokeLineJoin": "strokeLinejoin", | ||
| "strokeMiterLimit": "strokeMiterlimit", | ||
| "typeOf": "typeof", | ||
| "xLinkActuate": "xlinkActuate", | ||
| "xLinkArcRole": "xlinkArcrole", | ||
| "xLinkHref": "xlinkHref", | ||
| "xLinkRole": "xlinkRole", | ||
| "xLinkShow": "xlinkShow", | ||
| "xLinkTitle": "xlinkTitle", | ||
| "xLinkType": "xlinkType", | ||
| "xmlnsXLink": "xmlnsXlink" | ||
| } |
-10
| 'use strict' | ||
| var merge = require('./lib/util/merge') | ||
| var xlink = require('./lib/xlink') | ||
| var xml = require('./lib/xml') | ||
| var xmlns = require('./lib/xmlns') | ||
| var aria = require('./lib/aria') | ||
| var html = require('./lib/html') | ||
| module.exports = merge([xml, xlink, xmlns, aria, html]) |
| 'use strict' | ||
| module.exports = normalize | ||
| function normalize(value) { | ||
| return value.toLowerCase() | ||
| } |
-10
| 'use strict' | ||
| var merge = require('./lib/util/merge') | ||
| var xlink = require('./lib/xlink') | ||
| var xml = require('./lib/xml') | ||
| var xmlns = require('./lib/xmlns') | ||
| var aria = require('./lib/aria') | ||
| var svg = require('./lib/svg') | ||
| module.exports = merge([xml, xlink, xmlns, aria, svg]) |
101530
5.42%0
-100%39
69.57%1437
18.76%Yes
NaN23
21.05%931
-1.38%- Removed
- Removed