Core Modules

@sutton-signwriting/core

Gitter version npm downloads

Core Package Mindmap

@sutton-signwriting/core is a javascript package for node and browsers that supports general processing of SignWriting text.

This package supports both Formal SignWriting in ASCII (FSW) and SignWriting in Unicode (SWU) character sets, along with the associated query languages and style string. See draft-slevinski-formal-signwriting for detailed specification.

Author: https://SteveSlevinski.me
Channel: https://www.youtube.com/channel/UCXu4AXlG0rXFtk_5SzumDow
Support: https://www.patreon.com/signwriting
Donate: https://donate.sutton-signwriting.io

Useful links

Types of files

The source is written in small ES Modules available in the src directory along with the associated tests.

The distribution is available in three flavors. 28 KB for the whole library minified. Individual modules as small as 3 KB.

  • .js - Universal Module Definition
  • .cjs - CommonJS
  • .mjs - ES Module

Installation

Download and Install with NPM

npm install @sutton-signwriting/core

Developer Installation

Download from GitHub and Install Development Dependencies

wget https://github.com/sutton-signwriting/core/archive/master.zip
unzip master.zip
cd core-master
npm install

Install tsc command line tool

sudo apt install node-typescript

Usage

Using in Node

// import entire library
const core = require('@sutton-signwriting/core');

// import individual module
const fsw = require('@sutton-signwriting/core/fsw');

Using in the Browser

Local files

// import entire library
// available as ssw.core
<script src="core.js"></script>

// import individual module
// available as ssw.fsw
<script src="fsw/fsw.js"></script>

Unpkg

// import entire library
// available as ssw.core
<script src="https://unpkg.com/@sutton-signwriting/core@1.6.0"></script>

// import individual module
// available as ssw.fsw
<script src="https://unpkg.com/@sutton-signwriting/core@1.6.0/fsw/fsw.js"></script>

License

MIT

SignWriting General Interest

fsw

The fsw module contains functions for handling Formal SignWriting in ASCII (FSW) characters. FSW characters definition

fsw

fsw.re

Object of regular expressions for FSW strings

fsw.re
Properties
symbol (string) : regular expressions for a symbol
coord (string) : regular expressions for a coordinate
sort (string) : regular expressions for the sorting marker
box (string) : regular expression for a signbox marker
prefix (string) : regular expression for a sorting marker followed by one or more symbols
spatial (string) : regular expression for a symbol followed by a coordinate
signbox (string) : regular expression for a signbox marker, max coordinate and zero or more spatial symbols
sign (string) : regular expression for an optional prefix followed by a signbox
sortable (string) : regular expression for a mandatory prefix followed by a signbox

fsw.parse.symbol

Function to parse an fsw symbol with optional coordinate and style string

fsw.parse.symbol(fswSym: string): SymbolObject
Parameters
fswSym (string) an fsw symbol
Returns
SymbolObject: elements of fsw symbol
Example
fsw.parse.symbol('S10000500x500-C')

return {
 'symbol': 'S10000',
 'coord': [500, 500],
 'style': '-C'
}

fsw.parse.sign

Function to parse an fsw sign with style string

fsw.parse.sign(fswSign: string): SignObject
Parameters
fswSign (string) an fsw sign
Returns
SignObject: elements of fsw sign
Example
fsw.parse.sign('AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475-C')

return {
 sequence: ['S10011', 'S10019', 'S2e704', 'S2e748'],
 box: 'M',
 max: [525, 535],
 spatials: [
   {
     symbol: 'S2e748',
     coord: [483, 510]
   },
   {
     symbol: 'S10011',
     coord: [501, 466]
   },
   {
     symbol: 'S2e704',
     coord: [510, 500]
   },
   {
     symbol: 'S10019',
     coord: [476, 475]
   }
 ],
 style: '-C'
}

fsw.parse.text

Function to parse an fsw text

fsw.parse.text(fswText: string): Array<string>
Parameters
fswText (string) an fsw text
Returns
Array<string>: fsw signs and punctuations
Example
fsw.parse.text('AS14c20S27106M518x529S14c20481x471S27106503x489 AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468 S38800464x496')

return [
 'AS14c20S27106M518x529S14c20481x471S27106503x489',
 'AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468',
 'S38800464x496'
]

fsw.compose.symbol

Function to compose an fsw symbol with optional coordinate and style string

fsw.compose.symbol(fswSymObject: SymbolObject): string
Parameters
fswSymObject (SymbolObject) an fsw symbol object
Returns
string: an fsw symbol string
Example
fsw.compose.symbol({
 'symbol': 'S10000',
 'coord': [480, 480],
 'style': '-C'
})

return 'S10000480x480-C'

fsw.compose.sign

Function to compose an fsw sign with style string

fsw.compose.sign(fswSignObject: SignObject): string
Parameters
fswSignObject (SignObject) an fsw symbol object
Returns
string: an fsw sign string
Example
fsw.compose.sign({
 sequence: ['S10011', 'S10019', 'S2e704', 'S2e748'],
 box: 'M',
 max: [525, 535],
 spatials: [
   {
     symbol: 'S2e748',
     coord: [483, 510]
   },
   {
     symbol: 'S10011',
     coord: [501, 466]
   },
   {
     symbol: 'S2e704',
     coord: [510, 500]
   },
   {
     symbol: 'S10019',
     coord: [476, 475]
   }
 ],
 style: '-C'
})

return 'AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475-C'

fsw.info

Function to gather sizing information about an fsw sign or symbol

fsw.info(fsw: string): SegmentInfo
Parameters
fsw (string) an fsw sign or symbol
Returns
SegmentInfo: information about the fsw string
Example
fsw.info('AS14c20S27106L518x529S14c20481x471S27106503x489-P10Z2')

return {
  minX: 481,
  minY: 471,
  width: 37,
  height: 58,
  lane: -1,
  padding: 10,
  segment: 'sign',
  zoom: 2
}

fsw.columnDefaultsMerge

Function to an object of column options with default values

fsw.columnDefaultsMerge(options: ColumnOptions): ColumnOptions
Parameters
options (ColumnOptions) object of column options
Returns
ColumnOptions: object of column options merged with column defaults
Example
fsw.columnDefaultsMerge({height: 500,width:150})

