Skip to content

Commit

Permalink
Package optimization (oncokb#1139)
Browse files Browse the repository at this point in the history
* Use native unicode regex instead of xregexp

* Do not include moment.js locale

* remove xregexp & remove package lock
  • Loading branch information
zhx828 authored Aug 5, 2024
1 parent 139b3db commit 10e705a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 30,806 deletions.
30,782 changes: 0 additions & 30,782 deletions package-lock.json

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@
"tslib": "1.11.1",
"typeface-open-sans": "^0.0.54",
"uuid": "7.0.3",
"victory": "^31.0.22",
"xregexp": "^4.2.4"
"victory": "^31.0.22"
},
"devDependencies": {
"@babel/core": "7.6.4",
Expand Down
26 changes: 25 additions & 1 deletion src/main/webapp/app/config/constants/regex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { REF_CAPTURE } from 'app/config/constants/regex';
import { REF_CAPTURE, VALID_LATIN_TEXT } from 'app/config/constants/regex';

describe('Regex constants test', () => {
describe('Reference capture regex', () => {
Expand Down Expand Up @@ -47,4 +47,28 @@ describe('Regex constants test', () => {
expect(mixText.split(REF_CAPTURE).length).toEqual(5);
});
});

describe('Valid latin text regex', () => {
test.each([
'test',
'TEST',
'Test',
'Test Test',
'Test à',
'Test Ö',
'Test ö',
'Test ÿ',
"Test !@#$%^&*()_+[]{}|;:',.<>?",
'1234567890',
])('Truthy text: %s', text => {
expect(VALID_LATIN_TEXT.test(text)).toBeTruthy();
});

test.each(['Привет', 'Γειά', '你好', 'Hello 😊', 'Hello Привет'])(
'Falsy text: %s',
text => {
expect(VALID_LATIN_TEXT.test(text)).toBeFalsy();
}
);
});
});
1 change: 1 addition & 0 deletions src/main/webapp/app/config/constants/regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
// (PMID: 11753428, 16007150, 21467160)
// (NCT1234567)
export const REF_CAPTURE = /(\(\s*(?:PMID|NCT|Abstract):?.*?(?:\([^()]*\).*?)*\))/i;
export const VALID_LATIN_TEXT = /^[\p{Script=Latin}\p{M}\p{N}\p{Z}\p{P}\p{Sm}\p{Sc}\p{Sk}]+$/u;
8 changes: 3 additions & 5 deletions src/main/webapp/app/shared/utils/FormValidationUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import * as XRegExp from 'xregexp';
import _ from 'lodash';
import client from '../api/clientInstance';
import { VerifyCompanyNameVM } from '../api/generated/API';
import { notifyError } from './NotificationUtils';
import pluralize from 'pluralize';

export const XREGEXP_VALID_LATIN_TEXT = '^[\\p{Latin}\\p{Common}\\s]+$';
import { VALID_LATIN_TEXT } from 'app/config/constants/regex';

const LATIN_TEXT_PATTER = {
value: XRegExp(XREGEXP_VALID_LATIN_TEXT),
value: VALID_LATIN_TEXT,
errorMessage: 'Sorry, we only support Latin letters for now.',
};

Expand All @@ -24,7 +22,7 @@ export const debouncedCompanyNameValidator = _.debounce(
companyId?: number
) => {
// Don't run the validator if empty string or not latin chars
if (value.trim() === '' || !XRegExp(XREGEXP_VALID_LATIN_TEXT).test(value)) {
if (value.trim() === '' || !LATIN_TEXT_PATTER.value.test(value)) {
cb(false);
return;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/webapp/app/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ declare module '*.png' {
declare module 'availity-reactstrap-validation';
declare module 'react-responsive-tabs';
declare module 'victory';
declare module 'xregexp';
4 changes: 4 additions & 0 deletions webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,9 @@ module.exports = options => ({
base: '/',
inject: 'body',
}),
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
})
],
});
15 changes: 0 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1429,14 +1429,6 @@
"@babel/types" "^7.4.4"
esutils "^2.0.2"

"@babel/runtime-corejs2@^7.2.0":
version "7.7.7"
resolved "https://registry.yarnpkg.com/@babel/runtime-corejs2/-/runtime-corejs2-7.7.7.tgz#44885957b275a5fd70413142eda9cff4662847ac"
integrity sha512-P91T3dFYQL7aj44PxOMIAbo66Ag3NbmXG9fseSYaXxapp3K9XTct5HU9IpTOm2D0AoktKusgqzN5YcSxZXEKBQ==
dependencies:
core-js "^2.6.5"
regenerator-runtime "^0.13.2"

"@babel/runtime-corejs3@^7.8.3":
version "7.11.2"
resolved "https://registry.yarnpkg.com/@babel/runtime-corejs3/-/runtime-corejs3-7.11.2.tgz#02c3029743150188edeb66541195f54600278419"
Expand Down Expand Up @@ -19445,13 +19437,6 @@ xmlhttprequest-ssl@~1.5.4:
resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz#c2876b06168aadc40e57d97e81191ac8f4398b3e"
integrity sha1-wodrBhaKrcQOV9l+gRkayPQ5iz4=

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"

xregexp@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-4.3.0.tgz#7e92e73d9174a99a59743f67a4ce879a04b5ae50"
Expand Down

0 comments on commit 10e705a

Please sign in to comment.