UNPKG

660 BJavaScriptView Raw
1'use strict';
2/**
3 * Can unquote attribute detection from mothereff.in
4 * Copyright Mathias Bynens <https://mathiasbynens.be/>
5 * https://github.com/mathiasbynens/mothereff.in
6 */
7const escapes = /\\([0-9A-Fa-f]{1,6})[ \t\n\f\r]?/g;
8const range =
9 // eslint-disable-next-line no-control-regex
10 /[\u0000-\u002c\u002e\u002f\u003A-\u0040\u005B-\u005E\u0060\u007B-\u009f]/;
11
12/**
13 * @param {string} value
14 * @return {boolean}
15 */
16module.exports = function canUnquote(value) {
17 if (value === '-' || value === '') {
18 return false;
19 }
20
21 value = value.replace(escapes, 'a').replace(/\\./g, 'a');
22
23 return !(range.test(value) || /^(?:-?\d|--)/.test(value));
24};