return {
  "height": 500,
  "width": 150,
  "offset": 50,
  "pad": 20,
  "margin": 5,
  "dynamic": false,
  "punctuation": {
    "spacing": true,
    "pad": 30,
    "pull": true
  },
  "style": {
    "detail": [
      "black",
      "white"
    ],
    "zoom": 1
  }
}

fsw.columns

Function to transform an FSW text to an array of columns

fsw.columns(fswText: string, options: ColumnOptions): {options: ColumnOptions, widths: Array<number>, columns: ColumnData}
Parameters
fswText (string) FSW text of signs and punctuation
options (ColumnOptions) object of column options
Returns
{options: ColumnOptions, widths: Array<number>, columns: ColumnData}: object of column options, widths array, and column data
Example
fsw.columns('AS14c20S27106M518x529S14c20481x471S27106503x489 AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468 S38800464x496', {height: 500,width:150})

return {
  "options": {
    "height": 500,
    "width": 150,
    "offset": 50,
    "pad": 20,
    "margin": 5,
    "dynamic": false,
    "punctuation": {
      "spacing": true,
      "pad": 30,
      "pull": true
    },
    "style": {
      "detail": [
        "black",
        "white"
      ],
      "zoom": 1
    }
  },
  "widths": [
    150
  ],
  "columns": [
    [
      {
        "x": 56,
        "y": 20,
        "minX": 481,
        "minY": 471,
        "width": 37,
        "height": 58,
        "lane": 0,
        "padding": 0,
        "segment": "sign",
        "text": "AS14c20S27106M518x529S14c20481x471S27106503x489",
        "zoom": 1
      },
      {
        "x": 57,
        "y": 118,
        "minX": 482,
        "minY": 468,
        "width": 36,
        "height": 65,
        "lane": 0,
        "padding": 0,
        "segment": "sign",
        "text": "AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468",
        "zoom": 1
      },
      {
        "x": 39,
        "y": 203,
        "minX": 464,
        "minY": 496,
        "width": 72,
        "height": 8,
        "lane": 0,
        "padding": 0,
        "segment": "symbol",
        "text": "S38800464x496",
        "zoom": 1
      }
    ]
  ]
}

fsw.kind

Array of numbers for kinds of symbols: writing, location, and punctuation.

fsw.kind

Type: Array<number>

fsw.category

Array of numbers for categories of symbols: hand, movement, dynamics, head, trunk & limb, location, and punctuation.

fsw.category

Type: Array<number>

fsw.group

Array of numbers for the 30 symbol groups.

fsw.group

Type: Array<number>

fsw.ranges

Object of symbol ranges with starting and ending numbers.

{ all, writing, hand, movement, dynamic, head, hcenter, vcenter, trunk, limb, location, punctuation }

fsw.ranges

Type: object

fsw.isType

Function to test if symbol is of a certain type.

fsw.isType(key: string, type: string): boolean
Parameters
key (string) an FSW symbol key
type (string) the name of a symbol range
Returns
boolean: is symbol of specified type
Example
fsw.isType('S10000', 'hand')

return true

fsw.colors

Array of colors associated with the seven symbol categories.

fsw.colors

Type: Array<string>

fsw.colorize

Function that returns the standardized color for a symbol.

fsw.colorize(key: string): string
Parameters
key (string) an FSW symbol key
Returns
string: name of standardized color for symbol
Example
fsw.colorize('S10000')

return '#0000CC'

fswquery

The fswquery module contains functions for handling the FSW query language. Query Language definition

fswquery

fswquery.re

Object of regular expressions for FSW query strings

fswquery.re

Type: object

Properties
base (string) : FSW symbol base with neither fill or rotation
coord (string) : FSW coordinate of X and Y values separated by 'x'
var (string) : variance string for searching sign box
symbol (string) : FSW symbol key starting with 'S'
range (string) : FSW range starting with 'R'
item (string) : FSW symbol or range query string
list (string) : several FSW symbols and FSW ranges as a logical OR for searching
prefix (string) : a sequential list of FSW symbol keys starting with 'A'
signbox (string) : several groups of FSW lists, each group having a coordinate
full (string) : a query string to search prefix in order and the signbox with variance

fswquery.parse

Function to parse FSW query string to object

fswquery.parse(fswQueryString: string): QueryObject
Parameters
fswQueryString (string) an FSW query string
Returns
QueryObject: elements of a of query string identified by regular expression
Example
fswquery.parse('QAS10000S10500oS20500oR2fft304TS100uuR205t206oS207uu510x510V5-')

return {
  "query": true,
  "prefix": {
    "required": true,
    "parts": [
      "S10000",
      [
        "or",
        "S10500",
        "S20500",
        [
          "2ff",
          "304"
        ]
      ]
    ]
  },
  "signbox": [
    {
      "symbol": "S100uu"
    },
    {
      "or": [
        [
          "205",
          "206"
        ],
        "S207uu"
      ],
      "coord": [
        510,
        510
      ]
    }
  ],
  "variance": 5,
  "style": true
}

fswquery.compose

Function to compose FSW query string from object

fswquery.compose(fswQueryObject: QueryObject): string
Parameters
fswQueryObject (QueryObject) an object of query options
Returns
string: FSW query string
Example
fswquery.compose({
 query: true,
 prefix: {
   required: true,
   parts: [
     'S10000',
     ['100', '204'],
     'S20500'
   ]
 },
 signbox: [
   { symbol: 'S20000' },
   {
     range: ['100', '105'],
     coord: [500, 500]
   }
 ],
 variance: 5,
 style: true
})

return 'QAS10000R100t204S20500TS20000R100t105500x500V5-'

fswquery.fsw2query

Function to convert an FSW sign to a query string

For the flags parameter, use one or more of the following.

  • A: exact symbol in temporal prefix
  • a: general symbol in temporal prefix
  • S: exact symbol in spatial signbox
  • s: general symbol in spatial signbox
  • L: spatial signbox symbol at location
fswquery.fsw2query(fswSign: string, flags: string): string
Parameters
fswSign (string) FSW sign
flags (string) flags for query string creation
Returns
string: FSW query string
Example
fswquery.fsw2query('AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475', 'ASL')

