swc/bundler/tests/.cache/deno/1bb092a8985beb3c101d0c8cebff7023aafe5218.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

22 lines
586 B
TypeScript

// Loaded from https://deno.land/x/segno@v1.1.0/lib/validations/isLength.ts
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
type LengthOptions = {
min?: number;
max?: number;
};
export const isLength = (str: string, options?: LengthOptions) => {
assertString(str);
const min = options?.min || 0;
const max = options?.max;
const surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
const len = str.length - surrogatePairs.length;
return len >= min && (typeof max === 'undefined' || len <= max);
};