entity-convert
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,24 +0,3 @@ | ||
function replacer(mode){ | ||
return function(char){ | ||
var index = char.charCodeAt(0); | ||
if (index > 127){ | ||
return mode === 'css' ? ('\\00' + char.charCodeAt(0).toString(16)) : ('&#' + char.charCodeAt(0) + ';'); | ||
} else { | ||
return char; | ||
} | ||
}; | ||
} | ||
(function (root, factory) { | ||
function replaceBy(mode){ | ||
return function(string){ | ||
var fn = replacer(mode); | ||
string = string.split(''); | ||
for (var i = 0, len = string.length; i < len; i++){ | ||
string[i] = fn(string[i]); | ||
} | ||
return string.join(''); | ||
}; | ||
} | ||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
@@ -33,3 +12,36 @@ define(function(){ | ||
} | ||
}(this, function(){ | ||
function eachChar(str, fn){ | ||
str = str.split(''); | ||
for (var i = 0, len = str.length; i < len; i++){ | ||
str[i] = fn(str[i]); | ||
} | ||
return str.join(''); | ||
} | ||
function replacer(mode){ | ||
function getEnt(code){ | ||
return ( | ||
mode === 'css' ? | ||
['\\00', code.toString(16)] : | ||
['&#', code, ';'] | ||
).join(''); | ||
} | ||
return function(character){ | ||
var index = character.charCodeAt(0); | ||
return (index > 127) ? getEnt(index) : character; | ||
}; | ||
} | ||
function replaceBy(mode){ | ||
return function(string){ | ||
return eachChar(string, replacer(mode)); | ||
}; | ||
} | ||
return { | ||
@@ -39,2 +51,3 @@ css : replaceBy('css') | ||
}; | ||
})); |
{ | ||
"name": "entity-convert", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "convert all special characters in a string to their corresponding HTML and CSS entities", | ||
@@ -8,3 +8,3 @@ "main": "entityconvert.js", | ||
"homepage": "https://github.com/m90/entity-convert", | ||
"issues": "https://github.com/m90/entity-convert/issues", | ||
"bugs": "https://github.com/m90/entity-convert/issues", | ||
"keywords": [ | ||
@@ -11,0 +11,0 @@ "string", |
# entityconvert.js | ||
#### convert special characters in a string to their HTML or CSS charcode entities (useful for build tools et. al.) | ||
The module works as AMD or CommonJS module and exports an Object containing to functions: `.html(str)` and `.css(str)`. In a non-AMD or CommonJS environment `window.entityconvert` will be exported. | ||
The module works as AMD or CommonJS module and exports an Object containing two functions: `.html(str)` and `.css(str)`. In a non-AMD or CommonJS environment `window.entityconvert` will be exported. | ||
@@ -6,0 +6,0 @@ AMD usage like: |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
2389
40