return 'QAS10011S10019S2e704S2e748TS2e748483x510S10011501x466S2e704510x500S10019476x475'

fswquery.range

Function to transform a range to a regular expression

fswquery.range(min: (number | string), max: (number | string), hex: boolean?): string
Parameters
min ((number | string)) either a decimal number or hexidecimal string
max ((number | string)) either a decimal number or hexidecimal string
hex (boolean?) if true, the regular expression will match a hexidecimal range
Returns
string: a regular expression that matches a range
Example
fswquery.range(500,750)

return '(([56][0-9][0-9])|(7[0-4][0-9])|(750))'
fswquery.range('100','10e',true)

return '10[0-9a-e]'

fswquery.regex

Function to transform an FSW query string to one or more regular expressions

fswquery.regex(query: string): Array<string>
Parameters
query (string) an FSW query string
Returns
Array<string>: an array of one or more regular expressions
Example
fswquery.regex('QS100uuS20500480x520')

return [
  '(?:A(?:S[123][0-9a-f]{2}[0-5][0-9a-f])+)?[BLMR]([0-9]{3}x[0-9]{3})(S[123][0-9a-f]{2}[0-5][0-9a-f][0-9]{3}x[0-9]{3})*S100[0-5][0-9a-f][0-9]{3}x[0-9]{3}(S[123][0-9a-f]{2}[0-5][0-9a-f][0-9]{3}x[0-9]{3})*',
  '(?:A(?:S[123][0-9a-f]{2}[0-5][0-9a-f])+)?[BLMR]([0-9]{3}x[0-9]{3})(S[123][0-9a-f]{2}[0-5][0-9a-f][0-9]{3}x[0-9]{3})*S20500((4[6-9][0-9])|(500))x((5[0-3][0-9])|(540))(S[123][0-9a-f]{2}[0-5][0-9a-f][0-9]{3}x[0-9]{3})*'
]

fswquery.results

Function that uses a query string to match signs from a string of text.

fswquery.results(query: string, text: string): Array<string>
Parameters
query (string) an FSW query string
text (string) a string of text containing multiple signs
Returns
Array<string>: an array of FSW signs
Example
fswquery.results('QAS10011T','AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475 AS15a21S15a07S21100S2df04S2df14M521x538S15a07494x488S15a21498x489S2df04498x517S2df14497x461S21100479x486 AS1f010S10018S20600M519x524S10018485x494S1f010490x494S20600481x476')

return [
  'AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475'
]

fswquery.lines

Function that uses an FSW query string to match signs from multiple lines of text.

fswquery.lines(query: string, text: string): Array<string>
Parameters
query (string) an FSW query string
text (string) multiple lines of text, each starting with an FSW sign
Returns
Array<string>: an array of lines of text, each starting with an FSW sign
Example
fswquery.lines('QAS10011T',`AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475 line one
AS15a21S15a07S21100S2df04S2df14M521x538S15a07494x488S15a21498x489S2df04498x517S2df14497x461S21100479x486 line two
AS1f010S10018S20600M519x524S10018485x494S1f010490x494S20600481x476 line three`)

return [
  'AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475 line one'
]

swu

The swu module contains functions for handling SignWriting in Unicode (SWU) characters. SWU characters definition

swu

swu.encode

Function to encode SWU characters using the UTF-16 escape format.

swu.encode(swu: string): string
Parameters
swu (string) SWU characters
Returns
string: UTF-16 escape format
Example
swu.encode('ņ€€ðĪ†ðĪ†')

return '\\uD8C0\\uDC01\\uD836\\uDD06\\uD836\\uDD06'

swu.decode

Function to decode UTF-16 escape format to SWU characters.

swu.decode(encoded: string): string
Parameters
encoded (string) UTF-16 escape format
Returns
string: SWU characters
Example
swu.decode('\\uD8C0\\uDC01\\uD836\\uDD06\\uD836\\uDD06')

return 'ņ€€ðĪ†ðĪ†'

swu.pair

Function to decompose an SWU character into UTF-16 surrogate pairs.

swu.pair(swuChar: string): Array<string>
Parameters
swuChar (string) an SWU character
Returns
Array<string>: an array of UTF-16 surrogate pairs
Example
swu.pair('ņ€€')

return ['D8C0', 'DC01']

swu.re

Object of regular expressions for SWU strings in UTF-16

swu.re
Properties
symbol (string) : regular expressions for a symbol
coord (string) : regular expressions for a coordinate
sort (string) : regular expressions for the sorting marker
box (string) : regular expression for a signbox marker
prefix (string) : regular expression for a sorting marker followed by one or more symbols
spatial (string) : regular expression for a symbol followed by a coordinate
signbox (string) : regular expression for a signbox marker, max coordinate and zero or more spatial symbols
sign (string) : regular expression for an optional prefix followed by a signbox
sortable (string) : regular expression for a mandatory prefix followed by a signbox

swu.parse.symbol

Function to parse an swu symbol with optional coordinate and style string

swu.parse.symbol(swuSym: string): SymbolObject
Parameters
swuSym (string) an swu symbol
Returns
SymbolObject: elements of swu symbol
Example
swu.parse.symbol('ņ€€ðĪ†ðĪ†-C')

return {
 'symbol': 'ņ€€',
 'coord': [500, 500],
 'style': '-C'
}

swu.parse.sign

Function to parse an swu sign with style string

swu.parse.sign(swuSign: string): SignObject
Parameters
swuSign (string) an swu sign
Returns
SignObject: elements of swu sign
Example
swu.parse.sign('𝠀ņ€€’ņ€€šņ‹šĨņ‹›Đ𝠃ðĪŸðĪĐņ‹›ĐðĢĩðĪņ€€’ðĪ‡ðĢĪņ‹šĨðĪðĪ†ņ€€šðĢŪðĢ­-C')

return {
 sequence: ['ņ€€’','ņ€€š','ņ‹šĨ','ņ‹›Đ'],
 box: '𝠃',
 max: [525, 535],
 spatials: [
   {
     symbol: 'ņ‹›Đ',
     coord: [483, 510]
   },
   {
     symbol: 'ņ€€’',
     coord: [501, 466]
   },
   {
     symbol: 'ņ‹šĨ',
     coord: [510, 500]
   },
   {
     symbol: 'ņ€€š',
     coord: [476, 475]
   }
 ],
 style: '-C'
}

