You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
913 B

4 years ago
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = canUnquote;
  6. var _unquote = require('./unquote');
  7. var _unquote2 = _interopRequireDefault(_unquote);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /**
  10. * Can unquote attribute detection from mothereff.in
  11. * Copyright Mathias Bynens <https://mathiasbynens.be/>
  12. * https://github.com/mathiasbynens/mothereff.in
  13. */
  14. const escapes = /\\([0-9A-Fa-f]{1,6})[ \t\n\f\r]?/g;
  15. const range = /[\u0000-\u002c\u002e\u002f\u003A-\u0040\u005B-\u005E\u0060\u007B-\u009f]/;
  16. function canUnquote(value) {
  17. value = (0, _unquote2.default)(value);
  18. if (value === '-' || value === '') {
  19. return false;
  20. }
  21. value = value.replace(escapes, 'a').replace(/\\./g, 'a');
  22. return !(range.test(value) || /^(?:-?\d|--)/.test(value));
  23. }
  24. module.exports = exports['default'];