Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@
"wellknown": "^0.5.0",
"whatwg-fetch": "^3.0.0",
"xml2js": "^0.4.22",
"xregexp": "4.2.4",
"yauzl": "^2.10.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { getFont } from './get_font';

describe('getFont', () => {
it(`returns 'noto-cjk' when matching cjk characters`, () => {
const cjkStrings = [
'vi-Hani: 关',
'ko: 全',
'ja: 入',
'zh-Hant-HK: 免',
'zh-Hant: 令',
'zh-Hans: 令',
'random: おあいい 漢字 あい 抵 令',
String.fromCharCode(0x4ee4),
String.fromCodePoint(0x9aa8),
];

for (const cjkString of cjkStrings) {
expect(getFont(cjkString)).toBe('noto-cjk');
}
});

it(`returns 'Roboto' for non Han characters`, () => {
expect(getFont('English text')).toBe('Roboto');
expect(getFont('')).toBe('Roboto');
expect(getFont(undefined!)).toBe('Roboto');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
* 2.0.
*/

// @ts-ignore: no module definition
import xRegExp from 'xregexp';

export function getFont(text: string) {
// Once unicode regex scripts are fully supported we should be able to get rid of the dependency
// on xRegExp library. See https://github.com/tc39/proposal-regexp-unicode-property-escapes
// for more information. We are matching Han characters which is one of the supported unicode scripts
// We are matching Han characters which is one of the supported unicode scripts
// (you can see the full list of supported scripts here: http://www.unicode.org/standard/supported.html).
// This will match Chinese, Japanese, Korean and some other Asian languages.
const isCKJ = xRegExp('\\p{Han}').test(text, 'g');
const isCKJ = /\p{Script=Han}/gu.test(text);
if (isCKJ) {
return 'noto-cjk';
} else {
Expand Down
17 changes: 1 addition & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1882,14 +1882,6 @@
pirates "^4.0.0"
source-map-support "^0.5.16"

"@babel/runtime-corejs2@^7.2.0":
version "7.11.2"
resolved "https://registry.yarnpkg.com/@babel/runtime-corejs2/-/runtime-corejs2-7.11.2.tgz#700a03945ebad0d31ba6690fc8a6bcc9040faa47"
integrity sha512-AC/ciV28adSSpEkBglONBWq4/Lvm6GAZuxIoyVtsnUpZMl0bxLtoChEnYAkP+47KyOCayZanojtflUEUJtR/6Q==
dependencies:
core-js "^2.6.5"
regenerator-runtime "^0.13.4"

"@babel/runtime-corejs3@^7.10.2":
version "7.11.2"
resolved "https://registry.yarnpkg.com/@babel/runtime-corejs3/-/runtime-corejs3-7.11.2.tgz#02c3029743150188edeb66541195f54600278419"
Expand Down Expand Up @@ -11120,7 +11112,7 @@ core-js@^1.0.0:
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
integrity sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=

core-js@^2.4.0, core-js@^2.5.0, core-js@^2.5.3, core-js@^2.6.5, core-js@^2.6.9:
core-js@^2.4.0, core-js@^2.5.0, core-js@^2.5.3, core-js@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.9.tgz#6b4b214620c834152e179323727fc19741b084f2"
integrity sha512-HOpZf6eXmnl7la+cUdMnLvUxKNqLUzJvgIziQ0DiF3JwSImNphIqdGqzj6hIKyX04MmV0poclQ7+wjWvxQyR2A==
Expand Down Expand Up @@ -30800,13 +30792,6 @@ xpath@0.0.27:
resolved "https://registry.yarnpkg.com/xpath/-/xpath-0.0.27.tgz#dd3421fbdcc5646ac32c48531b4d7e9d0c2cfa92"
integrity sha512-fg03WRxtkCV6ohClePNAECYsmpKKTv5L8y/X3Dn1hQrec3POx2jHZ/0P2qQ6HvsrU1BmeqXcof3NGGueG6LxwQ==

xregexp@4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-4.2.4.tgz#02a4aea056d65a42632c02f0233eab8e4d7e57ed"
integrity sha512-sO0bYdYeJAJBcJA8g7MJJX7UrOZIfJPd8U2SC7B2Dd/J24U0aQNoGp33shCaBSWeb0rD5rh6VBUIXOkGal1TZA==
dependencies:
"@babel/runtime-corejs2" "^7.2.0"

"xtend@>=4.0.0 <4.1.0-0", xtend@^4.0.0, xtend@^4.0.1, xtend@^4.0.2, xtend@~4.0.0, xtend@~4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
Expand Down