swu.parse.text

Function to parse an swu text

swu.parse.text(swuText: string): Array<string>
Parameters
swuText (string) an swu text
Returns
Array<string>: swu signs and punctuations
Example
swu.parse.text('𝠀ņēĄņˆĐ§ð ƒðĪ˜ðĪĢņēĄðĢģðĢĐņˆĐ§ðĪ‰ðĢŧ 𝠀ņƒŠĒņƒŠŦņ‹›•ņ†‡Ąð ƒðĪ˜ðĪ§ņƒŠŦðĢŧðĪ•ņƒŠĒðĢīðĢžņ†‡ĄðĪŽðĪ‚ņ‹›•ðĪ†ðĢĶ ņŒðĢĒðĪ‚')

return [
 '𝠀ņēĄņˆĐ§ð ƒðĪ˜ðĪĢņēĄðĢģðĢĐņˆĐ§ðĪ‰ðĢŧ',
 '𝠀ņƒŠĒņƒŠŦņ‹›•ņ†‡Ąð ƒðĪ˜ðĪ§ņƒŠŦðĢŧðĪ•ņƒŠĒðĢīðĢžņ†‡ĄðĪŽðĪ‚ņ‹›•ðĪ†ðĢĶ',
 'ņŒðĢĒðĪ‚'
]

swu.compose.symbol

Function to compose an swu symbol with optional coordinate and style string

swu.compose.symbol(swuSymObject: SymbolObject): string
Parameters
swuSymObject (SymbolObject) an swu symbol object
Returns
string: an swu symbol string
Example
swu.compose.symbol({
 'symbol': 'ņ€€',
 'coord': [500, 500],
 'style': '-C'
})

return 'ņ€€ðĪ†ðĪ†-C'

swu.compose.sign

Function to compose an swu sign with style string

swu.compose.sign(swuSignObject: SignObject): string
Parameters
swuSignObject (SignObject) an swu sign object
Returns
string: an swu sign string
Example
swu.compose.sign({
 sequence: ['ņ€€’','ņ€€š','ņ‹šĨ','ņ‹›Đ'],
 box: '𝠃',
 max: [525, 535],
 spatials: [
   {
     symbol: 'ņ‹›Đ',
     coord: [483, 510]
   },
   {
     symbol: 'ņ€€’',
     coord: [501, 466]
   },
   {
     symbol: 'ņ‹šĨ',
     coord: [510, 500]
   },
   {
     symbol: 'ņ€€š',
     coord: [476, 475]
   }
 ],
 style: '-C'
})

return '𝠀ņ€€’ņ€€šņ‹šĨņ‹›Đ𝠃ðĪŸðĪĐņ‹›ĐðĢĩðĪņ€€’ðĪ‡ðĢĪņ‹šĨðĪðĪ†ņ€€šðĢŪðĢ­-C'

swu.info

Function to gather sizing information about an swu sign or symbol

swu.info(swu: string): SegmentInfo
Parameters
swu (string) an swu sign or symbol
Returns
SegmentInfo: information about the swu string
Example
swu.info('𝠀ņēĄņˆĐ§ð ‚ðĪ˜ðĪĢņēĄðĢģðĢĐņˆĐ§ðĪ‰ðĢŧ-P10Z2')

return {
  minX: 481,
  minY: 471,
  width: 37,
  height: 58,
  lane: -1,
  padding: 10,
  segment: 'sign',
  zoom: 2
}

swu.columnDefaultsMerge

Function to an object of column options with default values

swu.columnDefaultsMerge(options: ColumnOptions): ColumnOptions
Parameters
options (ColumnOptions) object of column options
Returns
ColumnOptions: object of column options merged with column defaults
Example
swu.columnDefaultsMerge({height: 500,width:150})

return {
  "height": 500,
  "width": 150,
  "offset": 50,
  "pad": 20,
  "margin": 5,
  "dynamic": false,
  "punctuation": {
    "spacing": true,
    "pad": 30,
    "pull": true
  },
  "style": {
    "detail": [
      "black",
      "white"
    ],
    "zoom": 1
  }
}

swu.columns

Function to transform an SWU text to an array of columns

swu.columns(swuText: string, options: ColumnOptions): {options: ColumnOptions, widths: Array<number>, columns: ColumnData}
Parameters
swuText (string) SWU text of signs and punctuation
options (ColumnOptions) object of column options
Returns
{options: ColumnOptions, widths: Array<number>, columns: ColumnData}: object of column options, widths array, and column data
Example
swu.columns('𝠀ņēĄņˆĐ§ð ƒðĪ˜ðĪĢņēĄðĢģðĢĐņˆĐ§ðĪ‰ðĢŧ 𝠀ņƒŠĒņƒŠŦņ‹›•ņ†‡Ąð ƒðĪ˜ðĪ§ņƒŠŦðĢŧðĪ•ņƒŠĒðĢīðĢžņ†‡ĄðĪŽðĪ‚ņ‹›•ðĪ†ðĢĶ ņŒðĢĒðĪ‚', {height: 500,width:150})

return {
  "options": {
    "height": 500,
    "width": 150,
    "offset": 50,
    "pad": 20,
    "margin": 5,
    "dynamic": false,
    "punctuation": {
      "spacing": true,
      "pad": 30,
      "pull": true
    },
    "style": {
      "detail": [
        "black",
        "white"
      ],
      "zoom": 1
    }
  },
  "widths": [
    150
  ],
  "columns": [
    [
      {
        "x": 56,
        "y": 20,
        "minX": 481,
        "minY": 471,
        "width": 37,
        "height": 58,
        "lane": 0,
        "padding": 0,
        "segment": "sign",
        "text": "𝠀ņēĄņˆĐ§ð ƒðĪ˜ðĪĢņēĄðĢģðĢĐņˆĐ§ðĪ‰ðĢŧ",
        "zoom": 1
      },
      {
        "x": 57,
        "y": 118,
        "minX": 482,
        "minY": 468,
        "width": 36,
        "height": 65,
        "lane": 0,
        "padding": 0,
        "segment": "sign",
        "text": "𝠀ņƒŠĒņƒŠŦņ‹›•ņ†‡Ąð ƒðĪ˜ðĪ§ņƒŠŦðĢŧðĪ•ņƒŠĒðĢīðĢžņ†‡ĄðĪŽðĪ‚ņ‹›•ðĪ†ðĢĶ",
        "zoom": 1
      },
      {
        "x": 39,
        "y": 203,
        "minX": 464,
        "minY": 496,
        "width": 72,
        "height": 8,
        "lane": 0,
        "padding": 0,
        "segment": "symbol",
        "text": "ņŒðĢĒðĪ‚",
        "zoom": 1
      }
    ]
  ]
}

