Permalink
Browse files

Introduce inflect.decapitalize()

  • Loading branch information...
1 parent 8f5eb04 commit 7a9ea6779cd8c0010d214959caf878ca08acaeca @ikr ikr committed Sep 19, 2012
View
@@ -24,6 +24,8 @@ A port of the Rails / ActiveSupport inflector to JavaScript (node.js and browser
inflect.capitalize('user'); // User
+ inflect.decapitalize('User'); // user
+
inflect.titleize('man from the boondocks'); // Man From The Boondocks
inflect.underscore('UsersController'); // users_controller
View
@@ -23,34 +23,34 @@ require._core = {
require.resolve = (function () {
return function (x, cwd) {
if (!cwd) cwd = '/';
-
+
if (require._core[x]) return x;
var path = require.modules.path();
cwd = path.resolve('/', cwd);
var y = cwd || '/';
-
+
if (x.match(/^(?:\.\.?\/|\/)/)) {
var m = loadAsFileSync(path.resolve(y, x))
|| loadAsDirectorySync(path.resolve(y, x));
if (m) return m;
}
-
+
var n = loadNodeModulesSync(x, y);
if (n) return n;
-
+
throw new Error("Cannot find module '" + x + "'");
-
+
function loadAsFileSync (x) {
if (require.modules[x]) {
return x;
}
-
+
for (var i = 0; i < require.extensions.length; i++) {
var ext = require.extensions[i];
if (require.modules[x + ext]) return x + ext;
}
}
-
+
function loadAsDirectorySync (x) {
x = x.replace(/\/+$/, '');
var pkgfile = x + '/package.json';
@@ -70,10 +70,10 @@ require.resolve = (function () {
if (m) return m;
}
}
-
+
return loadAsFileSync(x + '/index');
}
-
+
function loadNodeModulesSync (x, start) {
var dirs = nodeModulesPathsSync(start);
for (var i = 0; i < dirs.length; i++) {
@@ -83,23 +83,23 @@ require.resolve = (function () {
var n = loadAsDirectorySync(dir + '/' + x);
if (n) return n;
}
-
+
var m = loadAsFileSync(x);
if (m) return m;
}
-
+
function nodeModulesPathsSync (start) {
var parts;
if (start === '/') parts = [ '' ];
else parts = path.normalize(start).split('/');
-
+
var dirs = [];
for (var i = parts.length - 1; i >= 0; i--) {
if (parts[i] === 'node_modules') continue;
var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
dirs.push(dir);
}
-
+
return dirs;
}
};
@@ -115,13 +115,13 @@ require.alias = function (from, to) {
res = require.resolve(from, '/');
}
var basedir = path.dirname(res);
-
+
var keys = (Object.keys || function (obj) {
var res = [];
for (var key in obj) res.push(key)
return res;
})(require.modules);
-
+
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (key.slice(0, basedir.length + 1) === basedir + '/') {
@@ -139,7 +139,7 @@ require.define = function (filename, fn) {
? ''
: require.modules.path().dirname(filename)
;
-
+
var require_ = function (file) {
return require(file, dirname)
};
@@ -149,7 +149,7 @@ require.define = function (filename, fn) {
require_.modules = require.modules;
require_.define = require.define;
var module_ = { exports : {} };
-
+
require.modules[filename] = function () {
require.modules[filename]._cached = module_.exports;
fn.call(
@@ -172,7 +172,7 @@ if (!process.nextTick) process.nextTick = (function () {
var canPost = typeof window !== 'undefined'
&& window.postMessage && window.addEventListener
;
-
+
if (canPost) {
window.addEventListener('message', function (ev) {
if (ev.source === window && ev.data === 'browserify-tick') {
@@ -184,7 +184,7 @@ if (!process.nextTick) process.nextTick = (function () {
}
}, true);
}
-
+
return function (fn) {
if (canPost) {
queue.push(fn);
@@ -294,7 +294,7 @@ path = normalizeArray(filter(path.split('/'), function(p) {
if (path && trailingSlash) {
path += '/';
}
-
+
return (isAbsolute ? '/' : '') + path;
};
@@ -379,6 +379,8 @@ require.define("/inflect/index.coffee", function (require, module, exports, __di
exports.capitalize = methods.capitalize;
+ exports.decapitalize = methods.decapitalize;
+
exports.pluralize = methods.pluralize;
exports.singularize = methods.singularize;
@@ -529,7 +531,7 @@ require.define("/inflect/inflections.coffee", function (require, module, exports
require.define("/inflect/methods.coffee", function (require, module, exports, __dirname, __filename) {
(function() {
- var camelize, capitalize, dasherize, humanize, inflections, ordinalize, parameterize, pluralize, singularize, titleize, underscore;
+ var camelize, capitalize, decapitalize, dasherize, humanize, inflections, ordinalize, parameterize, pluralize, singularize, titleize, underscore;
inflections = require('../inflect').inflections;
@@ -570,6 +572,10 @@ require.define("/inflect/methods.coffee", function (require, module, exports, __
return (word[0] || '').toUpperCase() + (word.slice(1) || '').toLowerCase();
};
+ decapitalize = function(word) {
+ return (word[0] || '').toLowerCase() + (word.slice(1) || '');
+ };
+
pluralize = function(word) {
var plural, replacement, result, rule, _i, _len, _ref;
result = word.toString();
@@ -676,6 +682,8 @@ require.define("/inflect/methods.coffee", function (require, module, exports, __
exports.capitalize = capitalize;
+ exports.decapitalize = decapitalize;
+
exports.pluralize = pluralize;
exports.singularize = singularize;
@@ -710,6 +718,9 @@ require.define("/inflect/string_extensions.coffee", function (require, module, e
String.prototype.capitalize = function() {
return inflect.capitalize(this);
};
+ String.prototype.decapitalize = function() {
+ return inflect.decapitalize(this);
+ };
String.prototype.titleize = function() {
return inflect.titleize(this);
};
@@ -836,7 +847,7 @@ require.define("/inflect/default_inflections.coffee", function (require, module,
});
require.define("/index.coffee", function (require, module, exports, __dirname, __filename) {
-
+
module.exports = require("./inflect");
});
Oops, something went wrong.

0 comments on commit 7a9ea67

Please sign in to comment.