Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slang

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slang - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

.npmignore

2

package.json
{
"name": "slang",
"description": "A collection of utility functions for strings",
"version": "0.2.0",
"version": "0.3.0",
"author": {

@@ -6,0 +6,0 @@ "name": "Devon Govett",

@@ -10,3 +10,3 @@ Slang

The annotated source code for slang, generated by [Docco](http://jashkenas.github.com/docco/),
can be found [here](http://devongovett.github.com/slang/).
can be found [here](http://devongovett.github.com/slang/docs/slang.html).

@@ -62,2 +62,5 @@ ## API

### slang.uncamelize
slang.uncamelize('helloWorld'); // "hello World"
### slang.dasherize

@@ -64,0 +67,0 @@ Converts a string of words or a camelCased string into a series of words separated by a dash (`-`)

@@ -17,3 +17,3 @@ (function() {

// Set the slang version
slang.version = '0.2.0';
slang.version = '0.3.0';

@@ -78,2 +78,8 @@ // String utility functions

// Converts a camelCased string into a series of words separated
// by `separator` or a space by default
slang.uncamelize = function uncamelize(input, separator) {
return input.replace(/([a-z\d])([A-Z])/g, '$1' + (separator || ' ') + '$2');
}
// Converts a string of words or a camelCased string into a series of words

@@ -80,0 +86,0 @@ // separated by a dash (`-`)

@@ -1,1 +0,1 @@

(function(){function b(){this.plural=[],this.singular=[],this.uncountable=[],this.irregular={plural:{},singular:{}}}var a={};typeof module!="undefined"&&module.exports?module.exports=a:this.slang=a,a.version="0.2.0",a.isString=function(a){return Object.prototype.toString.call(a)==="[object String]"},a.capitalize=function(a){return a.charAt(0).toUpperCase()+a.slice(1)},a.uncapitalize=function(a){return a.charAt(0).toLowerCase()+a.slice(1)},a.capitalizeWords=function(b){return b.replace(/\w+/g,function(b){return a.capitalize(b)})},a.uncapitalizeWords=function(b){return b.replace(/\w+/g,function(b){return a.uncapitalize(b)})},a.isUpperCaseAt=function(a,b){return a.charAt(b).toUpperCase()===a.charAt(b)},a.isLowerCaseAt=function(a,b){return a.charAt(b).toLowerCase()===a.charAt(b)},a.swapcase=function(a){return a.replace(/([a-z]+)|([A-Z]+)/g,function(a,b,c){return b?a.toUpperCase():a.toLowerCase()})},a.camelize=function(a){return a.replace(/\W+(.)/g,function(a,b){return b.toUpperCase()})},a.dasherize=function(a){return a.replace(/\W+/g,"-").replace(/([a-z\d])([A-Z])/g,"$1-$2").toLowerCase()},a.repeat=function(a,b){return b<1?"":(new Array(b+1)).join(a)},a.insert=function(a,b,c){return a.slice(0,c)+b+a.slice(c)},a.remove=function(a,b,c){return a.slice(0,b)+a.slice(c)},a.chop=function(a){return a.slice(0,-1)},a.trim=function(a){return a.trim?a.trim():a.replace(/^\s+/,"").replace(/\s+$/,"")},a.trimLeft=function(a){return a.trimLeft?a.trimLeft():a.replace(/^\s+/,"")},a.trimRight=function(a){return a.trimRight?a.trimRight():a.replace(/\s+$/,"")},a.truncate=function(a,b){var c=b&&b.limit||10,d=b&&b.omission||"...";return a.length<=c?a:a.slice(0,c)+d},a.join=function(a,b){var c=a.pop(),b=b||"and";return a.join(", ")+" "+b+" "+c},a.humanize=function(a){if(a%100>=11&&a%100<=13)return a+"th";switch(a%10){case 1:return a+"st";case 2:return a+"nd";case 3:return a+"rd"}return a+"th"},a.contains=function(a,b){return a.indexOf(b)>-1},a.startsWith=function(a,b){return a.indexOf(b)===0},a.endsWith=function(a,b){var c=a.length-b.length;return c>=0&&a.indexOf(b,c)>-1},a.isBlank=function(a){return/^\s*$/.test(a)},a.successor=function(a){var b="abcdefghijklmnopqrstuvwxyz",c=b.length,d=a,e=a.length;while(e>=0){var f=a.charAt(--e),g="",h=!1;if(isNaN(f)){index=b.indexOf(f.toLowerCase());if(index===-1)g=f,h=!0;else{var i=f===f.toUpperCase();g=b.charAt((index+1)%c),i&&(g=g.toUpperCase()),h=index+1>=c;if(h&&e===0){var j=i?"A":"a";d=j+g+d.slice(1);break}}}else{g=+f+1,g>9&&(g=0,h=!0);if(h&&e===0){d="1"+g+d.slice(1);break}}d=d.slice(0,e)+g+d.slice(e+1);if(!h)break}return d},a.guid=function(a){var b=[],c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",d=c.length,a=a||32;for(var e=0;e<a;e++)b[e]=c.charAt(Math.floor(Math.random()*d));return b.join("")},a.lang="en",a.languages={},a.Language=b,b.prototype.addIrregular=function(a){for(var b=0,c=a.length;b<c;b++){var d=a[b];this.irregular.plural[d[0]]=d[1],this.irregular.singular[d[1]]=d[0]}},b.prototype.inflect=function(a,b){if(~this.uncountable.indexOf(a.toLowerCase()))return a;var c=this.irregular[b][a];if(c)return c;var d=this[b];for(var e=0,f=d.length;e<f;e++){var g=d[e][0];if(g.test(a))return a.replace(g,d[e][1])}return a},a.pluralize=function(b,c){return c||(c=a.lang),c=a.languages[c],c?c.inflect(b,"plural"):b},a.singularize=function(b,c){return c||(c=a.lang),c=a.languages[c],c?c.inflect(b,"singular"):b},a.addToPrototype=function(){for(key in a){if(key==="guid"||key==="lang"||key==="languages"||key==="Language"||key==="humanize"||key==="isString"||key==="version"||key==="addToPrototype")continue;(function(b){String.prototype[b]=function(){var c=Array.prototype.slice.call(arguments);return a[b].apply(a,[this].concat(c))}})(key)}};var c=a.languages.en=new a.Language;c.plural=[[/(todo)$/i,"$1s"],[/(matr|vert|ind)(?:ix|ex)$/i,"$1ices"],[/(octop|vir)us$/i,"$1i"],[/(alias|status)$/i,"$1es"],[/(cris|ax|test)is$/i,"$1es"],[/(s|ss|sh|ch|x|o)$/i,"$1es"],[/y$/i,"ies"],[/(o|e)y$/i,"$1ys"],[/([ti])um$/i,"$1a"],[/sis$/i,"ses"],[/(?:([^f])fe|([lr])f)$/i,"$1$2ves"],[/([^aeiouy]|qu)y$/i,"$1ies"],[/([m|l])ouse$/i,"$1ice"],[/^(ox)$/i,"$1en"],[/(quiz)$/i,"$1zes"],[/$/,"s"]],c.singular=[[/(bu|mis|kis)s$/i,"$1s"],[/([ti])a$/i,"$1um"],[/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i,"$1$2sis"],[/(^analy)ses$/i,"$1sis"],[/([^f])ves$/i,"$1fe"],[/([lr])ves$/i,"$1f"],[/([^aeiouy]|qu)ies$/i,"$1y"],[/ies$/i,"ie"],[/(x|ch|ss|sh)es$/i,"$1"],[/([m|l])ice$/i,"$1ouse"],[/(bus)es$/i,"$1"],[/(shoe)s$/i,"$1"],[/(o)es$/i,"$1"],[/(cris|ax|test)es$/i,"$1is"],[/(octop|vir)i$/i,"$1us"],[/(alias|status)es$/i,"$1"],[/^(ox)en/i,"$1"],[/(vert|ind)ices$/i,"$1ex"],[/(matr)ices$/i,"$1ix"],[/(quiz)zes$/i,"$1"],[/s$/i,""]],c.addIrregular([["i","we"],["person","people"],["man","men"],["child","children"],["move","moves"],["she","they"],["he","they"],["myself","ourselves"],["yourself","ourselves"],["himself","themselves"],["herself","themselves"],["themself","themselves"],["mine","ours"],["hers","theirs"],["his","theirs"],["its","theirs"],["theirs","theirs"],["sex","sexes"],["this","that"]]),c.uncountable=["advice","enegery","excretion","digestion","cooperation","health","justice","jeans","labour","machinery","equipment","information","pollution","sewage","paper","money","species","series","rain","rice","fish","sheep","moose","deer","bison","proceedings","shears","pincers","breeches","hijinks","clippers","chassis","innings","elk","rhinoceros","swine","you","news"]})()
(function(){var slang={};if(typeof module!=="undefined"&&module.exports){module.exports=slang}else{this.slang=slang}slang.version="0.2.0";slang.isString=function isString(input){return Object.prototype.toString.call(input)==="[object String]"};slang.capitalize=function capitalize(input){return input.charAt(0).toUpperCase()+input.slice(1)};slang.uncapitalize=function uncapitalize(input){return input.charAt(0).toLowerCase()+input.slice(1)};slang.capitalizeWords=function capitalizeWords(input){return input.replace(/\w+/g,function(word){return slang.capitalize(word)})};slang.uncapitalizeWords=function uncapitalizeWords(input){return input.replace(/\w+/g,function(word){return slang.uncapitalize(word)})};slang.isUpperCaseAt=function isUpperCaseAt(input,index){return input.charAt(index).toUpperCase()===input.charAt(index)};slang.isLowerCaseAt=function isLowerCaseAt(input,index){return input.charAt(index).toLowerCase()===input.charAt(index)};slang.swapcase=function swapcase(input){return input.replace(/([a-z]+)|([A-Z]+)/g,function(match,lower,upper){return lower?match.toUpperCase():match.toLowerCase()})};slang.camelize=function camelize(input){return input.replace(/\W+(.)/g,function(match,letter){return letter.toUpperCase()})};slang.uncamelize=function uncamelize(input,separator){return input.replace(/([a-z\d])([A-Z])/g,"$1"+(separator||" ")+"$2")};slang.dasherize=function dasherize(input){return input.replace(/\W+/g,"-").replace(/([a-z\d])([A-Z])/g,"$1-$2").toLowerCase()};slang.repeat=function repeat(input,count){return count<1?"":new Array(count+1).join(input)};slang.insert=function insert(input,string,index){return input.slice(0,index)+string+input.slice(index)};slang.remove=function remove(input,start,end){return input.slice(0,start)+input.slice(end)};slang.chop=function chop(input){return input.slice(0,-1)};slang.trim=function strip(input){return input.trim?input.trim():input.replace(/^\s+/,"").replace(/\s+$/,"")};slang.trimLeft=function trimLeft(input){return input.trimLeft?input.trimLeft():input.replace(/^\s+/,"")};slang.trimRight=function trimRight(input){return input.trimRight?input.trimRight():input.replace(/\s+$/,"")};slang.truncate=function truncate(input,args){var limit=args&&args.limit||10,omission=args&&args.omission||"...";return input.length<=limit?input:input.slice(0,limit)+omission};slang.join=function join(array,last){var lastItem=array.pop(),last=last||"and";return array.join(", ")+" "+last+" "+lastItem};slang.humanize=function humanize(number){if(number%100>=11&&number%100<=13)return number+"th";switch(number%10){case 1:return number+"st";case 2:return number+"nd";case 3:return number+"rd"}return number+"th"};slang.contains=function contains(input,string){return input.indexOf(string)>-1};slang.startsWith=function startsWith(input,string){return input.indexOf(string)===0};slang.endsWith=function endsWith(input,string){var index=input.length-string.length;return index>=0&&input.indexOf(string,index)>-1};slang.isBlank=function isBlank(input){return/^\s*$/.test(input)};slang.successor=function successor(input){var alphabet="abcdefghijklmnopqrstuvwxyz",length=alphabet.length,result=input,i=input.length;while(i>=0){var last=input.charAt(--i),next="",carry=false;if(isNaN(last)){index=alphabet.indexOf(last.toLowerCase());if(index===-1){next=last;carry=true}else{var isUpperCase=last===last.toUpperCase();next=alphabet.charAt((index+1)%length);if(isUpperCase){next=next.toUpperCase()}carry=index+1>=length;if(carry&&i===0){var added=isUpperCase?"A":"a";result=added+next+result.slice(1);break}}}else{next=+last+1;if(next>9){next=0;carry=true}if(carry&&i===0){result="1"+next+result.slice(1);break}}result=result.slice(0,i)+next+result.slice(i+1);if(!carry){break}}return result};slang.guid=function guid(length){var buf=[],chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",charlen=chars.length,length=length||32;for(var i=0;i<length;i++){buf[i]=chars.charAt(Math.floor(Math.random()*charlen))}return buf.join("")};slang.lang="en";slang.languages={};function Language(){this.plural=[];this.singular=[];this.uncountable=[];this.irregular={plural:{},singular:{}}}slang.Language=Language;Language.prototype.addIrregular=function(irregular){for(var i=0,len=irregular.length;i<len;i++){var item=irregular[i];this.irregular.plural[item[0]]=item[1];this.irregular.singular[item[1]]=item[0]}};Language.prototype.inflect=function(word,type){if(~this.uncountable.indexOf(word.toLowerCase()))return word;var irregular=this.irregular[type][word];if(irregular)return irregular;var rules=this[type];for(var i=0,len=rules.length;i<len;i++){var regexp=rules[i][0];if(regexp.test(word))return word.replace(regexp,rules[i][1])}return word};slang.pluralize=function(word,lang){lang||(lang=slang.lang);lang=slang.languages[lang];if(!lang)return word;return lang.inflect(word,"plural")};slang.singularize=function(word,lang){lang||(lang=slang.lang);lang=slang.languages[lang];if(!lang)return word;return lang.inflect(word,"singular")};slang.addToPrototype=function addToPrototype(){for(key in slang){if(key==="guid"||key==="lang"||key==="languages"||key==="Language"||key==="humanize"||key==="isString"||key==="version"||key==="addToPrototype"){continue}(function(key){String.prototype[key]=function(){var args=Array.prototype.slice.call(arguments);return slang[key].apply(slang,[this].concat(args))}})(key)}};var en=slang.languages["en"]=new slang.Language;en.plural=[[/(todo)$/i,"$1s"],[/(matr|vert|ind)(?:ix|ex)$/i,"$1ices"],[/(octop|vir)us$/i,"$1i"],[/(alias|status)$/i,"$1es"],[/(cris|ax|test)is$/i,"$1es"],[/(s|ss|sh|ch|x|o)$/i,"$1es"],[/y$/i,"ies"],[/(o|e)y$/i,"$1ys"],[/([ti])um$/i,"$1a"],[/sis$/i,"ses"],[/(?:([^f])fe|([lr])f)$/i,"$1$2ves"],[/([^aeiouy]|qu)y$/i,"$1ies"],[/([m|l])ouse$/i,"$1ice"],[/^(ox)$/i,"$1en"],[/(quiz)$/i,"$1zes"],[/$/,"s"]];en.singular=[[/(bu|mis|kis)s$/i,"$1s"],[/([ti])a$/i,"$1um"],[/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i,"$1$2sis"],[/(^analy)ses$/i,"$1sis"],[/([^f])ves$/i,"$1fe"],[/([lr])ves$/i,"$1f"],[/([^aeiouy]|qu)ies$/i,"$1y"],[/ies$/i,"ie"],[/(x|ch|ss|sh)es$/i,"$1"],[/([m|l])ice$/i,"$1ouse"],[/(bus)es$/i,"$1"],[/(shoe)s$/i,"$1"],[/(o)es$/i,"$1"],[/(cris|ax|test)es$/i,"$1is"],[/(octop|vir)i$/i,"$1us"],[/(alias|status)es$/i,"$1"],[/^(ox)en/i,"$1"],[/(vert|ind)ices$/i,"$1ex"],[/(matr)ices$/i,"$1ix"],[/(quiz)zes$/i,"$1"],[/s$/i,""]];en.addIrregular([["i","we"],["person","people"],["man","men"],["child","children"],["move","moves"],["she","they"],["he","they"],["myself","ourselves"],["yourself","ourselves"],["himself","themselves"],["herself","themselves"],["themself","themselves"],["mine","ours"],["hers","theirs"],["his","theirs"],["its","theirs"],["theirs","theirs"],["sex","sexes"],["this","that"]]);en.uncountable=["advice","enegery","excretion","digestion","cooperation","health","justice","jeans","labour","machinery","equipment","information","pollution","sewage","paper","money","species","series","rain","rice","fish","sheep","moose","deer","bison","proceedings","shears","pincers","breeches","hijinks","clippers","chassis","innings","elk","rhinoceros","swine","you","news"]})();

@@ -35,2 +35,6 @@ var slang = require('./slang'),

// Test **slang.uncamelize**
assert.equal('Camel Case', slang.uncamelize('CamelCase'));
assert.equal('camel Case', slang.uncamelize('camelCase'));
// Test **slang.dasherize**

@@ -37,0 +41,0 @@ assert.equal('this-is-dashed', slang.dasherize('this is dashed'));

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