swu.kind

Array of plane 4 code points for kinds of symbols: writing, location, and punctuation.

swu.kind

Type: array

swu.category

Array of plane 4 code points for categories of symbols: hand, movement, dynamics, head, trunk & limb, location, and punctuation.

swu.category

Type: array

swu.group

Array of plane 4 code points for the 30 symbol groups.

swu.group

Type: array

swu.ranges

Object of symbol ranges with starting and ending code points on plane 4.

{ all, writing, hand, movement, dynamic, head, hcenter, vcenter, trunk, limb, location, punctuation }

swu.ranges

Type: object

swu.isType

Function to test if symbol is of a certain type.

swu.isType(swuSym: string, type: string): boolean
Parameters
swuSym (string) an SWU symbol character
type (string) the name of a symbol range
Returns
boolean: is symbol of specified type
Example
swu.isType('ņ€€', 'hand')

return true

swu.colors

Array of colors associated with the seven symbol categories.

swu.colors

Type: array

swu.colorize

Function that returns the standardized color for a symbol.

swu.colorize(swuSym: string): string
Parameters
swuSym (string) an SWU symbol character
Returns
string: name of standardized color for symbol
Example
swu.colorize('ņ€€')

return '#0000CC'

swuquery

The swuquery module contains functions for handling the SWU query language. Query Language definition

swuquery

swuquery.re

Object of regular expressions for SWU query strings

swuquery.re

Type: object

Properties
base (string) : SWU symbol
coord (string) : SWU coordinate of X and Y number characters
var (string) : variance string for searching sign box
symbol (string) : SWU symbol character with ignore fill and rotation flags
range (string) : SWU range starting with 'R'
item (string) : SWU symbol or range query string
list (string) : several SWU symbols and SWU ranges as a logical OR for searching
prefix (string) : a sequential list of SWU symbol characters starting with SWU 'A' character
signbox (string) : several groups of SWU lists, each group having a coordinate
full (string) : a query string to search prefix in order and the signbox with variance

swuquery.parse

Function to parse SWU query string to object

swuquery.parse(swuQueryString: string): QueryObject
Parameters
swuQueryString (string) an SWU query string
Returns
QueryObject: elements of an SWU query string
Example
swuquery.parse('QAņ€€Rņ€€ņ††‘ņ†‡ĄTņ†€Rņ€€ņ€‡ąðĪ†ðĪ†V5-')

return { 
  query: true,
  prefix: {
    required: true,
    parts: [
      'ņ€€',
      ['ņ€€', 'ņ††‘'],
      'ņ†‡Ą'
    ]
  },
  signbox: [
    { symbol: 'ņ†€' },
    {
      range: ['ņ€€', 'ņ€‡ą'],
      coord: [500, 500]
    }
  ],
  variance: 5,
  style: true 
}

swuquery.compose

Function to compose SWU query string from object

swuquery.compose(swuQueryObject: QueryObject): string
Parameters
swuQueryObject (QueryObject) an object of query options
Returns
string: SWU query string
Example
swuquery.compose({ 
  query: true,
  prefix: {
    required: true,
    parts: [
      'ņ€€',
      ['ņ€€', 'ņ††‘'],
      'ņ†‡Ą'
    ]
  },
  signbox: [
    { symbol: 'ņ†€' },
    {
      range: ['ņ€€', 'ņ€‡ą'],
      coord: [500, 500]
    }
  ],
  variance: 5,
  style: true 
})

return 'QAņ€€Rņ€€ņ††‘ņ†‡ĄTņ†€Rņ€€ņ€‡ąðĪ†ðĪ†V5-'

swuquery.swu2query

Function to convert an SWU sign to a query string

For the flags parameter, use one or more of the following.

  • A: exact symbol in temporal prefix
  • a: general symbol in temporal prefix
  • S: exact symbol in spatial signbox
  • s: general symbol in spatial signbox
  • L: spatial signbox symbol at location
swuquery.swu2query(swuSign: string, flags: string): string
Parameters
swuSign (string) SWU sign
flags (string) flags for query string creation
Returns
string: SWU query string
Example
swuquery.swu2query('𝠀ņ€€’ņ€€šņ‹šĨņ‹›Đ𝠃ðĪŸðĪĐņ‹›ĐðĢĩðĪņ€€’ðĪ‡ðĢĪņ‹šĨðĪðĪ†ņ€€šðĢŪðĢ­', 'ASL')

return 'QAņ€€’ņ€€šņ‹šĨņ‹›ĐTņ‹›ĐðĢĩðĪņ€€’ðĪ‡ðĢĪņ‹šĨðĪðĪ†ņ€€šðĢŪðĢ­'

swuquery.range

Function to transform a range of SWU characters to a regular expression

swuquery.range(min: string, max: string): string
Parameters
min (string) an SWU character
max (string) an SWU character
Returns
string: a regular expression that matches a range of SWU characters
Example
swuquery.range('ņ€€', 'ņ€‡Ą')

return '\uD8C0[\uDC01-\uDDE1]'
swuquery.range('ðĢ”', 'ðĪļ')

return '\uD836[\uDCD4-\uDD38]'

swuquery.symbolRanges

Function to transform an SWU symbol with fill and rotation flags to a regular expression

swuquery.symbolRanges(symbolFR: string): string
Parameters
symbolFR (string) an SWU character with optional flags of 'f' for any fill and 'r' for any rotation
Returns
string: a regular expression that matches one or more ranges of SWU symbols
Example

