docusaurus/packages/docusaurus-theme-common/src/utils/regexpUtils.ts
Joshua Chen 62223ee556
test: improve test coverage (#6387)
* test: improve test coverage

* fix

* use posixPath
2022-01-18 16:29:40 +08:00

23 lines
561 B
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Utility to convert an optional string into a Regex case insensitive and global
*/
export function isRegexpStringMatch(
regexAsString?: string,
valueToTest?: string,
): boolean {
if (
typeof regexAsString === 'undefined' ||
typeof valueToTest === 'undefined'
) {
return false;
}
return new RegExp(regexAsString, 'gi').test(valueToTest);
}