* Composes the character set for the given variant name. * @param {string} name Variant name * @return {array|null} Character set array or null if it not defined
(name)
| 261 | * @return {array|null} Character set array or null if it not defined |
| 262 | */ |
| 263 | getVariantCharacterSet (name) { |
| 264 | // Return cached character set, if available |
| 265 | if (this._variantCharacterSet[name] !== undefined) { |
| 266 | return this._variantCharacterSet[name] |
| 267 | } |
| 268 | |
| 269 | // Find variant spec by name |
| 270 | const spec = variants.find(variant => variant.name === name) |
| 271 | if (spec === undefined) { |
| 272 | return null |
| 273 | } |
| 274 | |
| 275 | // Retrieve character set |
| 276 | let characterSet = (spec.characterSet || []).slice() |
| 277 | |
| 278 | // Extend character set if this variant extends another one |
| 279 | if (spec.extends) { |
| 280 | const parent = this.getVariantCharacterSet(spec.extends) |
| 281 | if (parent !== null) { |
| 282 | characterSet = parent.slice() |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | // Apply overrides |
| 287 | if (spec.overrides) { |
| 288 | for (const i in spec.overrides) { |
| 289 | characterSet[i] = spec.overrides[i] |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | // Map string chars to code points |
| 294 | for (let i = 0; i < characterSet.length; i++) { |
| 295 | const entry = characterSet[i] |
| 296 | if (entry !== 'FS' && entry !== 'LS' && entry !== null) { |
| 297 | characterSet[i] = |
| 298 | typeof entry === 'string' |
| 299 | ? TextEncoder.codePointsFromString(entry)[0] |
| 300 | : entry |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | // Cache variant character set |
| 305 | this._variantCharacterSet[name] = characterSet |
| 306 | return characterSet |
| 307 | } |
| 308 | } |
no test coverage detected