Socket
Socket
Sign inDemoInstall

string

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1-1

5

CHANGELOG.md

@@ -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);

2

lib/string.min.js

@@ -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]="&amp;",h==="HTML_ENTITIES"&&(c[160]="&nbsp;",c[161]="&iexcl;",c[162]="&cent;",c[163]="&pound;",c[164]="&curren;",c[165]="&yen;",c[166]="&brvbar;",c[167]="&sect;",c[168]="&uml;",c[169]="&copy;",c[170]="&ordf;",c[171]="&laquo;",c[172]="&not;",c[173]="&shy;",c[174]="&reg;",c[175]="&macr;",c[176]="&deg;",c[177]="&plusmn;",c[178]="&sup2;",c[179]="&sup3;",c[180]="&acute;",c[181]="&micro;",c[182]="&para;",c[183]="&middot;",c[184]="&cedil;",c[185]="&sup1;",c[186]="&ordm;",c[187]="&raquo;",c[188]="&frac14;",c[189]="&frac12;",c[190]="&frac34;",c[191]="&iquest;",c[192]="&Agrave;",c[193]="&Aacute;",c[194]="&Acirc;",c[195]="&Atilde;",c[196]="&Auml;",c[197]="&Aring;",c[198]="&AElig;",c[199]="&Ccedil;",c[200]="&Egrave;",c[201]="&Eacute;",c[202]="&Ecirc;",c[203]="&Euml;",c[204]="&Igrave;",c[205]="&Iacute;",c[206]="&Icirc;",c[207]="&Iuml;",c[208]="&ETH;",c[209]="&Ntilde;",c[210]="&Ograve;",c[211]="&Oacute;",c[212]="&Ocirc;",c[213]="&Otilde;",c[214]="&Ouml;",c[215]="&times;",c[216]="&Oslash;",c[217]="&Ugrave;",c[218]="&Uacute;",c[219]="&Ucirc;",c[220]="&Uuml;",c[221]="&Yacute;",c[222]="&THORN;",c[223]="&szlig;",c[224]="&agrave;",c[225]="&aacute;",c[226]="&acirc;",c[227]="&atilde;",c[228]="&auml;",c[229]="&aring;",c[230]="&aelig;",c[231]="&ccedil;",c[232]="&egrave;",c[233]="&eacute;",c[234]="&ecirc;",c[235]="&euml;",c[236]="&igrave;",c[237]="&iacute;",c[238]="&icirc;",c[239]="&iuml;",c[240]="&eth;",c[241]="&ntilde;",c[242]="&ograve;",c[243]="&oacute;",c[244]="&ocirc;",c[245]="&otilde;",c[246]="&ouml;",c[247]="&divide;",c[248]="&oslash;",c[249]="&ugrave;",c[250]="&uacute;",c[251]="&ucirc;",c[252]="&uuml;",c[253]="&yacute;",c[254]="&thorn;",c[255]="&yuml;"),i!=="ENT_NOQUOTES"&&(c[34]="&quot;"),i==="ENT_QUOTES"&&(c[39]="&#39;"),c[60]="&lt;",c[62]="&gt;";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["&"]="&amp;",console.log(g);for(e in d)c=d[e],g=g.split(c).join(e);return g=g.split("&#039;").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 &amp; Dennis Ritchie').decodeHtmlEntities().s; //'Ken Thompson & Dennis Ritchie'
S('3 &lt; 4').decodeHtmlEntities().s; //'3 < 4'
```
### - endsWith(ss) ###

@@ -468,2 +479,9 @@

Quirks
------
`decodeHtmlEntities()` converts `&nbsp;` 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 &amp; 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc