css.escape
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -1,88 +0,103 @@ | ||
/*! https://mths.be/cssescape v1.2.0 by @mathias | MIT license */ | ||
;(function(root) { | ||
/*! https://mths.be/cssescape v1.3.0 by @mathias | MIT license */ | ||
;(function(root, factory) { | ||
// https://github.com/umdjs/umd/blob/master/returnExports.js | ||
if (typeof exports == 'object') { | ||
// For Node.js. | ||
module.exports = factory(root); | ||
} else if (typeof define == 'function' && define.amd) { | ||
// For AMD. Register as an anonymous module. | ||
define(factory.bind(root, root)); | ||
} else { | ||
// For browser globals (not exposing the function separately). | ||
factory(root); | ||
} | ||
}(typeof global != 'undefined' ? global : this, function(root) { | ||
if (!root.CSS) { | ||
root.CSS = {}; | ||
if (root.CSS && root.CSS.escape) { | ||
return root.CSS.escape; | ||
} | ||
var CSS = root.CSS; | ||
// https://drafts.csswg.org/cssom/#serialize-an-identifier | ||
var cssEscape = function(value) { | ||
var string = String(value); | ||
var length = string.length; | ||
var index = -1; | ||
var codeUnit; | ||
var result = ''; | ||
var firstCodeUnit = string.charCodeAt(0); | ||
while (++index < length) { | ||
codeUnit = string.charCodeAt(index); | ||
// Note: there’s no need to special-case astral symbols, surrogate | ||
// pairs, or lone surrogates. | ||
if (!CSS.escape) { | ||
// https://drafts.csswg.org/cssom/#serialize-an-identifier | ||
CSS.escape = function(value) { | ||
var string = String(value); | ||
var length = string.length; | ||
var index = -1; | ||
var codeUnit; | ||
var result = ''; | ||
var firstCodeUnit = string.charCodeAt(0); | ||
while (++index < length) { | ||
codeUnit = string.charCodeAt(index); | ||
// Note: there’s no need to special-case astral symbols, surrogate | ||
// pairs, or lone surrogates. | ||
// If the character is NULL (U+0000), then the REPLACEMENT CHARACTER | ||
// (U+FFFD) escaped as a code point. | ||
if (codeUnit == 0x0000) { | ||
result += '\\fffd '; | ||
continue; | ||
} | ||
// If the character is NULL (U+0000), then the REPLACEMENT CHARACTER | ||
// (U+FFFD) escaped as a code point. | ||
if (codeUnit == 0x0000) { | ||
result += '\\FFFD '; | ||
continue; | ||
} | ||
if ( | ||
// If the character is in the range [\1-\1F] (U+0001 to U+001F) or is | ||
// U+007F, […] | ||
(codeUnit >= 0x0001 && codeUnit <= 0x001F) || codeUnit == 0x007F || | ||
// If the character is the first character and is in the range [0-9] | ||
// (U+0030 to U+0039), […] | ||
(index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) || | ||
// If the character is the second character and is in the range [0-9] | ||
// (U+0030 to U+0039) and the first character is a `-` (U+002D), […] | ||
( | ||
index == 1 && | ||
codeUnit >= 0x0030 && codeUnit <= 0x0039 && | ||
firstCodeUnit == 0x002D | ||
) | ||
) { | ||
// https://drafts.csswg.org/cssom/#escape-a-character-as-code-point | ||
result += '\\' + codeUnit.toString(16) + ' '; | ||
continue; | ||
} | ||
if ( | ||
// If the character is in the range [\1-\1F] (U+0001 to U+001F) or is | ||
// U+007F, […] | ||
(codeUnit >= 0x0001 && codeUnit <= 0x001F) || codeUnit == 0x007F || | ||
// If the character is the first character and is in the range [0-9] | ||
// (U+0030 to U+0039), […] | ||
(index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) || | ||
// If the character is the second character and is in the range [0-9] | ||
// (U+0030 to U+0039) and the first character is a `-` (U+002D), […] | ||
( | ||
index == 1 && | ||
codeUnit >= 0x0030 && codeUnit <= 0x0039 && | ||
firstCodeUnit == 0x002D | ||
) | ||
) { | ||
// https://drafts.csswg.org/cssom/#escape-a-character-as-code-point | ||
result += '\\' + codeUnit.toString(16) + ' '; | ||
continue; | ||
} | ||
if ( | ||
// If the character is the first character and is a `-` (U+002D), and | ||
// there is no second character, […] | ||
index == 0 && | ||
length == 1 && | ||
codeUnit == 0x002D | ||
) { | ||
result += '\\' + string.charAt(index); | ||
continue; | ||
} | ||
if ( | ||
// If the character is the first character and is a `-` (U+002D), and | ||
// there is no second character, […] | ||
index == 0 && | ||
length == 1 && | ||
codeUnit == 0x002D | ||
) { | ||
result += '\\' + string.charAt(index); | ||
continue; | ||
} | ||
// If the character is not handled by one of the above rules and is | ||
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or | ||
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to | ||
// U+005A), or [a-z] (U+0061 to U+007A), […] | ||
if ( | ||
codeUnit >= 0x0080 || | ||
codeUnit == 0x002D || | ||
codeUnit == 0x005F || | ||
codeUnit >= 0x0030 && codeUnit <= 0x0039 || | ||
codeUnit >= 0x0041 && codeUnit <= 0x005A || | ||
codeUnit >= 0x0061 && codeUnit <= 0x007A | ||
) { | ||
// the character itself | ||
result += string.charAt(index); | ||
continue; | ||
} | ||
// If the character is not handled by one of the above rules and is | ||
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or | ||
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to | ||
// U+005A), or [a-z] (U+0061 to U+007A), […] | ||
if ( | ||
codeUnit >= 0x0080 || | ||
codeUnit == 0x002D || | ||
codeUnit == 0x005F || | ||
codeUnit >= 0x0030 && codeUnit <= 0x0039 || | ||
codeUnit >= 0x0041 && codeUnit <= 0x005A || | ||
codeUnit >= 0x0061 && codeUnit <= 0x007A | ||
) { | ||
// the character itself | ||
result += string.charAt(index); | ||
continue; | ||
} | ||
// Otherwise, the escaped character. | ||
// https://drafts.csswg.org/cssom/#escape-a-character | ||
result += '\\' + string.charAt(index); | ||
// Otherwise, the escaped character. | ||
// https://drafts.csswg.org/cssom/#escape-a-character | ||
result += '\\' + string.charAt(index); | ||
} | ||
return result; | ||
}; | ||
} | ||
return result; | ||
}; | ||
if (!root.CSS) { | ||
root.CSS = {}; | ||
} | ||
}(typeof global != 'undefined' ? global : this)); | ||
root.CSS.escape = cssEscape; | ||
return cssEscape; | ||
})); |
{ | ||
"name": "css.escape", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A robust polyfill for the `CSS.escape` utility method as defined in CSSOM.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://mths.be/cssescape", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6410
92