Match an exact symbol

swuquery.symbolRanges('ņ€€')

return '\uD8C0\uDC01');

Match a symbol with any fill

swuquery.symbolRanges('ņ€€f')

return '(\uD8C0\uDC01|\uD8C0\uDC11|\uD8C0\uDC21|\uD8C0\uDC31|\uD8C0\uDC41|\uD8C0\uDC51)'

Match a symbol with any rotation

swuquery.symbolRanges('ņ€€r')

return '\uD8C0[\uDC01-\uDC10]'

Match a symbol with any fill or rotation

swuquery.symbolRanges('ņ€€fr')

return '\uD8C0[\uDC01-\uDC60]'

swuquery.regex

Function to transform an SWU query string to one or more regular expressions

swuquery.regex(query: string): Array<string>
Parameters
query (string) an SWU query string
Returns
Array<string>: an array of one or more regular expressions
Example
swuquery.regex('QAņ€€’T')

return [
  '(\uD836\uDC00\uD8C0\uDC12((?:(?:\uD8C0[\uDC01-\uDFFF])|(?:[\uD8C1-\uD8FC][\uDC00-\uDFFF])|(?:\uD8FD[\uDC00-\uDC80])))*)\uD836[\uDC01-\uDC04](?:\uD836[\uDC0C-\uDDFF]){2}((?:(?:\uD8C0[\uDC01-\uDFFF])|(?:[\uD8C1-\uD8FC][\uDC00-\uDFFF])|(?:\uD8FD[\uDC00-\uDC80]))(?:\uD836[\uDC0C-\uDDFF]){2})*'
]

swuquery.results

Function that uses a query string to match signs from a string of text.

swuquery.results(query: string, text: string): Array<string>
Parameters
query (string) an SWU query string
text (string) a string of text containing multiple signs
Returns
Array<string>: an array of SWU signs
Example
swuquery.results('QAņ€€’T','𝠀ņ€€’ņ€€šņ‹šĨņ‹›Đ𝠃ðĪŸðĪĐņ‹›ĐðĢĩðĪņ€€’ðĪ‡ðĢĪņ‹šĨðĪðĪ†ņ€€šðĢŪðĢ­ 𝠀ņ‚‡Ēņ‚‡ˆņ†™Ąņ‹ŽĨņ‹Žĩ𝠃ðĪ›ðĪŽņ‚‡ˆðĪ€ðĢšņ‚‡ĒðĪ„ðĢŧņ‹ŽĨðĪ„ðĪ—ņ‹ŽĩðĪƒðĢŸņ†™ĄðĢąðĢļ 𝠀ņ…Ļ‘ņ€€™ņ†‰ð ƒðĪ™ðĪžņ€€™ðĢ·ðĪ€ņ…Ļ‘ðĢžðĪ€ņ†‰ðĢģðĢŪ')

return [
  '𝠀ņ€€’ņ€€šņ‹šĨņ‹›Đ𝠃ðĪŸðĪĐņ‹›ĐðĢĩðĪņ€€’ðĪ‡ðĢĪņ‹šĨðĪðĪ†ņ€€šðĢŪðĢ­'
]

swuquery.lines

Function that uses an SWU query string to match signs from multiple lines of text.

swuquery.lines(query: string, text: string): Array<string>
Parameters
query (string) an SWU query string
text (string) multiple lines of text, each starting with an SWU sign
Returns
Array<string>: an array of lines of text, each starting with an SWU sign
Example
swuquery.lines('QAņ€€’T',`𝠀ņ€€’ņ€€šņ‹šĨņ‹›Đ𝠃ðĪŸðĪĐņ‹›ĐðĢĩðĪņ€€’ðĪ‡ðĢĪņ‹šĨðĪðĪ†ņ€€šðĢŪðĢ­ line one
𝠀ņ‚‡Ēņ‚‡ˆņ†™Ąņ‹ŽĨņ‹Žĩ𝠃ðĪ›ðĪŽņ‚‡ˆðĪ€ðĢšņ‚‡ĒðĪ„ðĢŧņ‹ŽĨðĪ„ðĪ—ņ‹ŽĩðĪƒðĢŸņ†™ĄðĢąðĢļ line two
𝠀ņ…Ļ‘ņ€€™ņ†‰ð ƒðĪ™ðĪžņ€€™ðĢ·ðĪ€ņ…Ļ‘ðĢžðĪ€ņ†‰ðĢģðĢŪ line three`)

return [
  '𝠀ņ€€’ņ€€šņ‹šĨņ‹›Đ𝠃ðĪŸðĪĐņ‹›ĐðĢĩðĪņ€€’ðĪ‡ðĢĪņ‹šĨðĪðĪ†ņ€€šðĢŪðĢ­ line one'
]

style

The style module contains regular expressions and functions for parsing and composing style strings. Style string definition

style

StyleObject

The elements of a style string

StyleObject

Type: object

Properties
colorize (boolean?) : boolean to use standardized colors for symbol groups
padding (number?) : integer value for padding around symbol or sign
background (string?) : css name or hex color for background
detail (Array<string>?) : array for css name or hex color for line and optional fill
zoom (number?) : decimal value for zoom level
detailsym (Array<object>?) : custom colors for individual symbols
  • detailsym.index number

    symbol index in sign box

  • detailsym.detail Array<string>

    array for css name or hex color for line and optional fill

classes (string?) : list of class names separated with spaces used for SVG
id (string?) : id name used for SVG

style.re

Object of regular expressions for style strings

style.re

Type: object

Properties
colorize (string) : regular expression for colorize section
colorhex (string) : regular expression for color hex values with 3 or 6 characters
colorname (string) : regular expression for css color name
padding (string) : regular expression for padding section
zoom (string) : regular expression for zoom section
classbase (string) : regular expression for class name definition
id (string) : regular expression for id definition
colorbase (string) : regular expression for color hex or color name
color (string) : regular expression for single color entry
colors (string) : regular expression for double color entry
background (string) : regular expression for background section
detail (string) : regular expression for color details for line and optional fill
detailsym (string) : regular expression for color details for individual symbols
classes (string) : regular expression for one or more class names
full (string) : full regular expression for style string

