mirror of
https://github.com/grpc/grpc-node.git
synced 2025-12-08 18:23:54 +00:00
grpc-js-core: simplify regular expression usage
This commit moves two regular expressions out of the functions they are used in, and defines them as constants. This commit also switches from match() to test(), as a Boolean result is all that's needed.
This commit is contained in:
parent
d777e9312b
commit
797bcbaffe
@ -1,5 +1,7 @@
|
||||
import * as http2 from 'http2';
|
||||
import {forOwn} from 'lodash';
|
||||
const LEGAL_KEY_REGEX = /^[0-9a-z_.-]+$/;
|
||||
const LEGAL_NON_BINARY_VALUE_REGEX = /^[ -~]*$/;
|
||||
|
||||
export type MetadataValue = string|Buffer;
|
||||
|
||||
@ -24,11 +26,11 @@ function cloneMetadataObject(repr: MetadataObject): MetadataObject {
|
||||
}
|
||||
|
||||
function isLegalKey(key: string): boolean {
|
||||
return !!key.match(/^[0-9a-z_.-]+$/);
|
||||
return LEGAL_KEY_REGEX.test(key);
|
||||
}
|
||||
|
||||
function isLegalNonBinaryValue(value: string): boolean {
|
||||
return !!value.match(/^[ -~]*$/);
|
||||
return LEGAL_NON_BINARY_VALUE_REGEX.test(value);
|
||||
}
|
||||
|
||||
function isBinaryKey(key: string): boolean {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user