swc/bundler/tests/.cache/deno/5707df2773cbf05df35503cd5a8cc873455ad561.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

38 lines
764 B
TypeScript

// Loaded from https://deno.land/x/segno@v1.1.0/lib/validations/isByteLength.ts
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
type ByteLengthOptions = {
/**
* @default 0
*/
min?: number;
/**
* @default undefined
*/
max?: number;
};
/**
* @ignore
*/
const defaultByteLengthOptions: ByteLengthOptions = {
min: 0,
};
export const isByteLength = (str: string, options?: ByteLengthOptions) => {
assertString(str);
options = { ...defaultByteLengthOptions, ...options };
let { min, max } = options;
// force min to be 0 if undefined
min = min || 0;
const len = encodeURI(str).split(/%..|./).length - 1;
return len >= min && (typeof max === 'undefined' || len <= max);
};