What is unicode-match-property-value-ecmascript?
The unicode-match-property-value-ecmascript npm package is designed for matching Unicode property values in a given input according to the ECMAScript specification. It is primarily used in the context of regular expressions that involve Unicode property escapes, providing a way to ensure that input strings conform to expected Unicode property values.
What are unicode-match-property-value-ecmascript's main functionalities?
Matching Unicode Property Values
This feature allows you to match a given Unicode property (e.g., 'Script') and value (e.g., 'Hani') to check if it conforms to the ECMAScript specification. It's useful for validating and transforming Unicode property values in JavaScript regular expressions.
"use strict";
const matchPropertyValue = require('unicode-match-property-value-ecmascript');
try {
const result = matchPropertyValue('Script', 'Hani');
console.log(result); // Expected output: 'Han'
} catch (error) {
console.error(error);
}
Other packages similar to unicode-match-property-value-ecmascript
regexpu-core
regexpu-core is a package that transforms Unicode-aware regular expressions into equivalent ES5-compatible versions. While it focuses on transforming regular expressions, unicode-match-property-value-ecmascript specifically matches property values according to the ECMAScript specification. Both packages are useful for dealing with Unicode in JavaScript regular expressions, but they serve slightly different purposes.
unicode-property-aliases-ecmascript
unicode-property-aliases-ecmascript provides the aliases of Unicode property names and values as per the ECMAScript specification. It complements unicode-match-property-value-ecmascript by offering the aliases for property names and values, whereas unicode-match-property-value-ecmascript focuses on matching the property values themselves. Together, they can be used to enhance handling of Unicode properties in JavaScript.
unicode-match-property-value-ecmascript
unicode-match-property-value-ecmascript matches a given Unicode property value or property value alias to its canonical property value without applying loose matching, per the algorithm used for RegExp Unicode property escapes in ECMAScript. Consider it a strict alternative to loose matching.
Installation
To use unicode-match-property-value-ecmascript programmatically, install it as a dependency via npm:
$ npm install unicode-match-property-value-ecmascript
Then, require
it:
const matchPropertyValue = require('unicode-match-property-value-ecmascript');
API
This module exports a single function named matchPropertyValue
.
matchPropertyValue(property, value)
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.
matchPropertyValue('Script_Extensions', 'Aghb')
matchPropertyValue('Script_Extensions', 'Caucasian_Albanian')
matchPropertyValue('script_extensions', 'Caucasian_Albanian')
matchPropertyValue('Script_Extensions', 'caucasian_albanian')
Author
License
unicode-match-property-value-ecmascript is available under the MIT license.