(str, options)
| 2 | |
| 3 | /* eslint-disable prefer-rest-params */ |
| 4 | export default function isByteLength(str, options) { |
| 5 | assertString(str); |
| 6 | let min; |
| 7 | let max; |
| 8 | if (typeof (options) === 'object') { |
| 9 | min = options.min || 0; |
| 10 | max = options.max; |
| 11 | } else { // backwards compatibility: isByteLength(str, min [, max]) |
| 12 | min = arguments[1]; |
| 13 | max = arguments[2]; |
| 14 | } |
| 15 | const len = encodeURI(str).split(/%..|./).length - 1; |
| 16 | return len >= min && (typeof max === 'undefined' || len <= max); |
| 17 | } |
no test coverage detected