isByteLength.js 842 B

12345678910111213141516171819
  1. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  2. import assertString from './util/assertString';
  3. /* eslint-disable prefer-rest-params */
  4. export default function isByteLength(str, options) {
  5. assertString(str);
  6. var min;
  7. var max;
  8. if (_typeof(options) === 'object') {
  9. min = options.min || 0;
  10. max = options.max;
  11. } else {
  12. // backwards compatibility: isByteLength(str, min [, max])
  13. min = arguments[1];
  14. max = arguments[2];
  15. }
  16. var len = encodeURI(str).split(/%..|./).length - 1;
  17. return len >= min && (typeof max === 'undefined' || len <= max);
  18. }