You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.2 KiB

4 years ago
  1. # unicode-match-property-value-ecmascript [![Build status](https://travis-ci.org/mathiasbynens/unicode-match-property-value-ecmascript.svg?branch=master)](https://travis-ci.org/mathiasbynens/unicode-match-property-value-ecmascript)
  2. _unicode-match-property-value-ecmascript_ matches a given Unicode property value or [property value alias](https://github.com/mathiasbynens/unicode-property-value-aliases) to its canonical property value without applying [loose matching](https://github.com/mathiasbynens/unicode-loose-match), per the algorithm used for [RegExp Unicode property escapes in ECMAScript](https://github.com/tc39/proposal-regexp-unicode-property-escapes). Consider it a strict alternative to loose matching.
  3. ## Installation
  4. To use _unicode-match-property-value-ecmascript_ programmatically, install it as a dependency via [npm](https://www.npmjs.com/):
  5. ```bash
  6. $ npm install unicode-match-property-value-ecmascript
  7. ```
  8. Then, `require` it:
  9. ```js
  10. const matchPropertyValue = require('unicode-match-property-value-ecmascript');
  11. ```
  12. ## API
  13. This module exports a single function named `matchPropertyValue`.
  14. ### `matchPropertyValue(property, value)`
  15. This function takes a string `property` that is a canonical/unaliased Unicode property name, and a string `value`. It attemps to match `value` to a canonical Unicode property value for the given property. If there’s a match, it returns the canonical property value. Otherwise, it throws an exception.
  16. ```js
  17. // Find the canonical property value:
  18. matchPropertyValue('Script_Extensions', 'Aghb')
  19. // → 'Caucasian_Albanian'
  20. matchPropertyValue('Script_Extensions', 'Caucasian_Albanian')
  21. // → 'Caucasian_Albanian'
  22. matchPropertyValue('script_extensions', 'Caucasian_Albanian') // Note: incorrect casing.
  23. // → throws
  24. matchPropertyValue('Script_Extensions', 'caucasian_albanian') // Note: incorrect casing.
  25. // → throws
  26. ```
  27. ## Author
  28. | [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
  29. |---|
  30. | [Mathias Bynens](https://mathiasbynens.be/) |
  31. ## License
  32. _unicode-match-property-value-ecmascript_ is available under the [MIT](https://mths.be/mit) license.