@sutton-signwriting/unicode8
Version:
a javascript package for processing SignWriting in Unicode 8 (uni8) characters
75 lines (66 loc) • 1.84 kB
JavaScript
/**
* Sutton SignWriting Unicode 8 Module v1.2.0 (https://github.com/sutton-signwriting/unicode8)
* Author: Steve Slevinski (https://SteveSlevinski.me)
* Sponsor: https://patreon.com/signwriting
* Donate: https://donate.sutton-signwriting.io
*
* string.cjs is released under the MIT License.
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Object of regular expressions for symbol strings
*
* { base, fill, rotation, full }
* @alias symbol.re
* @type {object}
*/
let re$1 = {
'base': '(?:\uD836[\uDC00-\uDE8B])',
'fill': '(?:\uD836[\uDE9B-\uDE9F])',
'rotation': '(?:\uD836[\uDEA1-\uDEAF])'
};
re$1.full = `(${re$1.base})(${re$1.fill})?(${re$1.rotation})?`;
/**
* Object of regular expressions for string of symbols
*
* { full }
* @alias string.re
* @type {object}
*/
let re = {
'full': `(?:${re$1.full})+`
};
/**
* Function to parse string of uni8 symbols to array
* @function string.parse
* @param {string} uni8String - a string of uni8 symbols
* @returns {array} array of uni8 symbols
* @example
* string.parse('𝠀𝠁')
*
* return ['𝠀','𝠁']
*/
const parse = uni8String => {
const regex = `^(${re.full})`;
const m = (typeof uni8String === 'string' ? uni8String.match(new RegExp(regex)) : []) || [];
return !m[1] ? [] : [...m[1].matchAll(new RegExp(re$1.full, 'g'))].map(mm => mm[0]);
};
/**
* Function to compose uni8 string from array
* @function string.compose
* @param {array} stringArray - an array of uni8 symbols
* @returns {string} string of uni8 symbols
* @example
* string.compose(['𝠀','𝠁'])
*
* return '𝠀𝠁'
*/
const compose = stringArray => {
if (!Array.isArray(stringArray)) return undefined;
return stringArray.join('');
};
exports.compose = compose;
exports.parse = parse;
exports.re = re;
/* the end */