style.parse

Function to parse style string to object

style.parse(styleString: string): StyleObject
Parameters
styleString (string) a style string
Returns
StyleObject: elements of style string
Example
style.parse('-CP10G_blue_D_red,Cyan_')

return {
 'colorize': true,
 'padding': 10,
 'background': 'blue',
 'detail': ['red', 'Cyan']
}

style.compose

Function to compose style string from object

style.compose(styleObject: StyleObject): string
Parameters
styleObject (StyleObject) an object of style options
Returns
string: style string
Example
style.compose({
 'colorize': true,
 'padding': 10,
 'background': 'blue',
 'detail': ['red', 'Cyan'],
 'zoom': 1.1,
 'detailsym': [
   {
     'index': 1,
     'detail': ['#ff00ff']
   },
   {
     'index': 2,
     'detail': ['yellow', 'green']
   }
 ],
 'classes': 'primary blinking',
 'id': 'cursor'
})

return '-CP10G_blue_D_red,Cyan_Z1.1-D01_ff00ff_D02_yellow,green_-primary blinking!cursor!'

style.merge

Function to merge style objects

style.merge(style1: StyleObject, style2: StyleObject): StyleObject
Parameters
style1 (StyleObject) a style object
style2 (StyleObject) a style object
Returns
StyleObject: a style object
Example
style.merge({'colorize': true},{zoom:2})

return {
 'colorize': true,
 'zoom': 2
}

style.rgb2hex

Function to convert rgb color to hex or "transparent" if below tolerance

style.rgb2hex(rgb: string, tolerance: number): string
Parameters
rgb (string) an rgb color
tolerance (number = 0) max alpha for full transparency
Returns
string: a hex color or "transparent"
Example
style.rgb2hex("rgb(255,255,255)")
return "ffffff"

style.rgb2hex("rgba(255,255,255,0.5)",0.5)
return "transparent"

style.rgba2hex

Function to merge color with background based on alpha transparency

style.rgba2hex(color: string, background: string): string
Parameters
color (string) an rgba color
background (string) an rgba background color
Returns
string: a hex color or "transparent"
Example
style.rgba2hex("rgba(255,255,255,0.5)","rgb(0,0,0)")

return "7f7f7f"

convert

The convert module contains functions to convert between Formal SignWriitng in ASCII (FSW) and SignWriting in Unicode (SWU) characters, along with other types of data. Characters set definitions

convert

convert.swu2mark

Function to convert an SWU structural marker to FSW equivalent

convert.swu2mark(swuMark: string): string
Parameters
swuMark (string) character for SWU structural marker
Returns
string: FSW structural marker
Example
convert.swu2mark('𝠀')

return 'A'

convert.mark2swu

Function to convert an FSW structural marker to SWU equivalent

convert.mark2swu(fswMark: string): string
Parameters
fswMark (string) character for FSW structural marker
Returns
string: SWU structural marker
Example
convert.mark2swu('A')

return '𝠀'

convert.swu2num

Function to convert an SWU number character to an integer

convert.swu2num(swuNum: string): number
Parameters
swuNum (string) SWU number character
Returns
number: Integer value for number
Example
convert.swu2num('ðĪ†')

return 500

convert.num2swu

Function to convert a number to an SWU number character

convert.num2swu(num: number): string
Parameters
num (number) Integer value for number
Returns
string: SWU number character
Example
convert.num2swu(500)

return 'ðĪ†'

convert.swu2coord

Function to convert two SWU number characters to an array of x,y integers

convert.swu2coord(swuCoord: string): Array<number>
Parameters
swuCoord (string) Two SWU number character
Returns
Array<number>: Array of x,y integers
Example
convert.swu2coord('ðĪ†ðĪ†')

return [500, 500]

convert.coord2swu

Function to convert an array of x,y integers to two SWU number characters

convert.coord2swu(coord: Array<number>): string
Parameters
coord (Array<number>) Array of x,y integers
Returns
string: Two SWU number character
Example
convert.coord2swu([500, 500])

return 'ðĪ†ðĪ†'

convert.fsw2coord

Function to convert an FSW coordinate string to an array of x,y integers

convert.fsw2coord(fswCoord: string): Array<number>
Parameters
fswCoord (string) An FSW coordinate string
Returns
Array<number>: Array of x,y integers
Example
convert.fsw2coord('500x500')

return [500, 500]

convert.coord2fsw

Function to convert an array of x,y integers to an FSW coordinate string

convert.coord2fsw(coord: Array<number>): string
Parameters
coord (Array<number>) Array of x,y integers
Returns
string: An FSW coordinate string
Example
convert.coord2fsw([500, 500])

return '500x500'

convert.swu2code

Function to convert an SWU symbol character to a code point on plane 4

convert.swu2code(swuSym: string): number
Parameters
swuSym (string) SWU symbol character
Returns
number: Code point on plane 4
Example
convert.swu2code('ņ€€')

return 0x40001

convert.code2swu

Function to convert a code point on plane 4 to an SWU symbol character

convert.code2swu(code: number): string
Parameters
code (number) Code point on plane 4
Returns
string: SWU symbol character
Example
convert.code2swu(0x40001)

return 'ņ€€'

convert.swu2id

Function to convert an SWU symbol character to a 16-bit ID

convert.swu2id(swuSym: string): number
Parameters
swuSym (string) SWU symbol character
Returns
number: 16-bit ID
Example
convert.swu2id('ņ€€')

return 1

convert.id2swu

Function to convert a 16-bit ID to an SWU symbol character

convert.id2swu(id: number): string
Parameters
id (number) 16-bit ID
Returns
string: SWU symbol character
Example
convert.id2swu(1)

return 'ņ€€'

convert.key2id

Function to convert an FSW symbol key to a 16-bit ID

convert.key2id(key: string): number
Parameters
key (string) FSW symbol key
Returns
number: 16-bit ID
Example
convert.key2id('S10000')

return 1

convert.id2key

Function to convert a 16-bit ID to an FSW symbol key

convert.id2key(id: number): string
Parameters
id (number) 16-bit ID
Returns
string: FSW symbol key
Example
convert.id2key(1)

return 'S10000'

convert.swu2key

