CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
find.js98 linesDownload Raw Back to lib
1/**2 * @import {Schema} from 'property-information'3 */4 5import {DefinedInfo} from './util/defined-info.js'6import {Info} from './util/info.js'7import {normalize} from './normalize.js'8 9const cap = /[A-Z]/g10const dash = /-[a-z]/g11const valid = /^data[-\w.:]+$/i12 13/**14 * Look up info on a property.15 *16 * In most cases the given `schema` contains info on the property.17 * All standard,18 * most legacy,19 * and some non-standard properties are supported.20 * For these cases,21 * the returned `Info` has hints about the value of the property.22 *23 * `name` can also be a valid data attribute or property,24 * in which case an `Info` object with the correctly cased `attribute` and25 * `property` is returned.26 *27 * `name` can be an unknown attribute,28 * in which case an `Info` object with `attribute` and `property` set to the29 * given name is returned.30 * It is not recommended to provide unsupported legacy or recently specced31 * properties.32 *33 *34 * @param {Schema} schema35 *   Schema;36 *   either the `html` or `svg` export.37 * @param {string} value38 *   An attribute-like or property-like name;39 *   it will be passed through `normalize` to hopefully find the correct info.40 * @returns {Info}41 *   Info.42 */43export function find(schema, value) {44  const normal = normalize(value)45  let property = value46  let Type = Info47 48  if (normal in schema.normal) {49    return schema.property[schema.normal[normal]]50  }51 52  if (normal.length > 4 && normal.slice(0, 4) === 'data' && valid.test(value)) {53    // Attribute or property.54    if (value.charAt(4) === '-') {55      // Turn it into a property.56      const rest = value.slice(5).replace(dash, camelcase)57      property = 'data' + rest.charAt(0).toUpperCase() + rest.slice(1)58    } else {59      // Turn it into an attribute.60      const rest = value.slice(4)61 62      if (!dash.test(rest)) {63        let dashes = rest.replace(cap, kebab)64 65        if (dashes.charAt(0) !== '-') {66          dashes = '-' + dashes67        }68 69        value = 'data' + dashes70      }71    }72 73    Type = DefinedInfo74  }75 76  return new Type(property, value)77}78 79/**80 * @param {string} $081 *   Value.82 * @returns {string}83 *   Kebab.84 */85function kebab($0) {86  return '-' + $0.toLowerCase()87}88 89/**90 * @param {string} $091 *   Value.92 * @returns {string}93 *   Camel.94 */95function camelcase($0) {96  return $0.charAt(1).toUpperCase()97}98 
basant307/AI_Governance_Project · CoolFace