feat(search-algolia): algolia externalUrl regex to navigate with window.href (#5795)

This commit is contained in:
Sergio Moreno 2021-10-29 19:53:47 +02:00 committed by GitHub
parent 8c12983a2a
commit adbc02ea38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 69 additions and 17 deletions

View file

@ -93,3 +93,5 @@ export {
useIsomorphicLayoutEffect,
useDynamicCallback,
} from './utils/reactUtils';
export {isRegexpStringMatch} from './utils/regexpUtils';

View file

@ -0,0 +1,23 @@
/**
* 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 sensitive 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);
}