Function to convert an SWU symbol character to an FSW symbol key

convert.swu2key(swuSym: string): string
Parameters
swuSym (string) SWU symbol character
Returns
string: FSW symbol key
Example
convert.swu2key('ņ€€')

return 'S10000'

convert.key2swu

Function to convert an FSW symbol key to an SWU symbol character

convert.key2swu(key: string): string
Parameters
key (string) FSW symbol key
Returns
string: SWU symbol character
Example
convert.key2swu('S10000')

return 'ņ€€'

convert.swu2fsw

Function to convert SWU text to FSW text

convert.swu2fsw(swuText: string): string
Parameters
swuText (string) SWU text
Returns
string: FSW text
Example
convert.swu2fsw('𝠀ņ€€’ņ€€šņ‹šĨņ‹›Đ𝠃ðĪŸðĪĐņ‹›ĐðĢĩðĪņ€€’ðĪ‡ðĢĪņ‹šĨðĪðĪ†ņ€€šðĢŪðĢ­')

return 'AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475'

convert.fsw2swu

Function to convert FSW text to SWU text

convert.fsw2swu(fswText: string): string
Parameters
fswText (string) FSW text
Returns
string: SWU text
Example
convert.fsw2swu('AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475')

return '𝠀ņ€€’ņ€€šņ‹šĨņ‹›Đ𝠃ðĪŸðĪĐņ‹›ĐðĢĩðĪņ€€’ðĪ‡ðĢĪņ‹šĨðĪðĪ†ņ€€šðĢŪðĢ­'

convert.symidArr

An array of symbol IDs in minimized format such as "101011"

convert.symidArr

Type: Array<string>

convert.symidMax

Function to convert base or full symid Min to symid Max

convert.symidMax(symidMin: string): string
Parameters
symidMin (string) Symbol ID minimized
Returns
string: Symbol ID maximized
Example
convert.symidMax('101011')

return '01-01-001-01'
convert.symidMax('101011616')

return '01-01-001-01-06-16'

convert.symidMin

Function to convert base or full symid Max to symid Min

convert.symidMin(symidMax: string): string
Parameters
symidMax (string) Symbol ID maximized
Returns
string: Symbol ID minimized
Example
convert.symidMin('01-01-001-01')

return '101011'
convert.symidMin('01-01-001-01-06-16')

return '101011616'

convert.symid2key

Function to convert base or full symid to key

convert.symid2key(symid: string): string
Parameters
symid (string) Symbol ID
Returns
string: Symbol key
Example
convert.symid2key('01-01-001-01')

return 'S100'
convert.symid2key('01-01-001-01-06-16')

return 'S1005f'

convert.key2symid

Function to convert base or full key to symid

convert.key2symid(key: string): string
Parameters
key (string) Symbol key
Returns
string: Symbol ID
Example
convert.key2symid('S100')

return '01-01-001-01'
convert.key2symid('S1005f')

return '01-01-001-01-06-16'

QueryObject

Object of query elements with regular expression identification.

QueryObject

Type: object

Properties
query (boolean) : required true for query object
prefix (object?) : an object for prefix elements
signbox (Array<(QuerySignboxSymbol | QuerySignboxRange | QuerySignboxOr)>?) : array of objects for symbols, ranges, and list of symbols or ranges, with optional coordinates
variance (number?) : amount that x or y coordinates can vary and find a match, defaults to 20
style (boolean?) : boolean value for including style string in matches

QuerySignboxSymbol

QuerySignboxSymbol

Type: object

Properties
symbol (string) : a symbol
coord (Array<number>?) : an optional coordinate

QuerySignboxRange

QuerySignboxRange

Type: object

Properties
range (Array<string>) : an array of two symbols
coord (Array<number>?) : an optional coordinate

QuerySignboxOr

QuerySignboxOr

Type: object

Properties
or (Array<(string | Array<string>)>) : an array of symbol strings and range arrays
coord (Array<number>?) : an optional coordinate

ColumnOptions

ColumnOptions

Type: object

Properties
height (number?) : the height of the columns
width (number?) : the widths of the columns
offset (number?) : the lane offset for left and right lanes
pad (number?) : amount of padding before and after signs as well as at top, left, and right of columns
margin (number?) : amount of space at bottom of column that is not available
dynamic (boolean?) : enables variable width columns
background (string?) : background color for columns
style (StyleObject?) : an object of style options
punctuation (object?) : an object of punctuation options
  • punctuation.spacing boolean?

    enables special spacing for punctuation with no space above and custom space below

  • punctuation.pad number?

    the amount of spacing after a punctuation if punctuation spacing is enabled

  • punctuation.pull boolean?

    prevents line breaks before punctuation by reducing spacing between signs in a column

ColumnData

ColumnData

Type: Array<ColumnSegment>

ColumnSegment

ColumnSegment

Type: object

Properties
x (number) : the x position in the column
y (number) : the y position in the column
minX (number) : the min x value within the segment
minY (number) : the min y value within the segment
width (number) : the width of the text segment
height (number) : the height of the text segment
lane (number) : Left as -1, Middle as 0, Right as 1
padding (number) : the padding of the text segment affects colored background
segment (string) : "sign" or "symbol"
text (string) : the text of the sign or symbol with optional style string
zoom (number) : the zoom size of the segment

SymbolObject

The elements of a symbol string

SymbolObject

Type: object

Properties
symbol (string?) : symbol identifier
coord (Array<number>?) : x,y coordinate
style (string?) : style string

SignObject

The elements of a sign string

SignObject

Type: object

Properties
sequence (Array<string>?) : array of symbols
box (string?) : signbox marker or lane
max (Array<number>?) : preprocessed x,y coordinate
spatials (Array<{symbol: string, coord: Array<number>}>?) : array of symbols with coordinates
style (string?) : style string

SegmentInfo

SegmentInfo

Type: object

Properties
minX (number) : the min x value within the segment
minY (number) : the min y value within the segment
width (number) : the width of the text segment
height (number) : the height of the text segment
lane (number) : Left as -1, Middle as 0, Right as 1
padding (number) : the padding of the text segment affects colored background
segment (string) : "sign" or "symbol"
zoom (number) : the zoom size of the segment