Comparing version
@@ -0,1 +1,6 @@ | ||
0.2.1 / 2012-03-09 | ||
================== | ||
* Updated README to include Quirks/Credits. | ||
* Added method `decodeHtmlEntities()`. | ||
0.2.0 / 2012-03-02 | ||
@@ -2,0 +7,0 @@ ================== |
@@ -39,2 +39,21 @@ (function() { | ||
S.prototype.decodeHtmlEntities = function(quote_style) { | ||
var entity, hash_map, symbol, tmp_str; | ||
hash_map = {}; | ||
symbol = entity = ""; | ||
tmp_str = this.s; | ||
if (false === (hash_map = get_html_translation_table("HTML_ENTITIES", quote_style))) { | ||
return false; | ||
} | ||
delete hash_map["&"]; | ||
hash_map["&"] = "&"; | ||
console.log(tmp_str); | ||
for (symbol in hash_map) { | ||
entity = hash_map[symbol]; | ||
tmp_str = tmp_str.split(entity).join(symbol); | ||
} | ||
tmp_str = tmp_str.split("'").join("'"); | ||
return new S(tmp_str); | ||
}; | ||
S.prototype.endsWith = function(suffix) { | ||
@@ -189,2 +208,148 @@ var l; | ||
function get_html_translation_table (table, quote_style) { | ||
var entities = {}, | ||
hash_map = {}, | ||
decimal; | ||
var constMappingTable = {}, | ||
constMappingQuoteStyle = {}; | ||
var useTable = {}, | ||
useQuoteStyle = {}; | ||
// Translate arguments | ||
constMappingTable[0] = 'HTML_SPECIALCHARS'; | ||
constMappingTable[1] = 'HTML_ENTITIES'; | ||
constMappingQuoteStyle[0] = 'ENT_NOQUOTES'; | ||
constMappingQuoteStyle[2] = 'ENT_COMPAT'; | ||
constMappingQuoteStyle[3] = 'ENT_QUOTES'; | ||
useTable = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS'; | ||
useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT'; | ||
if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') { | ||
throw new Error("Table: " + useTable + ' not supported'); | ||
// return false; | ||
} | ||
entities['38'] = '&'; | ||
if (useTable === 'HTML_ENTITIES') { | ||
entities['160'] = ' '; | ||
entities['161'] = '¡'; | ||
entities['162'] = '¢'; | ||
entities['163'] = '£'; | ||
entities['164'] = '¤'; | ||
entities['165'] = '¥'; | ||
entities['166'] = '¦'; | ||
entities['167'] = '§'; | ||
entities['168'] = '¨'; | ||
entities['169'] = '©'; | ||
entities['170'] = 'ª'; | ||
entities['171'] = '«'; | ||
entities['172'] = '¬'; | ||
entities['173'] = '­'; | ||
entities['174'] = '®'; | ||
entities['175'] = '¯'; | ||
entities['176'] = '°'; | ||
entities['177'] = '±'; | ||
entities['178'] = '²'; | ||
entities['179'] = '³'; | ||
entities['180'] = '´'; | ||
entities['181'] = 'µ'; | ||
entities['182'] = '¶'; | ||
entities['183'] = '·'; | ||
entities['184'] = '¸'; | ||
entities['185'] = '¹'; | ||
entities['186'] = 'º'; | ||
entities['187'] = '»'; | ||
entities['188'] = '¼'; | ||
entities['189'] = '½'; | ||
entities['190'] = '¾'; | ||
entities['191'] = '¿'; | ||
entities['192'] = 'À'; | ||
entities['193'] = 'Á'; | ||
entities['194'] = 'Â'; | ||
entities['195'] = 'Ã'; | ||
entities['196'] = 'Ä'; | ||
entities['197'] = 'Å'; | ||
entities['198'] = 'Æ'; | ||
entities['199'] = 'Ç'; | ||
entities['200'] = 'È'; | ||
entities['201'] = 'É'; | ||
entities['202'] = 'Ê'; | ||
entities['203'] = 'Ë'; | ||
entities['204'] = 'Ì'; | ||
entities['205'] = 'Í'; | ||
entities['206'] = 'Î'; | ||
entities['207'] = 'Ï'; | ||
entities['208'] = 'Ð'; | ||
entities['209'] = 'Ñ'; | ||
entities['210'] = 'Ò'; | ||
entities['211'] = 'Ó'; | ||
entities['212'] = 'Ô'; | ||
entities['213'] = 'Õ'; | ||
entities['214'] = 'Ö'; | ||
entities['215'] = '×'; | ||
entities['216'] = 'Ø'; | ||
entities['217'] = 'Ù'; | ||
entities['218'] = 'Ú'; | ||
entities['219'] = 'Û'; | ||
entities['220'] = 'Ü'; | ||
entities['221'] = 'Ý'; | ||
entities['222'] = 'Þ'; | ||
entities['223'] = 'ß'; | ||
entities['224'] = 'à'; | ||
entities['225'] = 'á'; | ||
entities['226'] = 'â'; | ||
entities['227'] = 'ã'; | ||
entities['228'] = 'ä'; | ||
entities['229'] = 'å'; | ||
entities['230'] = 'æ'; | ||
entities['231'] = 'ç'; | ||
entities['232'] = 'è'; | ||
entities['233'] = 'é'; | ||
entities['234'] = 'ê'; | ||
entities['235'] = 'ë'; | ||
entities['236'] = 'ì'; | ||
entities['237'] = 'í'; | ||
entities['238'] = 'î'; | ||
entities['239'] = 'ï'; | ||
entities['240'] = 'ð'; | ||
entities['241'] = 'ñ'; | ||
entities['242'] = 'ò'; | ||
entities['243'] = 'ó'; | ||
entities['244'] = 'ô'; | ||
entities['245'] = 'õ'; | ||
entities['246'] = 'ö'; | ||
entities['247'] = '÷'; | ||
entities['248'] = 'ø'; | ||
entities['249'] = 'ù'; | ||
entities['250'] = 'ú'; | ||
entities['251'] = 'û'; | ||
entities['252'] = 'ü'; | ||
entities['253'] = 'ý'; | ||
entities['254'] = 'þ'; | ||
entities['255'] = 'ÿ'; | ||
} | ||
if (useQuoteStyle !== 'ENT_NOQUOTES') { | ||
entities['34'] = '"'; | ||
} | ||
if (useQuoteStyle === 'ENT_QUOTES') { | ||
entities['39'] = '''; | ||
} | ||
entities['60'] = '<'; | ||
entities['62'] = '>'; | ||
// ascii decimals to real symbols | ||
for (decimal in entities) { | ||
if (entities.hasOwnProperty(decimal)) { | ||
hash_map[String.fromCharCode(decimal)] = entities[decimal]; | ||
} | ||
} | ||
return hash_map; | ||
} | ||
; | ||
}).call(this); |
@@ -1,1 +0,1 @@ | ||
((function(){var a,b,c,d,e;a=function(){function a(a){this.s=a,this.s==null&&(this.s=this)}return a.prototype.camelize=function(){var b;return b=this.trim().s.replace(/(\-|_|\s)+(.)?/g,function(a,b,c){return c?c.toUpperCase():""}),new a(b)},a.prototype.capitalize=function(){return new a(this.s.substr(0,1).toUpperCase()+this.s.substring(1).toLowerCase())},a.prototype.collapseWhitespace=function(){var b;return b=this.s.replace(/[\s\xa0]+/g," ").replace(/^\s+|\s+$/g,""),new a(b)},a.prototype.contains=function(a){return this.s.indexOf(a)>=0},a.prototype.dasherize=function(){var b;return b=this.trim().s.replace(/[_\s]+/g,"-").replace(/([A-Z])/g,"-$1").replace(/-+/g,"-").toLowerCase(),new a(b)},a.prototype.endsWith=function(a){var b;return b=this.s.length-a.length,b>=0&&this.s.indexOf(a,b)===b},a.prototype.isAlpha=function(){return!/[^a-zA-Z]/.test(this.s)},a.prototype.isAlphaNumeric=function(){return!/[^a-zA-Z0-9]/.test(this.s)},a.prototype.isEmpty=function(){return/^[\s\xa0]*$/.test(this.s)},a.prototype.isLower=function(){return!/[^a-z]/.test(this.s)},a.prototype.isNumeric=function(){return!/[^0-9]/.test(this.s)},a.prototype.isUpper=function(){return!/[^A-Z]/.test(this.s)},a.prototype.left=function(b){var c;return b>=2?(c=this.s.substr(0,b),new a(c)):this.right(-b)},a.prototype.ltrim=function(){var b;return b=this.s.replace(/(^\s*)/g,""),new a(b)},a.prototype.replaceAll=function(b,c){var d;return d=this.s.replace(new RegExp(b,"g"),c),new a(d)},a.prototype.right=function(b){var c;return b>=0?(c=this.s.substr(this.s.length-b,b),new a(c)):this.left(-b)},a.prototype.rtrim=function(){var b;return b=this.s.replace(/\s+$/,""),new a(b)},a.prototype.startsWith=function(a){return this.s.lastIndexOf(a,0)===0},a.prototype.times=function(b){return new a((new Array(b+1)).join(this.s))},a.prototype.trim=function(){var b;return typeof String.prototype.trim=="undefined"?b=this.s.replace(/(^\s*|\s*$)/g,""):b=this.s.trim(),new a(b)},a.prototype.toString=function(){return this.s},a.prototype.underscore=function(){var b;return b=this.trim().s.replace(/([a-z\d])([A-Z]+)/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase(),(new a(this.s.charAt(0))).isUpper()&&(b="_"+b),new a(b)},a.prototype.repeat=a.prototype.times,a.prototype.include=a.prototype.contains,a}(),e=function(b){return new a(b)},c=[],b=function(){var b,d,e,f;e=new a,f=[];for(d in e)b=e[d],String.prototype.hasOwnProperty(d)?f.push(void 0):(c.push(d),f.push(String.prototype[d]=function(){return String.prototype.s=this,b.apply(this,arguments)}));return f},d=function(){var a,b,d;for(b=0,d=c.length;b<d;b++)a=c[b],delete String.prototype[a];return c.length=0},typeof window!="undefined"&&window!==null?(window.S=e,window.S.clobberPrototype=b,window.S.restorePrototype=d):(module.exports=e,module.exports.clobberPrototype=b,module.exports.restorePrototype=d)})).call(this); | ||
((function(){function f(a,b){var c={},d={},e,f={},g={},h={},i={};f[0]="HTML_SPECIALCHARS",f[1]="HTML_ENTITIES",g[0]="ENT_NOQUOTES",g[2]="ENT_COMPAT",g[3]="ENT_QUOTES",h=isNaN(a)?a?a.toUpperCase():"HTML_SPECIALCHARS":f[a],i=isNaN(b)?b?b.toUpperCase():"ENT_COMPAT":g[b];if(h!=="HTML_SPECIALCHARS"&&h!=="HTML_ENTITIES")throw new Error("Table: "+h+" not supported");c[38]="&",h==="HTML_ENTITIES"&&(c[160]=" ",c[161]="¡",c[162]="¢",c[163]="£",c[164]="¤",c[165]="¥",c[166]="¦",c[167]="§",c[168]="¨",c[169]="©",c[170]="ª",c[171]="«",c[172]="¬",c[173]="­",c[174]="®",c[175]="¯",c[176]="°",c[177]="±",c[178]="²",c[179]="³",c[180]="´",c[181]="µ",c[182]="¶",c[183]="·",c[184]="¸",c[185]="¹",c[186]="º",c[187]="»",c[188]="¼",c[189]="½",c[190]="¾",c[191]="¿",c[192]="À",c[193]="Á",c[194]="Â",c[195]="Ã",c[196]="Ä",c[197]="Å",c[198]="Æ",c[199]="Ç",c[200]="È",c[201]="É",c[202]="Ê",c[203]="Ë",c[204]="Ì",c[205]="Í",c[206]="Î",c[207]="Ï",c[208]="Ð",c[209]="Ñ",c[210]="Ò",c[211]="Ó",c[212]="Ô",c[213]="Õ",c[214]="Ö",c[215]="×",c[216]="Ø",c[217]="Ù",c[218]="Ú",c[219]="Û",c[220]="Ü",c[221]="Ý",c[222]="Þ",c[223]="ß",c[224]="à",c[225]="á",c[226]="â",c[227]="ã",c[228]="ä",c[229]="å",c[230]="æ",c[231]="ç",c[232]="è",c[233]="é",c[234]="ê",c[235]="ë",c[236]="ì",c[237]="í",c[238]="î",c[239]="ï",c[240]="ð",c[241]="ñ",c[242]="ò",c[243]="ó",c[244]="ô",c[245]="õ",c[246]="ö",c[247]="÷",c[248]="ø",c[249]="ù",c[250]="ú",c[251]="û",c[252]="ü",c[253]="ý",c[254]="þ",c[255]="ÿ"),i!=="ENT_NOQUOTES"&&(c[34]="""),i==="ENT_QUOTES"&&(c[39]="'"),c[60]="<",c[62]=">";for(e in c)c.hasOwnProperty(e)&&(d[String.fromCharCode(e)]=c[e]);return d}var a,b,c,d,e;a=function(){function a(a){this.s=a,this.s==null&&(this.s=this)}return a.prototype.camelize=function(){var b;return b=this.trim().s.replace(/(\-|_|\s)+(.)?/g,function(a,b,c){return c?c.toUpperCase():""}),new a(b)},a.prototype.capitalize=function(){return new a(this.s.substr(0,1).toUpperCase()+this.s.substring(1).toLowerCase())},a.prototype.collapseWhitespace=function(){var b;return b=this.s.replace(/[\s\xa0]+/g," ").replace(/^\s+|\s+$/g,""),new a(b)},a.prototype.contains=function(a){return this.s.indexOf(a)>=0},a.prototype.dasherize=function(){var b;return b=this.trim().s.replace(/[_\s]+/g,"-").replace(/([A-Z])/g,"-$1").replace(/-+/g,"-").toLowerCase(),new a(b)},a.prototype.decodeHtmlEntities=function(b){var c,d,e,g;d={},e=c="",g=this.s;if(!1===(d=f("HTML_ENTITIES",b)))return!1;delete d["&"],d["&"]="&",console.log(g);for(e in d)c=d[e],g=g.split(c).join(e);return g=g.split("'").join("'"),new a(g)},a.prototype.endsWith=function(a){var b;return b=this.s.length-a.length,b>=0&&this.s.indexOf(a,b)===b},a.prototype.isAlpha=function(){return!/[^a-zA-Z]/.test(this.s)},a.prototype.isAlphaNumeric=function(){return!/[^a-zA-Z0-9]/.test(this.s)},a.prototype.isEmpty=function(){return/^[\s\xa0]*$/.test(this.s)},a.prototype.isLower=function(){return!/[^a-z]/.test(this.s)},a.prototype.isNumeric=function(){return!/[^0-9]/.test(this.s)},a.prototype.isUpper=function(){return!/[^A-Z]/.test(this.s)},a.prototype.left=function(b){var c;return b>=2?(c=this.s.substr(0,b),new a(c)):this.right(-b)},a.prototype.ltrim=function(){var b;return b=this.s.replace(/(^\s*)/g,""),new a(b)},a.prototype.replaceAll=function(b,c){var d;return d=this.s.replace(new RegExp(b,"g"),c),new a(d)},a.prototype.right=function(b){var c;return b>=0?(c=this.s.substr(this.s.length-b,b),new a(c)):this.left(-b)},a.prototype.rtrim=function(){var b;return b=this.s.replace(/\s+$/,""),new a(b)},a.prototype.startsWith=function(a){return this.s.lastIndexOf(a,0)===0},a.prototype.times=function(b){return new a((new Array(b+1)).join(this.s))},a.prototype.trim=function(){var b;return typeof String.prototype.trim=="undefined"?b=this.s.replace(/(^\s*|\s*$)/g,""):b=this.s.trim(),new a(b)},a.prototype.toString=function(){return this.s},a.prototype.underscore=function(){var b;return b=this.trim().s.replace(/([a-z\d])([A-Z]+)/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase(),(new a(this.s.charAt(0))).isUpper()&&(b="_"+b),new a(b)},a.prototype.repeat=a.prototype.times,a.prototype.include=a.prototype.contains,a}(),e=function(b){return new a(b)},c=[],b=function(){var b,d,e,f;e=new a,f=[];for(d in e)b=e[d],String.prototype.hasOwnProperty(d)?f.push(void 0):(c.push(d),f.push(String.prototype[d]=function(){return String.prototype.s=this,b.apply(this,arguments)}));return f},d=function(){var a,b,d;for(b=0,d=c.length;b<d;b++)a=c[b],delete String.prototype[a];return c.length=0},typeof window!="undefined"&&window!==null?(window.S=e,window.S.clobberPrototype=b,window.S.restorePrototype=d):(module.exports=e,module.exports.clobberPrototype=b,module.exports.restorePrototype=d)})).call(this); |
{ | ||
"name": "string", | ||
"version": "0.2.0", | ||
"version": "0.2.1-1", | ||
"description": "string contains methods that aren't included in the vanilla JavaScript string.", | ||
@@ -12,3 +12,3 @@ "homepage": [ | ||
}, | ||
"keywords": ["string","strings", "string.js", "S", "s"], | ||
"keywords": ["string","strings", "string.js", "stringjs", "S", "s"], | ||
"author": "JP Richardson <jprichardson@gmail.com>", | ||
@@ -15,0 +15,0 @@ "licenses":[{ |
@@ -20,2 +20,3 @@ [string.js](http://stringjs.com) | ||
* [Sugar.js](http://sugarjs.com) | ||
* [php.js](http://phpjs.org/pages/home) | ||
@@ -173,2 +174,12 @@ Why wasn't I happy with any of them? They are all static methods that don't seem to support chaining in a clean way 'OR' they have an odd dependency. Sugar is the notable exception. | ||
### - decodeHtmlEntities() ### | ||
Decodes HTML entities into their string representation. | ||
```javascript | ||
S('Ken Thompson & Dennis Ritchie').decodeHtmlEntities().s; //'Ken Thompson & Dennis Ritchie' | ||
S('3 < 4').decodeHtmlEntities().s; //'3 < 4' | ||
``` | ||
### - endsWith(ss) ### | ||
@@ -468,2 +479,9 @@ | ||
Quirks | ||
------ | ||
`decodeHtmlEntities()` converts ` ` to **0x0a** (160) and not **0x20** (20). Most browsers consider 0xa to be whitespace characters, Internet Explorer does not despite it being part of the ECMA standard. Google Closure does a good job of normalizing this behavior. This may need to fixed in `string.js` at some point in time. | ||
Testing | ||
@@ -494,3 +512,9 @@ ------- | ||
Credits | ||
------- | ||
I have looked at the code by the creators in the libraries mentioned in **Motivation**. As noted in the source code, I've specifically used code from Google Closure (Google Inc), Underscore String [Esa-Matti Suuronen](http://esa-matti.suuronen.org/), and php.js (http://phpjs.org/authors/index). | ||
License | ||
@@ -501,3 +525,2 @@ ------- | ||
As noted, some of these methods were plucked from Google. | ||
@@ -504,0 +527,0 @@ Copyright (c) 2012 JP Richardson |
@@ -60,6 +60,9 @@ (function() { | ||
}); | ||
describe('- decodeHtmlEntities', function() { | ||
return it('should decode HTML entities into their proper string representation', function() { | ||
return console.log(S('Ken Thompson & Dennis Ritchie').decodeHtmlEntities().s); | ||
}); | ||
}); | ||
describe('- endsWith(suffix)', function() { | ||
return it("should return true if the string ends with the input string", function() { | ||
console.log('SE: ' + S); | ||
console.log('T: ' + T); | ||
T(S("hello jon").endsWith('jon')); | ||
@@ -66,0 +69,0 @@ F(S('ffffaaa').endsWith('jon')); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
57213
35.8%541
40.89%527
4.56%0
-100%