mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 20:22:26 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
22 lines
586 B
TypeScript
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);
|
|
};
|