Comparing version 0.3.6 to 0.3.7
// Default inflections | ||
module.exports = function (inflect) { | ||
inflect.plural(/$/, 's'); | ||
@@ -67,3 +66,14 @@ inflect.plural(/s$/i, 's'); | ||
inflect.uncountable(['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'sushi']); | ||
} | ||
inflect.uncountable([ | ||
'equipment', | ||
'information', | ||
'rice', | ||
'money', | ||
'species', | ||
'series', | ||
'fish', | ||
'sheep', | ||
'jeans', | ||
'sushi', | ||
]); | ||
}; |
@@ -10,3 +10,3 @@ // Requiring modules | ||
return methods | ||
return methods; | ||
}; |
@@ -52,20 +52,38 @@ // A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional | ||
// irregular 'person', 'people' | ||
Inflections.prototype.irregular = function (singular, plural, fullMatchRequired) { | ||
Inflections.prototype.irregular = function (singular, plural, fullMatchRequired) { | ||
this.uncountables = util.array.del(this.uncountables, singular); | ||
this.uncountables = util.array.del(this.uncountables, plural); | ||
var prefix = ""; | ||
var prefix = ''; | ||
if (fullMatchRequired) { | ||
prefix = "^"; | ||
prefix = '^'; | ||
} | ||
if (singular[0].toUpperCase() == plural[0].toUpperCase()) { | ||
this.plural(new RegExp("(" + prefix + singular[0] + ")" + singular.slice(1) + "$", "i"), '$1' + plural.slice(1)); | ||
this.plural(new RegExp("(" + prefix + plural[0] + ")" + plural.slice(1) + "$", "i"), '$1' + plural.slice(1)); | ||
this.singular(new RegExp("(" + prefix + plural[0] + ")" + plural.slice(1) + "$", "i"), '$1' + singular.slice(1)); | ||
this.plural(new RegExp('(' + prefix + singular[0] + ')' + singular.slice(1) + '$', 'i'), '$1' + plural.slice(1)); | ||
this.plural(new RegExp('(' + prefix + plural[0] + ')' + plural.slice(1) + '$', 'i'), '$1' + plural.slice(1)); | ||
this.singular(new RegExp('(' + prefix + plural[0] + ')' + plural.slice(1) + '$', 'i'), '$1' + singular.slice(1)); | ||
} else { | ||
this.plural(new RegExp(prefix + (singular[0].toUpperCase()) + singular.slice(1) + "$"), plural[0].toUpperCase() + plural.slice(1)); | ||
this.plural(new RegExp(prefix + (singular[0].toLowerCase()) + singular.slice(1) + "$"), plural[0].toLowerCase() + plural.slice(1)); | ||
this.plural(new RegExp(prefix + (plural[0].toUpperCase()) + plural.slice(1) + "$"), plural[0].toUpperCase() + plural.slice(1)); | ||
this.plural(new RegExp(prefix + (plural[0].toLowerCase()) + plural.slice(1) + "$"), plural[0].toLowerCase() + plural.slice(1)); | ||
this.singular(new RegExp(prefix + (plural[0].toUpperCase()) + plural.slice(1) + "$"), singular[0].toUpperCase() + singular.slice(1)); | ||
this.singular(new RegExp(prefix + (plural[0].toLowerCase()) + plural.slice(1) + "$"), singular[0].toLowerCase() + singular.slice(1)); | ||
this.plural( | ||
new RegExp(prefix + singular[0].toUpperCase() + singular.slice(1) + '$'), | ||
plural[0].toUpperCase() + plural.slice(1) | ||
); | ||
this.plural( | ||
new RegExp(prefix + singular[0].toLowerCase() + singular.slice(1) + '$'), | ||
plural[0].toLowerCase() + plural.slice(1) | ||
); | ||
this.plural( | ||
new RegExp(prefix + plural[0].toUpperCase() + plural.slice(1) + '$'), | ||
plural[0].toUpperCase() + plural.slice(1) | ||
); | ||
this.plural( | ||
new RegExp(prefix + plural[0].toLowerCase() + plural.slice(1) + '$'), | ||
plural[0].toLowerCase() + plural.slice(1) | ||
); | ||
this.singular( | ||
new RegExp(prefix + plural[0].toUpperCase() + plural.slice(1) + '$'), | ||
singular[0].toUpperCase() + singular.slice(1) | ||
); | ||
this.singular( | ||
new RegExp(prefix + plural[0].toLowerCase() + plural.slice(1) + '$'), | ||
singular[0].toLowerCase() + singular.slice(1) | ||
); | ||
} | ||
@@ -82,3 +100,3 @@ }; | ||
this.humans.unshift([rule, replacement]); | ||
} | ||
}; | ||
@@ -91,3 +109,3 @@ // Add uncountable words that shouldn't be attempted inflected. | ||
this.uncountables = this.uncountables.concat(words); | ||
} | ||
}; | ||
@@ -111,3 +129,3 @@ // Clears the loaded inflections within a given scope (default is _'all'_). | ||
} | ||
} | ||
}; | ||
@@ -114,0 +132,0 @@ // Clears the loaded inflections and initializes them to [default](../inflections.html) |
@@ -13,3 +13,3 @@ // The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without, | ||
// Import [inflections](inflections.html) instance | ||
inflect.inflections = require('./inflections') | ||
inflect.inflections = require('./inflections'); | ||
@@ -35,9 +35,9 @@ // Gives easy access to add inflections to this class | ||
// "SSLError".underscore.camelize // => "SslError" | ||
inflect.camelize = function(lower_case_and_underscored_word, first_letter_in_uppercase) { | ||
inflect.camelize = function (lower_case_and_underscored_word, first_letter_in_uppercase) { | ||
var result; | ||
if (first_letter_in_uppercase == null) first_letter_in_uppercase = true; | ||
result = util.string.gsub(lower_case_and_underscored_word, /\/(.?)/, function($) { | ||
return "." + (util.string.upcase($[1])); | ||
result = util.string.gsub(lower_case_and_underscored_word, /\/(.?)/, function ($) { | ||
return '.' + util.string.upcase($[1]); | ||
}); | ||
result = util.string.gsub(result, /(?:_)(.)/, function($) { | ||
result = util.string.gsub(result, /(?:_)(.)/, function ($) { | ||
return util.string.upcase($[1]); | ||
@@ -66,4 +66,4 @@ }); | ||
self = util.string.gsub(camel_cased_word, /\./, '/'); | ||
self = util.string.gsub(self, /([A-Z]+)([A-Z][a-z])/, "$1_$2"); | ||
self = util.string.gsub(self, /([a-z\d])([A-Z])/, "$1_$2"); | ||
self = util.string.gsub(self, /([A-Z])([A-Z][a-z])/, '$1_$2'); | ||
self = util.string.gsub(self, /([a-z\d])([A-Z])/, '$1_$2'); | ||
self = util.string.gsub(self, /-/, '_'); | ||
@@ -99,3 +99,5 @@ return self.toLowerCase(); | ||
} | ||
return inflect.underscore(inflect.demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id"); | ||
return ( | ||
inflect.underscore(inflect.demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? '_id' : 'id') | ||
); | ||
}; | ||
@@ -116,13 +118,13 @@ | ||
if ((_ref = Math.abs(number) % 100) === 11 || _ref === 12 || _ref === 13) { | ||
return "" + number + "th"; | ||
return '' + number + 'th'; | ||
} else { | ||
switch (Math.abs(number) % 10) { | ||
case 1: | ||
return "" + number + "st"; | ||
return '' + number + 'st'; | ||
case 2: | ||
return "" + number + "nd"; | ||
return '' + number + 'nd'; | ||
case 3: | ||
return "" + number + "rd"; | ||
return '' + number + 'rd'; | ||
default: | ||
return "" + number + "th"; | ||
return '' + number + 'th'; | ||
} | ||
@@ -137,4 +139,4 @@ } | ||
inflect.uncountability = function (word) { | ||
return inflect.inflections.uncountables.some(function(ele, ind, arr) { | ||
return word.match(new RegExp("(\\b|_)" + ele + "$", 'i')) != null; | ||
return inflect.inflections.uncountables.some(function (ele, ind, arr) { | ||
return word.match(new RegExp('(\\b|_)' + ele + '$', 'i')) != null; | ||
}); | ||
@@ -199,4 +201,4 @@ }; | ||
} | ||
result = util.string.gsub(result, /_id$/, ""); | ||
result = util.string.gsub(result, /_/, " "); | ||
result = util.string.gsub(result, /_id$/, ''); | ||
result = util.string.gsub(result, /_/, ' '); | ||
return util.string.capitalize(result, true); | ||
@@ -238,3 +240,3 @@ }; | ||
inflect.classify = function (table_name) { | ||
return inflect.camelize(inflect.singularize(util.string.gsub(table_name, /.*\./, ''))); | ||
} | ||
return inflect.camelize(inflect.singularize(util.string.gsub(table_name, /^.*\./, ''))); | ||
}; |
module.exports = function (obj) { | ||
var addProperty = function (method, func) { | ||
String.prototype.__defineGetter__(method, func); | ||
} | ||
}; | ||
var stringPrototypeBlacklist = [ | ||
'__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor', | ||
'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt', | ||
'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'replace', 'search', 'slice', 'split', 'substring', | ||
'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'gsub' | ||
'__defineGetter__', | ||
'__defineSetter__', | ||
'__lookupGetter__', | ||
'__lookupSetter__', | ||
'charAt', | ||
'constructor', | ||
'hasOwnProperty', | ||
'isPrototypeOf', | ||
'propertyIsEnumerable', | ||
'toLocaleString', | ||
'toString', | ||
'valueOf', | ||
'charCodeAt', | ||
'indexOf', | ||
'lastIndexof', | ||
'length', | ||
'localeCompare', | ||
'match', | ||
'replace', | ||
'search', | ||
'slice', | ||
'split', | ||
'substring', | ||
'toLocaleLowerCase', | ||
'toLocaleUpperCase', | ||
'toLowerCase', | ||
'toUpperCase', | ||
'trim', | ||
'trimLeft', | ||
'trimRight', | ||
'gsub', | ||
]; | ||
@@ -25,3 +51,2 @@ | ||
}); | ||
} | ||
}; |
// Some utility functions in js | ||
var u = module.exports = { | ||
var u = (module.exports = { | ||
array: { | ||
@@ -14,5 +14,5 @@ // Returns a copy of the array with the value removed once | ||
if (index == 0) { | ||
return arr.slice(1) | ||
return arr.slice(1); | ||
} else { | ||
return arr.slice(0, index).concat(arr.slice(index+1)); | ||
return arr.slice(0, index).concat(arr.slice(index + 1)); | ||
} | ||
@@ -27,3 +27,3 @@ } else { | ||
// [1, 2, 3].first() #=> 1 | ||
first: function(arr) { | ||
first: function (arr) { | ||
return arr[0]; | ||
@@ -35,5 +35,5 @@ }, | ||
// [1, 2, 3].last() #=> 3 | ||
last: function(arr) { | ||
return arr[arr.length-1]; | ||
} | ||
last: function (arr) { | ||
return arr[arr.length - 1]; | ||
}, | ||
}, | ||
@@ -58,3 +58,3 @@ string: { | ||
var i, match, matchCmpr, matchCmprPrev, replacementStr, result, self; | ||
if (!((pattern != null) && (replacement != null))) return u.string.value(str); | ||
if (!(pattern != null && replacement != null)) return u.string.value(str); | ||
result = ''; | ||
@@ -79,3 +79,3 @@ self = str; | ||
if (matchCmpr[i]) { | ||
replacementStr = u.string.gsub(replacementStr, new RegExp("\\\$" + i), matchCmpr[i]); | ||
replacementStr = u.string.gsub(replacementStr, new RegExp('\\$' + i), matchCmpr[i]); | ||
} | ||
@@ -99,9 +99,9 @@ } | ||
// "hello".upcase #=> "Hello" | ||
upcase: function(str) { | ||
upcase: function (str) { | ||
var self = u.string.gsub(str, /_([a-z])/, function ($) { | ||
return "_" + $[1].toUpperCase(); | ||
return '_' + $[1].toUpperCase(); | ||
}); | ||
self = u.string.gsub(self, /\/([a-z])/, function ($) { | ||
return "/" + $[1].toUpperCase(); | ||
return '/' + $[1].toUpperCase(); | ||
}); | ||
@@ -124,3 +124,3 @@ | ||
self = u.string.gsub(self, /\s([a-z])/, function ($) { | ||
return " " + $[1].toUpperCase(); | ||
return ' ' + $[1].toUpperCase(); | ||
}); | ||
@@ -135,9 +135,9 @@ } | ||
// "HELLO".downcase #=> "hELLO" | ||
downcase: function(str) { | ||
downcase: function (str) { | ||
var self = u.string.gsub(str, /_([A-Z])/, function ($) { | ||
return "_" + $[1].toLowerCase(); | ||
return '_' + $[1].toLowerCase(); | ||
}); | ||
self = u.string.gsub(self, /\/([A-Z])/, function ($) { | ||
return "/" + $[1].toLowerCase(); | ||
return '/' + $[1].toLowerCase(); | ||
}); | ||
@@ -153,4 +153,4 @@ | ||
return str.substr(0); | ||
} | ||
} | ||
} | ||
}, | ||
}, | ||
}); |
{ | ||
"name": "i", | ||
"version": "0.3.6", | ||
"version": "0.3.7", | ||
"author": "Pavan Kumar Sunkara <pavan.sss1991@gmail.com> (pksunkara.github.com)", | ||
@@ -39,3 +39,3 @@ "description": "custom inflections for nodejs", | ||
"devDependencies": { | ||
"vows": "0.7.0" | ||
"vows": "^0.8.2" | ||
}, | ||
@@ -42,0 +42,0 @@ "engines": { |
@@ -147,3 +147,3 @@ # inflect | ||
inflect.inflections.human(/^(.*)_cnt$/i, '$1_count'); | ||
inflect.inflections.humanize('jargon_cnt'); // === 'Jargon count' | ||
inflect.humanize('jargon_cnt'); // === 'Jargon count' | ||
``` | ||
@@ -150,0 +150,0 @@ |
Sorry, the diff of this file is not supported yet
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
56146
1379