UNPKG

2.24 kBJavaScriptView Raw
1
2import { parse } from './swu-parse';
3import { swu2code } from '../convert';
4
5/**
6 * Array of plane 4 code points for kinds of symbols: writing, location, and punctuation.
7 * @alias swu.kind
8 * @type {array}
9 */
10const kind = [0x40001, 0x4efa1, 0x4f2a1];
11
12/**
13 * Array of plane 4 code points for categories of symbols: hand, movement, dynamics, head, trunk & limb, location, and punctuation.
14 * @alias swu.category
15 * @type {array}
16 */
17const category = [0x40001, 0x461e1, 0x4bca1, 0x4bfa1, 0x4e8e1, 0x4efa1, 0x4f2a1];
18
19/**
20 * Array of plane 4 code points for the 30 symbol groups.
21 * @alias swu.group
22 * @type {array}
23 */
24const group = [0x40001, 0x40541, 0x40b41, 0x41981, 0x41c81, 0x43241, 0x43d81, 0x445c1, 0x44ce1, 0x45be1, 0x461e1, 0x46841, 0x46fc1, 0x47fe1, 0x485e1, 0x49301, 0x49e41, 0x4a4a1, 0x4afe1, 0x4b521, 0x4bca1, 0x4bfa1, 0x4c3c1, 0x4cfc1, 0x4d621, 0x4e161, 0x4e8e1, 0x4ec41, 0x4efa1, 0x4f2a1];
25
26/**
27 * Object of symbol ranges with starting and ending code points on plane 4.
28 *
29 * { all, writing, hand, movement, dynamic, head, hcenter, vcenter, trunk, limb, location, punctuation }
30 * @alias swu.ranges
31 * @type {object}
32 */
33const ranges = {
34 'all': [0x40001, 0x4f480],
35 'writing': [0x40001, 0x4efa0],
36 'hand': [0x40001, 0x461e0],
37 'movement': [0x461e1, 0x4bca0],
38 'dynamic': [0x4bca1, 0x4bfa0],
39 'head': [0x4bfa1, 0x4e8e0],
40 'hcenter': [0x4bfa1, 0x4e8e0],
41 'vcenter': [0x4bfa1, 0x4ec40],
42 'trunk': [0x4e8e1, 0x4ec40],
43 'limb': [0x4ec41, 0x4efa0],
44 'location': [0x4efa1, 0x4f2a0],
45 'punctuation': [0x4f2a1, 0x4f480]
46}
47
48/**
49 * Function to test if symbol is of a certain type.
50 * @function swu.isType
51 * @param {string} swuSym - an SWU symbol character
52 * @param {string} type - the name of a symbol range
53 * @returns {boolean} is symbol of specified type
54 * @example
55 * swu.isType('񀀁', 'hand')
56 *
57 * return true
58 */
59const isType = (swuSym, type) => {
60 const parsed = parse.symbol(swuSym);
61 if (parsed.symbol) {
62 const code = swu2code(parsed.symbol);
63 const range = ranges[type];
64 if (range) {
65 return (range[0] <= code && range[1] >= code);
66 }
67 }
68 return false;
69}
70
71export { kind, category, group, ranges, isType }