)
*
* Inflection returns an object that contains different inflections
* created from the given `name`
*/
/**
@name string#getInflections
@public
@function
@return {Object} A Object containing multiple different inflects for the given `name`
@description Inflection returns an object that contains different inflections
created from the given `name`
@param {String} name The string to create inflections from
*/
this.getInflections = function (name) {
if (!name) {
return;
}
var self = this
// Use plural version to fix possible mistakes(e,g,. thingie instead of thingy)
, normalizedName = this.snakeize(inflection.pluralize(name))
, nameSingular = inflection.singularize(normalizedName)
, namePlural = inflection.pluralize(normalizedName);
return {
// For filepaths or URLs
filename: {
// neil_peart
singular: nameSingular
// neil_pearts
, plural: namePlural
}
// Constructor names
, constructor: {
// NeilPeart
singular: self.camelize(nameSingular, {initialCap: true})
// NeilPearts
, plural: self.camelize(namePlural, {initialCap: true})
}
, property: {
// neilPeart
singular: self.camelize(nameSingular)
// neilPearts
, plural: self.camelize(namePlural)
}
};
};
/**
@name string#getInflection
@public
@function
@return {Object} A Object containing multiple different inflects for the given `name`
@description Inflection returns an object that contains different inflections
created from the given `name`
@param {String} name The string to create inflections from
*/
this.getInflection = function (name, key, pluralization) {
var infl = this.getInflections(name);
return infl[key][pluralization];
};
// From Math.uuid.js, https://github.com/broofa/node-uuid
// Robert Kieffer (robert@broofa.com), MIT license
this.uuid = function (length, radix) {
var chars = _UUID_CHARS
, uuid = []
, r
, i;
radix = radix || chars.length;
if (length) {
// Compact form
i = -1;
while (++i < length) {
uuid[i] = chars[0 | Math.random()*radix];
}
} else {
// rfc4122, version 4 form
// rfc4122 requires these characters
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
// Fill in random data. At i==19 set the high bits of clock sequence as
// per rfc4122, sec. 4.1.5
i = -1;
while (++i < 36) {
if (!uuid[i]) {
r = 0 | Math.random()*16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
}
return uuid.join('');
};
/**
@name string#stripTags
@public
@function
@return {String} A String with HTML tags removed.
@description Strips HTML tags from a string.
@param {String} The string to strip HTML tags from
@param {String|Array} A String or Array containing allowed tags. e.g. "
"
*/
this.stripTags = function(string, allowed) {
// taken from http://phpjs.org/functions/strip_tags/
var allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); // making sure the allowed arg is a string containing only tags in lowercase ()
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
comments = //gi;
return string.replace(comments, '').replace(tags, function ($0, $1) {
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
});
}
})();
module.exports = string;