isLength.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isLength;
  6. var _assertString = _interopRequireDefault(require("./util/assertString"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9. /* eslint-disable prefer-rest-params */
  10. function isLength(str, options) {
  11. (0, _assertString.default)(str);
  12. var min;
  13. var max;
  14. if (_typeof(options) === 'object') {
  15. min = options.min || 0;
  16. max = options.max;
  17. } else {
  18. // backwards compatibility: isLength(str, min [, max])
  19. min = arguments[1] || 0;
  20. max = arguments[2];
  21. }
  22. var surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
  23. var len = str.length - surrogatePairs.length;
  24. return len >= min && (typeof max === 'undefined' || len <= max);
  25. }
  26. module.exports = exports.default;
  27. module.exports.default = exports.default;