mirror of https://gitee.com/bigwinds/arangodb
Added the most complicated and non documented pluralizer npm module we ever found in Lucas life
This commit is contained in:
parent
ac6dee8011
commit
13d0ff1169
|
@ -0,0 +1,3 @@
|
|||
node_modules
|
||||
npm-debug.log
|
||||
*.swp
|
|
@ -0,0 +1,9 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- 0.4
|
||||
- 0.6
|
||||
- 0.7
|
||||
notifications:
|
||||
irc: "irc.freenode.net#pksunkara"
|
||||
email:
|
||||
on_success: never
|
|
@ -0,0 +1,18 @@
|
|||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,174 @@
|
|||
# inflect
|
||||
|
||||
customizable inflections for nodejs
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install i
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Require the module before using
|
||||
|
||||
```js
|
||||
var inflect = require('i')();
|
||||
```
|
||||
|
||||
All the below api functions can be called directly on a string
|
||||
|
||||
```js
|
||||
inflect.titleize('messages to store') // === 'Messages To Store'
|
||||
'messages to store'.titleize // === 'Messages To Store'
|
||||
```
|
||||
|
||||
only if `true` is passed while initiating
|
||||
|
||||
```js
|
||||
var inflect = require('i')(true);
|
||||
```
|
||||
|
||||
### Pluralize
|
||||
|
||||
```js
|
||||
inflect.pluralize('person'); // === 'people'
|
||||
inflect.pluralize('octopus'); // === 'octopi'
|
||||
inflect.pluralize('Hat'); // === 'Hats'
|
||||
```
|
||||
|
||||
### Singularize
|
||||
|
||||
```js
|
||||
inflect.singularize('people'); // === 'person'
|
||||
inflect.singularize('octopi'); // === 'octopus'
|
||||
inflect.singularize('Hats'); // === 'Hat'
|
||||
```
|
||||
|
||||
### Camelize
|
||||
|
||||
```js
|
||||
inflect.camelize('message_properties'); // === 'MessageProperties'
|
||||
inflect.camelize('message_properties', false); // === 'messageProperties'
|
||||
```
|
||||
|
||||
### Underscore
|
||||
|
||||
```js
|
||||
inflect.underscore('MessageProperties'); // === 'message_properties'
|
||||
inflect.underscore('messageProperties'); // === 'message_properties'
|
||||
```
|
||||
|
||||
### Humanize
|
||||
|
||||
```js
|
||||
inflect.humanize('message_id'); // === 'Message'
|
||||
```
|
||||
|
||||
### Dasherize
|
||||
|
||||
```js
|
||||
inflect.dasherize('message_properties'); // === 'message-properties'
|
||||
inflect.dasherize('Message Properties'); // === 'Message Properties'
|
||||
```
|
||||
|
||||
### Titleize
|
||||
|
||||
```js
|
||||
inflect.titleize('message_properties'); // === 'Message Properties'
|
||||
inflect.titleize('message properties to keep'); // === 'Message Properties to Keep'
|
||||
```
|
||||
|
||||
### Demodulize
|
||||
|
||||
```js
|
||||
inflect.demodulize('Message.Bus.Properties'); // === 'Properties'
|
||||
```
|
||||
|
||||
### Tableize
|
||||
|
||||
```js
|
||||
inflect.tableize('MessageBusProperty'); // === 'message_bus_properties'
|
||||
```
|
||||
|
||||
### Classify
|
||||
|
||||
```js
|
||||
inflect.classify('message_bus_properties'); // === 'MessageBusProperty'
|
||||
```
|
||||
|
||||
### Foreign key
|
||||
|
||||
```js
|
||||
inflect.foreign_key('MessageBusProperty'); // === 'message_bus_property_id'
|
||||
inflect.foreign_key('MessageBusProperty', false); // === 'message_bus_propertyid'
|
||||
```
|
||||
|
||||
### Ordinalize
|
||||
|
||||
```js
|
||||
inflect.ordinalize( '1' ); // === '1st'
|
||||
```
|
||||
|
||||
## Custom rules for inflection
|
||||
|
||||
### Custom plural
|
||||
|
||||
We can use regexp in any of these custom rules
|
||||
|
||||
```js
|
||||
inflect.inflections.plural('person', 'guys');
|
||||
inflect.pluralize('person'); // === 'guys'
|
||||
inflect.singularize('guys'); // === 'guy'
|
||||
```
|
||||
|
||||
### Custom singular
|
||||
|
||||
```js
|
||||
inflect.inflections.singular('guys', 'person')
|
||||
inflect.singularize('guys'); // === 'person'
|
||||
inflect.pluralize('person'); // === 'people'
|
||||
```
|
||||
|
||||
### Custom irregular
|
||||
|
||||
```js
|
||||
inflect.inflections.irregular('person', 'guys')
|
||||
inflect.pluralize('person'); // === 'guys'
|
||||
inflect.singularize('guys'); // === 'person'
|
||||
```
|
||||
|
||||
### Custom human
|
||||
|
||||
```js
|
||||
inflect.inflections.human(/^(.*)_cnt$/i, '$1_count');
|
||||
inflect.inflections.humanize('jargon_cnt'); // === 'Jargon count'
|
||||
```
|
||||
|
||||
### Custom uncountable
|
||||
|
||||
```js
|
||||
inflect.inflections.uncountable('oil')
|
||||
inflect.pluralize('oil'); // === 'oil'
|
||||
inflect.singularize('oil'); // === 'oil'
|
||||
```
|
||||
|
||||
## Contributors
|
||||
Here is a list of [Contributors](http://github.com/pksunkara/inflect/contributors)
|
||||
|
||||
### TODO
|
||||
|
||||
- More obscure test cases
|
||||
|
||||
__I accept pull requests and guarantee a reply back within a day__
|
||||
|
||||
## License
|
||||
MIT/X11
|
||||
|
||||
## Bug Reports
|
||||
Report [here](http://github.com/pksunkara/inflect/issues). __Guaranteed reply within a day__.
|
||||
|
||||
## Contact
|
||||
Pavan Kumar Sunkara (pavan.sss1991@gmail.com)
|
||||
|
||||
Follow me on [github](https://github.com/users/follow?target=pksunkara), [twitter](http://twitter.com/pksunkara)
|
|
@ -0,0 +1,63 @@
|
|||
// Default inflections
|
||||
module.exports = function (inflect) {
|
||||
|
||||
inflect.plural(/$/, 's');
|
||||
inflect.plural(/s$/i, 's');
|
||||
inflect.plural(/(ax|test)is$/i, '$1es');
|
||||
inflect.plural(/(octop|vir)us$/i, '$1i');
|
||||
inflect.plural(/(octop|vir)i$/i, '$1i');
|
||||
inflect.plural(/(alias|status)$/i, '$1es');
|
||||
inflect.plural(/(bu)s$/i, '$1ses');
|
||||
inflect.plural(/(buffal|tomat)o$/i, '$1oes');
|
||||
inflect.plural(/([ti])um$/i, '$1a');
|
||||
inflect.plural(/([ti])a$/i, '$1a');
|
||||
inflect.plural(/sis$/i, 'ses');
|
||||
inflect.plural(/(?:([^f])fe|([lr])f)$/i, '$1ves');
|
||||
inflect.plural(/(hive)$/i, '$1s');
|
||||
inflect.plural(/([^aeiouy]|qu)y$/i, '$1ies');
|
||||
inflect.plural(/(x|ch|ss|sh)$/i, '$1es');
|
||||
inflect.plural(/(matr|vert|ind)(?:ix|ex)$/i, '$1ices');
|
||||
inflect.plural(/([m|l])ouse$/i, '$1ice');
|
||||
inflect.plural(/([m|l])ice$/i, '$1ice');
|
||||
inflect.plural(/^(ox)$/i, '$1en');
|
||||
inflect.plural(/^(oxen)$/i, '$1');
|
||||
inflect.plural(/(quiz)$/i, '$1zes');
|
||||
|
||||
|
||||
inflect.singular(/s$/i, '');
|
||||
inflect.singular(/(n)ews$/i, '$1ews');
|
||||
inflect.singular(/([ti])a$/i, '$1um');
|
||||
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '$1sis');
|
||||
inflect.singular(/(^analy)ses$/i, '$1sis');
|
||||
inflect.singular(/([^f])ves$/i, '$1fe');
|
||||
inflect.singular(/(hive)s$/i, '$1');
|
||||
inflect.singular(/(tive)s$/i, '$1');
|
||||
inflect.singular(/([lr])ves$/i, '$1f');
|
||||
inflect.singular(/([^aeiouy]|qu)ies$/i, '$1y');
|
||||
inflect.singular(/(s)eries$/i, '$1eries');
|
||||
inflect.singular(/(m)ovies$/i, '$1ovie');
|
||||
inflect.singular(/(x|ch|ss|sh)es$/i, '$1');
|
||||
inflect.singular(/([m|l])ice$/i, '$1ouse');
|
||||
inflect.singular(/(bus)es$/i, '$1');
|
||||
inflect.singular(/(o)es$/i, '$1');
|
||||
inflect.singular(/(shoe)s$/i, '$1');
|
||||
inflect.singular(/(cris|ax|test)es$/i, '$1is');
|
||||
inflect.singular(/(octop|vir)i$/i, '$1us');
|
||||
inflect.singular(/(alias|status)es$/i, '$1');
|
||||
inflect.singular(/^(ox)en/i, '$1');
|
||||
inflect.singular(/(vert|ind)ices$/i, '$1ex');
|
||||
inflect.singular(/(matr)ices$/i, '$1ix');
|
||||
inflect.singular(/(quiz)zes$/i, '$1');
|
||||
inflect.singular(/(database)s$/i, '$1');
|
||||
|
||||
inflect.irregular('child', 'children');
|
||||
inflect.irregular('person', 'people');
|
||||
inflect.irregular('man', 'men');
|
||||
inflect.irregular('child', 'children');
|
||||
inflect.irregular('sex', 'sexes');
|
||||
inflect.irregular('move', 'moves');
|
||||
inflect.irregular('cow', 'kine');
|
||||
inflect.irregular('zombie', 'zombies');
|
||||
|
||||
inflect.uncountable(['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans']);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
// Requiring modules
|
||||
|
||||
module.exports = function (attach) {
|
||||
var methods = require('./methods');
|
||||
|
||||
if (attach) {
|
||||
require('./native')(methods);
|
||||
}
|
||||
|
||||
return methods
|
||||
};
|
|
@ -0,0 +1,116 @@
|
|||
// A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
|
||||
// inflection rules. Examples:
|
||||
//
|
||||
// BulletSupport.Inflector.inflect ($) ->
|
||||
// $.plural /^(ox)$/i, '$1en'
|
||||
// $.singular /^(ox)en/i, '$1'
|
||||
//
|
||||
// $.irregular 'octopus', 'octopi'
|
||||
//
|
||||
// $.uncountable "equipment"
|
||||
//
|
||||
// New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the
|
||||
// pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
|
||||
// already have been loaded.
|
||||
|
||||
var util = require('./util');
|
||||
|
||||
var Inflections = function () {
|
||||
this.plurals = [];
|
||||
this.singulars = [];
|
||||
this.uncountables = [];
|
||||
this.humans = [];
|
||||
require('./defaults')(this);
|
||||
return this;
|
||||
};
|
||||
|
||||
// Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
|
||||
// The replacement should always be a string that may include references to the matched data from the rule.
|
||||
Inflections.prototype.plural = function (rule, replacement) {
|
||||
if (typeof rule == 'string') {
|
||||
this.uncountables = util.array.del(this.uncountables, rule);
|
||||
}
|
||||
this.uncountables = util.array.del(this.uncountables, replacement);
|
||||
this.plurals.unshift([rule, replacement]);
|
||||
};
|
||||
|
||||
// Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
|
||||
// The replacement should always be a string that may include references to the matched data from the rule.
|
||||
Inflections.prototype.singular = function (rule, replacement) {
|
||||
if (typeof rule == 'string') {
|
||||
this.uncountables = util.array.del(this.uncountables, rule);
|
||||
}
|
||||
this.uncountables = util.array.del(this.uncountables, replacement);
|
||||
this.singulars.unshift([rule, replacement]);
|
||||
};
|
||||
|
||||
// Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
|
||||
// for strings, not regular expressions. You simply pass the irregular in singular and plural form.
|
||||
//
|
||||
// irregular 'octopus', 'octopi'
|
||||
// irregular 'person', 'people'
|
||||
Inflections.prototype.irregular = function (singular, plural) {
|
||||
this.uncountables = util.array.del(this.uncountables, singular);
|
||||
this.uncountables = util.array.del(this.uncountables, plural);
|
||||
if (singular[0].toUpperCase() == plural[0].toUpperCase()) {
|
||||
this.plural(new RegExp("(" + singular[0] + ")" + singular.slice(1) + "$", "i"), '$1' + plural.slice(1));
|
||||
this.plural(new RegExp("(" + plural[0] + ")" + plural.slice(1) + "$", "i"), '$1' + plural.slice(1));
|
||||
this.singular(new RegExp("(" + plural[0] + ")" + plural.slice(1) + "$", "i"), '$1' + singular.slice(1));
|
||||
} else {
|
||||
this.plural(new RegExp("" + (singular[0].toUpperCase()) + singular.slice(1) + "$"), plural[0].toUpperCase() + plural.slice(1));
|
||||
this.plural(new RegExp("" + (singular[0].toLowerCase()) + singular.slice(1) + "$"), plural[0].toLowerCase() + plural.slice(1));
|
||||
this.plural(new RegExp("" + (plural[0].toUpperCase()) + plural.slice(1) + "$"), plural[0].toUpperCase() + plural.slice(1));
|
||||
this.plural(new RegExp("" + (plural[0].toLowerCase()) + plural.slice(1) + "$"), plural[0].toLowerCase() + plural.slice(1));
|
||||
this.singular(new RegExp("" + (plural[0].toUpperCase()) + plural.slice(1) + "$"), singular[0].toUpperCase() + singular.slice(1));
|
||||
this.singular(new RegExp("" + (plural[0].toLowerCase()) + plural.slice(1) + "$"), singular[0].toLowerCase() + singular.slice(1));
|
||||
}
|
||||
};
|
||||
|
||||
// Specifies a humanized form of a string by a regular expression rule or by a string mapping.
|
||||
// When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
|
||||
// When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name')
|
||||
//
|
||||
// human /(.*)_cnt$/i, '$1_count'
|
||||
// human "legacy_col_person_name", "Name"
|
||||
Inflections.prototype.human = function (rule, replacement) {
|
||||
this.humans.unshift([rule, replacement]);
|
||||
}
|
||||
|
||||
// Add uncountable words that shouldn't be attempted inflected.
|
||||
//
|
||||
// uncountable "money"
|
||||
// uncountable ["money", "information"]
|
||||
Inflections.prototype.uncountable = function (words) {
|
||||
this.uncountables = this.uncountables.concat(words);
|
||||
}
|
||||
|
||||
// Clears the loaded inflections within a given scope (default is _'all'_).
|
||||
// Give the scope as a symbol of the inflection type, the options are: _'plurals'_,
|
||||
// _'singulars'_, _'uncountables'_, _'humans'_.
|
||||
//
|
||||
// clear 'all'
|
||||
// clear 'plurals'
|
||||
Inflections.prototype.clear = function (scope) {
|
||||
if (scope == null) scope = 'all';
|
||||
switch (scope) {
|
||||
case 'all':
|
||||
this.plurals = [];
|
||||
this.singulars = [];
|
||||
this.uncountables = [];
|
||||
this.humans = [];
|
||||
default:
|
||||
this[scope] = [];
|
||||
}
|
||||
}
|
||||
|
||||
// Clears the loaded inflections and initializes them to [default](../inflections.html)
|
||||
Inflections.prototype.default = function () {
|
||||
this.plurals = [];
|
||||
this.singulars = [];
|
||||
this.uncountables = [];
|
||||
this.humans = [];
|
||||
require('./defaults')(this);
|
||||
return this;
|
||||
};
|
||||
|
||||
module.exports = new Inflections();
|
|
@ -0,0 +1,233 @@
|
|||
// The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
|
||||
// and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept
|
||||
// in inflections.coffee
|
||||
//
|
||||
// If you discover an incorrect inflection and require it for your application, you'll need
|
||||
// to correct it yourself (explained below).
|
||||
|
||||
var util = require('./util');
|
||||
|
||||
var inflect = module.exports;
|
||||
|
||||
// Import [inflections](inflections.html) instance
|
||||
inflect.inflections = require('./inflections')
|
||||
|
||||
// Gives easy access to add inflections to this class
|
||||
inflect.inflect = function (inflections_function) {
|
||||
inflections_function(inflect.inflections);
|
||||
};
|
||||
|
||||
// By default, _camelize_ converts strings to UpperCamelCase. If the argument to _camelize_
|
||||
// is set to _false_ then _camelize_ produces lowerCamelCase.
|
||||
//
|
||||
// _camelize_ will also convert '/' to '.' which is useful for converting paths to namespaces.
|
||||
//
|
||||
// "bullet_record".camelize() // => "BulletRecord"
|
||||
// "bullet_record".camelize(false) // => "bulletRecord"
|
||||
// "bullet_record/errors".camelize() // => "BulletRecord.Errors"
|
||||
// "bullet_record/errors".camelize(false) // => "bulletRecord.Errors"
|
||||
//
|
||||
// As a rule of thumb you can think of _camelize_ as the inverse of _underscore_,
|
||||
// though there are cases where that does not hold:
|
||||
//
|
||||
// "SSLError".underscore.camelize // => "SslError"
|
||||
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(result, /(?:_)(.)/, function($) {
|
||||
return util.string.upcase($[1]);
|
||||
});
|
||||
if (first_letter_in_uppercase) {
|
||||
return util.string.upcase(result);
|
||||
} else {
|
||||
return util.string.downcase(result);
|
||||
}
|
||||
};
|
||||
|
||||
// Makes an underscored, lowercase form from the expression in the string.
|
||||
//
|
||||
// Changes '.' to '/' to convert namespaces to paths.
|
||||
//
|
||||
// "BulletRecord".underscore() // => "bullet_record"
|
||||
// "BulletRecord.Errors".underscore() // => "bullet_record/errors"
|
||||
//
|
||||
// As a rule of thumb you can think of +underscore+ as the inverse of +camelize+,
|
||||
// though there are cases where that does not hold:
|
||||
//
|
||||
// "SSLError".underscore().camelize() // => "SslError"
|
||||
inflect.underscore = function (camel_cased_word) {
|
||||
var self;
|
||||
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, /-/, '_');
|
||||
return self.toLowerCase();
|
||||
};
|
||||
|
||||
// Replaces underscores with dashes in the string.
|
||||
//
|
||||
// "puni_puni".dasherize() // => "puni-puni"
|
||||
inflect.dasherize = function (underscored_word) {
|
||||
return util.string.gsub(underscored_word, /_/, '-');
|
||||
};
|
||||
|
||||
// Removes the module part from the expression in the string.
|
||||
//
|
||||
// "BulletRecord.String.Inflections".demodulize() // => "Inflections"
|
||||
// "Inflections".demodulize() // => "Inflections"
|
||||
inflect.demodulize = function (class_name_in_module) {
|
||||
return util.string.gsub(class_name_in_module, /^.*\./, '');
|
||||
};
|
||||
|
||||
// Creates a foreign key name from a class name.
|
||||
// _separate_class_name_and_id_with_underscore_ sets whether
|
||||
// the method should put '_' between the name and 'id'.
|
||||
//
|
||||
// "Message".foreign_key() // => "message_id"
|
||||
// "Message".foreign_key(false) // => "messageid"
|
||||
// "Admin::Post".foreign_key() // => "post_id"
|
||||
inflect.foreign_key = function (class_name, separate_class_name_and_id_with_underscore) {
|
||||
if (separate_class_name_and_id_with_underscore == null) {
|
||||
separate_class_name_and_id_with_underscore = true;
|
||||
}
|
||||
return inflect.underscore(inflect.demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id");
|
||||
};
|
||||
|
||||
// Turns a number into an ordinal string used to denote the position in an
|
||||
// ordered sequence such as 1st, 2nd, 3rd, 4th.
|
||||
//
|
||||
// ordinalize(1) // => "1st"
|
||||
// ordinalize(2) // => "2nd"
|
||||
// ordinalize(1002) // => "1002nd"
|
||||
// ordinalize(1003) // => "1003rd"
|
||||
// ordinalize(-11) // => "-11th"
|
||||
// ordinalize(-1021) // => "-1021st"
|
||||
inflect.ordinalize = function (number) {
|
||||
var _ref;
|
||||
number = parseInt(number);
|
||||
if ((_ref = Math.abs(number) % 100) === 11 || _ref === 12 || _ref === 13) {
|
||||
return "" + number + "th";
|
||||
} else {
|
||||
switch (Math.abs(number) % 10) {
|
||||
case 1:
|
||||
return "" + number + "st";
|
||||
case 2:
|
||||
return "" + number + "nd";
|
||||
case 3:
|
||||
return "" + number + "rd";
|
||||
default:
|
||||
return "" + number + "th";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Checks a given word for uncountability
|
||||
//
|
||||
// "money".uncountability() // => true
|
||||
// "my money".uncountability() // => true
|
||||
inflect.uncountability = function (word) {
|
||||
return inflect.inflections.uncountables.some(function(ele, ind, arr) {
|
||||
return word.match(new RegExp("(\\b|_)" + ele + "$", 'i')) != null;
|
||||
});
|
||||
};
|
||||
|
||||
// Returns the plural form of the word in the string.
|
||||
//
|
||||
// "post".pluralize() // => "posts"
|
||||
// "octopus".pluralize() // => "octopi"
|
||||
// "sheep".pluralize() // => "sheep"
|
||||
// "words".pluralize() // => "words"
|
||||
// "CamelOctopus".pluralize() // => "CamelOctopi"
|
||||
inflect.pluralize = function (word) {
|
||||
var plural, result;
|
||||
result = word;
|
||||
if (word === '' || inflect.uncountability(word)) {
|
||||
return result;
|
||||
} else {
|
||||
for (var i = 0; i < inflect.inflections.plurals.length; i++) {
|
||||
plural = inflect.inflections.plurals[i];
|
||||
result = util.string.gsub(result, plural[0], plural[1]);
|
||||
if (word.match(plural[0]) != null) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
// The reverse of _pluralize_, returns the singular form of a word in a string.
|
||||
//
|
||||
// "posts".singularize() // => "post"
|
||||
// "octopi".singularize() // => "octopus"
|
||||
// "sheep".singularize() // => "sheep"
|
||||
// "word".singularize() // => "word"
|
||||
// "CamelOctopi".singularize() // => "CamelOctopus"
|
||||
inflect.singularize = function (word) {
|
||||
var result, singular;
|
||||
result = word;
|
||||
if (word === '' || inflect.uncountability(word)) {
|
||||
return result;
|
||||
} else {
|
||||
for (var i = 0; i < inflect.inflections.singulars.length; i++) {
|
||||
singular = inflect.inflections.singulars[i];
|
||||
result = util.string.gsub(result, singular[0], singular[1]);
|
||||
if (word.match(singular[0])) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
// Capitalizes the first word and turns underscores into spaces and strips a
|
||||
// trailing "_id", if any. Like _titleize_, this is meant for creating pretty output.
|
||||
//
|
||||
// "employee_salary".humanize() // => "Employee salary"
|
||||
// "author_id".humanize() // => "Author"
|
||||
inflect.humanize = function (lower_case_and_underscored_word) {
|
||||
var human, result;
|
||||
result = lower_case_and_underscored_word;
|
||||
for (var i = 0; i < inflect.inflections.humans.length; i++) {
|
||||
human = inflect.inflections.humans[i];
|
||||
result = util.string.gsub(result, human[0], human[1]);
|
||||
}
|
||||
result = util.string.gsub(result, /_id$/, "");
|
||||
result = util.string.gsub(result, /_/, " ");
|
||||
return util.string.capitalize(result, true);
|
||||
};
|
||||
|
||||
// Capitalizes all the words and replaces some characters in the string to create
|
||||
// a nicer looking title. _titleize_ is meant for creating pretty output. It is not
|
||||
// used in the Bullet internals.
|
||||
//
|
||||
//
|
||||
// "man from the boondocks".titleize() // => "Man From The Boondocks"
|
||||
// "x-men: the last stand".titleize() // => "X Men: The Last Stand"
|
||||
inflect.titleize = function (word) {
|
||||
var self;
|
||||
self = inflect.humanize(inflect.underscore(word));
|
||||
self = util.string.gsub(self, /[^a-zA-Z:']/, ' ');
|
||||
return util.string.capitalize(self);
|
||||
};
|
||||
|
||||
// Create the name of a table like Bullet does for models to table names. This method
|
||||
// uses the _pluralize_ method on the last word in the string.
|
||||
//
|
||||
// "RawScaledScorer".tableize() // => "raw_scaled_scorers"
|
||||
// "egg_and_ham".tableize() // => "egg_and_hams"
|
||||
// "fancyCategory".tableize() // => "fancy_categories"
|
||||
inflect.tableize = function (class_name) {
|
||||
return inflect.pluralize(inflect.underscore(class_name));
|
||||
};
|
||||
|
||||
// Create a class name from a plural table name like Bullet does for table names to models.
|
||||
// Note that this returns a string and not a Class.
|
||||
//
|
||||
// "egg_and_hams".classify() // => "EggAndHam"
|
||||
// "posts".classify() // => "Post"
|
||||
//
|
||||
// Singular names are not handled correctly:
|
||||
//
|
||||
// "business".classify() // => "Busines"
|
||||
inflect.classify = function (table_name) {
|
||||
return inflect.camelize(inflect.singularize(util.string.gsub(table_name, /.*\./, '')));
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
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'
|
||||
];
|
||||
|
||||
Object.keys(obj).forEach(function (key) {
|
||||
if (key != 'inflect' && key != 'inflections') {
|
||||
if (stringPrototypeBlacklist.indexOf(key) !== -1) {
|
||||
console.log('warn: You should not override String.prototype.' + key);
|
||||
} else {
|
||||
addProperty(key, function () {
|
||||
return obj[key](this);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
// Some utility functions in js
|
||||
|
||||
var u = module.exports = {
|
||||
array: {
|
||||
// Returns a copy of the array with the value removed once
|
||||
//
|
||||
// [1, 2, 3, 1].del 1 #=> [2, 3, 1]
|
||||
// [1, 2, 3].del 4 #=> [1, 2, 3]
|
||||
del: function (arr, val) {
|
||||
var index = arr.indexOf(val);
|
||||
if (index != -1) {
|
||||
if (index == 0) {
|
||||
return arr.slice(1)
|
||||
} else {
|
||||
return arr.slice(0, index).concat(arr.slice(index+1));
|
||||
}
|
||||
} else {
|
||||
return arr;
|
||||
}
|
||||
},
|
||||
|
||||
// Returns the first element of the array
|
||||
//
|
||||
// [1, 2, 3].first() #=> 1
|
||||
first: function(arr) {
|
||||
return arr[0];
|
||||
},
|
||||
|
||||
// Returns the last element of the array
|
||||
//
|
||||
// [1, 2, 3].last() #=> 3
|
||||
last: function(arr) {
|
||||
return arr[arr.length-1];
|
||||
}
|
||||
},
|
||||
string: {
|
||||
// Returns a copy of str with all occurrences of pattern replaced with either replacement or the return value of a function.
|
||||
// The pattern will typically be a Regexp; if it is a String then no regular expression metacharacters will be interpreted
|
||||
// (that is /\d/ will match a digit, but ‘\d’ will match a backslash followed by a ‘d’).
|
||||
//
|
||||
// In the function form, the current match object is passed in as a parameter to the function, and variables such as
|
||||
// $[1], $[2], $[3] (where $ is the match object) will be set appropriately. The value returned by the function will be
|
||||
// substituted for the match on each call.
|
||||
//
|
||||
// The result inherits any tainting in the original string or any supplied replacement string.
|
||||
//
|
||||
// "hello".gsub /[aeiou]/, '*' #=> "h*ll*"
|
||||
// "hello".gsub /[aeiou]/, '<$1>' #=> "h<e>ll<o>"
|
||||
// "hello".gsub /[aeiou]/, ($) {
|
||||
// "<#{$[1]}>" #=> "h<e>ll<o>"
|
||||
//
|
||||
gsub: function (str, pattern, replacement) {
|
||||
var i, match, matchCmpr, matchCmprPrev, replacementStr, result, self;
|
||||
if (!((pattern != null) && (replacement != null))) return u.string.value(str);
|
||||
result = '';
|
||||
self = str;
|
||||
while (self.length > 0) {
|
||||
if ((match = self.match(pattern))) {
|
||||
result += self.slice(0, match.index);
|
||||
if (typeof replacement === 'function') {
|
||||
match[1] = match[1] || match[0];
|
||||
result += replacement(match);
|
||||
} else if (replacement.match(/\$[1-9]/)) {
|
||||
matchCmprPrev = match;
|
||||
matchCmpr = u.array.del(match, void 0);
|
||||
while (matchCmpr !== matchCmprPrev) {
|
||||
matchCmprPrev = matchCmpr;
|
||||
matchCmpr = u.array.del(matchCmpr, void 0);
|
||||
}
|
||||
match[1] = match[1] || match[0];
|
||||
replacementStr = replacement;
|
||||
for (i = 1; i <= 9; i++) {
|
||||
if (matchCmpr[i]) {
|
||||
replacementStr = u.string.gsub(replacementStr, new RegExp("\\\$" + i), matchCmpr[i]);
|
||||
}
|
||||
}
|
||||
result += replacementStr;
|
||||
} else {
|
||||
result += replacement;
|
||||
}
|
||||
self = self.slice(match.index + match[0].length);
|
||||
} else {
|
||||
result += self;
|
||||
self = '';
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
// Returns a copy of the String with the first letter being upper case
|
||||
//
|
||||
// "hello".upcase #=> "Hello"
|
||||
upcase: function(str) {
|
||||
var self = u.string.gsub(str, /_([a-z])/, function ($) {
|
||||
return "_" + $[1].toUpperCase();
|
||||
});
|
||||
self = u.string.gsub(self, /\/([a-z])/, function ($) {
|
||||
return "/" + $[1].toUpperCase();
|
||||
});
|
||||
return self[0].toUpperCase() + self.substr(1);
|
||||
},
|
||||
|
||||
// Returns a copy of capitalized string
|
||||
//
|
||||
// "employee salary" #=> "Employee Salary"
|
||||
capitalize: function (str, spaces) {
|
||||
var self = str.toLowerCase();
|
||||
if(!spaces) {
|
||||
self = u.string.gsub(self, /\s([a-z])/, function ($) {
|
||||
return " " + $[1].toUpperCase();
|
||||
});
|
||||
}
|
||||
return self[0].toUpperCase() + self.substr(1);
|
||||
},
|
||||
|
||||
// Returns a copy of the String with the first letter being lower case
|
||||
//
|
||||
// "HELLO".downcase #=> "hELLO"
|
||||
downcase: function(str) {
|
||||
var self = u.string.gsub(str, /_([A-Z])/, function ($) {
|
||||
return "_" + $[1].toLowerCase();
|
||||
});
|
||||
self = u.string.gsub(self, /\/([A-Z])/, function ($) {
|
||||
return "/" + $[1].toLowerCase();
|
||||
});
|
||||
return self[0].toLowerCase() + self.substr(1);
|
||||
},
|
||||
|
||||
// Returns a string value for the String object
|
||||
//
|
||||
// "hello".value() #=> "hello"
|
||||
value: function (str) {
|
||||
return str.substr(0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
{
|
||||
"name": "i",
|
||||
"version": "0.3.2",
|
||||
"author": {
|
||||
"name": "Pavan Kumar Sunkara",
|
||||
"email": "pavan.sss1991@gmail.com",
|
||||
"url": "pksunkara.github.com"
|
||||
},
|
||||
"description": "custom inflections for nodejs",
|
||||
"main": "./lib/inflect",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/pksunkara/inflect.git"
|
||||
},
|
||||
"keywords": [
|
||||
"singular",
|
||||
"plural",
|
||||
"camelize",
|
||||
"underscore",
|
||||
"dasherize",
|
||||
"demodulize",
|
||||
"ordinalize",
|
||||
"uncountable",
|
||||
"pluralize",
|
||||
"singularize",
|
||||
"titleize",
|
||||
"tableize",
|
||||
"classify",
|
||||
"foreign_key"
|
||||
],
|
||||
"homepage": "http://pksunkara.github.com/inflect",
|
||||
"scripts": {
|
||||
"test": "vows --spec $(find test -name '*-test.js')"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Pavan Kumar Sunkara",
|
||||
"email": "pavan.sss1991@gmail.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"vows": "~0.6.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.4"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/pksunkara/inflect/issues"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "https://github.com/pksunkara/inflect/raw/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"readme": "# inflect\n\ncustomizable inflections for nodejs\n\n## Installation\n\n```bash\nnpm install i\n```\n\n## Usage\n\nRequire the module before using\n\n```js\nvar inflect = require('i')();\n```\n\nAll the below api functions can be called directly on a string\n\n```js\ninflect.titleize('messages to store') // === 'Messages To Store'\n'messages to store'.titleize // === 'Messages To Store'\n```\n\nonly if `true` is passed while initiating\n\n```js\nvar inflect = require('i')(true);\n```\n\n### Pluralize\n\n```js\ninflect.pluralize('person'); // === 'people'\ninflect.pluralize('octopus'); // === 'octopi'\ninflect.pluralize('Hat'); // === 'Hats'\n```\n\n### Singularize\n\n```js\ninflect.singularize('people'); // === 'person'\ninflect.singularize('octopi'); // === 'octopus'\ninflect.singularize('Hats'); // === 'Hat'\n```\n\n### Camelize\n\n```js\ninflect.camelize('message_properties'); // === 'MessageProperties'\ninflect.camelize('message_properties', false); // === 'messageProperties'\n```\n\n### Underscore\n\n```js\ninflect.underscore('MessageProperties'); // === 'message_properties'\ninflect.underscore('messageProperties'); // === 'message_properties'\n```\n\n### Humanize\n\n```js\ninflect.humanize('message_id'); // === 'Message'\n```\n\n### Dasherize\n\n```js\ninflect.dasherize('message_properties'); // === 'message-properties'\ninflect.dasherize('Message Properties'); // === 'Message Properties'\n```\n\n### Titleize\n\n```js\ninflect.titleize('message_properties'); // === 'Message Properties'\ninflect.titleize('message properties to keep'); // === 'Message Properties to Keep'\n```\n\n### Demodulize\n\n```js\ninflect.demodulize('Message.Bus.Properties'); // === 'Properties'\n```\n\n### Tableize\n\n```js\ninflect.tableize('MessageBusProperty'); // === 'message_bus_properties'\n```\n\n### Classify\n\n```js\ninflect.classify('message_bus_properties'); // === 'MessageBusProperty'\n```\n\n### Foreign key\n\n```js\ninflect.foreign_key('MessageBusProperty'); // === 'message_bus_property_id'\ninflect.foreign_key('MessageBusProperty', false); // === 'message_bus_propertyid'\n```\n\n### Ordinalize\n\n```js\ninflect.ordinalize( '1' ); // === '1st'\n```\n\n## Custom rules for inflection\n\n### Custom plural\n\nWe can use regexp in any of these custom rules\n\n```js\ninflect.inflections.plural('person', 'guys');\ninflect.pluralize('person'); // === 'guys'\ninflect.singularize('guys'); // === 'guy'\n```\n\n### Custom singular\n\n```js\ninflect.inflections.singular('guys', 'person')\ninflect.singularize('guys'); // === 'person'\ninflect.pluralize('person'); // === 'people'\n```\n\n### Custom irregular\n\n```js\ninflect.inflections.irregular('person', 'guys')\ninflect.pluralize('person'); // === 'guys'\ninflect.singularize('guys'); // === 'person'\n```\n\n### Custom human\n\n```js\ninflect.inflections.human(/^(.*)_cnt$/i, '$1_count');\ninflect.inflections.humanize('jargon_cnt'); // === 'Jargon count'\n```\n\n### Custom uncountable\n\n```js\ninflect.inflections.uncountable('oil')\ninflect.pluralize('oil'); // === 'oil'\ninflect.singularize('oil'); // === 'oil'\n```\n\n## Contributors\nHere is a list of [Contributors](http://github.com/pksunkara/inflect/contributors)\n\n### TODO\n\n- More obscure test cases\n\n__I accept pull requests and guarantee a reply back within a day__\n\n## License\nMIT/X11\n\n## Bug Reports\nReport [here](http://github.com/pksunkara/inflect/issues). __Guaranteed reply within a day__.\n\n## Contact\nPavan Kumar Sunkara (pavan.sss1991@gmail.com)\n\nFollow me on [github](https://github.com/users/follow?target=pksunkara), [twitter](http://twitter.com/pksunkara)\n",
|
||||
"readmeFilename": "README.md",
|
||||
"_id": "i@0.3.2",
|
||||
"dist": {
|
||||
"shasum": "b2e2d6ef47900bd924e281231ff4c5cc798d9ea8",
|
||||
"tarball": "http://registry.npmjs.org/i/-/i-0.3.2.tgz"
|
||||
},
|
||||
"_from": "i@*",
|
||||
"_npmVersion": "1.3.5",
|
||||
"_npmUser": {
|
||||
"name": "pksunkara",
|
||||
"email": "pavan.sss1991@gmail.com"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "pksunkara",
|
||||
"email": "pavan.sss1991@gmail.com"
|
||||
}
|
||||
],
|
||||
"directories": {},
|
||||
"_shasum": "b2e2d6ef47900bd924e281231ff4c5cc798d9ea8",
|
||||
"_resolved": "https://registry.npmjs.org/i/-/i-0.3.2.tgz"
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
(function() {
|
||||
|
||||
module.exports = {
|
||||
SingularToPlural: {
|
||||
"search": "searches",
|
||||
"switch": "switches",
|
||||
"fix": "fixes",
|
||||
"box": "boxes",
|
||||
"process": "processes",
|
||||
"address": "addresses",
|
||||
"case": "cases",
|
||||
"stack": "stacks",
|
||||
"wish": "wishes",
|
||||
"fish": "fish",
|
||||
"jeans": "jeans",
|
||||
"funky jeans": "funky jeans",
|
||||
"my money": "my money",
|
||||
"category": "categories",
|
||||
"query": "queries",
|
||||
"ability": "abilities",
|
||||
"agency": "agencies",
|
||||
"movie": "movies",
|
||||
"archive": "archives",
|
||||
"index": "indices",
|
||||
"wife": "wives",
|
||||
"safe": "saves",
|
||||
"half": "halves",
|
||||
"move": "moves",
|
||||
"salesperson": "salespeople",
|
||||
"person": "people",
|
||||
"spokesman": "spokesmen",
|
||||
"man": "men",
|
||||
"woman": "women",
|
||||
"basis": "bases",
|
||||
"diagnosis": "diagnoses",
|
||||
"diagnosis_a": "diagnosis_as",
|
||||
"datum": "data",
|
||||
"medium": "media",
|
||||
"stadium": "stadia",
|
||||
"analysis": "analyses",
|
||||
"node_child": "node_children",
|
||||
"child": "children",
|
||||
"experience": "experiences",
|
||||
"day": "days",
|
||||
"comment": "comments",
|
||||
"foobar": "foobars",
|
||||
"newsletter": "newsletters",
|
||||
"old_news": "old_news",
|
||||
"news": "news",
|
||||
"series": "series",
|
||||
"species": "species",
|
||||
"quiz": "quizzes",
|
||||
"perspective": "perspectives",
|
||||
"ox": "oxen",
|
||||
"photo": "photos",
|
||||
"buffalo": "buffaloes",
|
||||
"tomato": "tomatoes",
|
||||
"dwarf": "dwarves",
|
||||
"elf": "elves",
|
||||
"information": "information",
|
||||
"equipment": "equipment",
|
||||
"bus": "buses",
|
||||
"status": "statuses",
|
||||
"status_code": "status_codes",
|
||||
"mouse": "mice",
|
||||
"louse": "lice",
|
||||
"house": "houses",
|
||||
"octopus": "octopi",
|
||||
"virus": "viri",
|
||||
"alias": "aliases",
|
||||
"portfolio": "portfolios",
|
||||
"vertex": "vertices",
|
||||
"matrix": "matrices",
|
||||
"matrix_fu": "matrix_fus",
|
||||
"axis": "axes",
|
||||
"testis": "testes",
|
||||
"crisis": "crises",
|
||||
"rice": "rice",
|
||||
"shoe": "shoes",
|
||||
"horse": "horses",
|
||||
"prize": "prizes",
|
||||
"edge": "edges",
|
||||
"cow": "kine",
|
||||
"database": "databases"
|
||||
},
|
||||
CamelToUnderscore: {
|
||||
"Product": "product",
|
||||
"SpecialGuest": "special_guest",
|
||||
"ApplicationController": "application_controller",
|
||||
"Area51Controller": "area51_controller"
|
||||
},
|
||||
UnderscoreToLowerCamel: {
|
||||
"product": "product",
|
||||
"Widget": "widget",
|
||||
"special_guest": "specialGuest",
|
||||
"application_controller": "applicationController",
|
||||
"area51_controller": "area51Controller"
|
||||
},
|
||||
CamelToUnderscoreWithoutReverse: {
|
||||
"HTMLTidy": "html_tidy",
|
||||
"HTMLTidyGenerator": "html_tidy_generator",
|
||||
"FreeBSD": "free_bsd",
|
||||
"HTML": "html"
|
||||
},
|
||||
CamelWithModuleToUnderscoreWithSlash: {
|
||||
"Admin.Product": "admin/product",
|
||||
"Users.Commission.Department": "users/commission/department",
|
||||
"UsersSection.CommissionDepartment": "users_section/commission_department"
|
||||
},
|
||||
ClassNameToForeignKeyWithUnderscore: {
|
||||
"Person": "person_id",
|
||||
"MyApplication.Billing.Account": "account_id"
|
||||
},
|
||||
ClassNameToForeignKeyWithoutUnderscore: {
|
||||
"Person": "personid",
|
||||
"MyApplication.Billing.Account": "accountid"
|
||||
},
|
||||
ClassNameToTableName: {
|
||||
"PrimarySpokesman": "primary_spokesmen",
|
||||
"NodeChild": "node_children"
|
||||
},
|
||||
UnderscoreToHuman: {
|
||||
"employee_salary": "Employee salary",
|
||||
"employee_id": "Employee",
|
||||
"underground": "Underground"
|
||||
},
|
||||
MixtureToTitleCase: {
|
||||
'bullet_record': 'Bullet Record',
|
||||
'BulletRecord': 'Bullet Record',
|
||||
'bullet web service': 'Bullet Web Service',
|
||||
'Bullet Web Service': 'Bullet Web Service',
|
||||
'Bullet web service': 'Bullet Web Service',
|
||||
'bulletwebservice': 'Bulletwebservice',
|
||||
'Bulletwebservice': 'Bulletwebservice',
|
||||
"pavan's code": "Pavan's Code",
|
||||
"Pavan's code": "Pavan's Code",
|
||||
"pavan's Code": "Pavan's Code"
|
||||
},
|
||||
OrdinalNumbers: {
|
||||
"-1": "-1st",
|
||||
"-2": "-2nd",
|
||||
"-3": "-3rd",
|
||||
"-4": "-4th",
|
||||
"-5": "-5th",
|
||||
"-6": "-6th",
|
||||
"-7": "-7th",
|
||||
"-8": "-8th",
|
||||
"-9": "-9th",
|
||||
"-10": "-10th",
|
||||
"-11": "-11th",
|
||||
"-12": "-12th",
|
||||
"-13": "-13th",
|
||||
"-14": "-14th",
|
||||
"-20": "-20th",
|
||||
"-21": "-21st",
|
||||
"-22": "-22nd",
|
||||
"-23": "-23rd",
|
||||
"-24": "-24th",
|
||||
"-100": "-100th",
|
||||
"-101": "-101st",
|
||||
"-102": "-102nd",
|
||||
"-103": "-103rd",
|
||||
"-104": "-104th",
|
||||
"-110": "-110th",
|
||||
"-111": "-111th",
|
||||
"-112": "-112th",
|
||||
"-113": "-113th",
|
||||
"-1000": "-1000th",
|
||||
"-1001": "-1001st",
|
||||
"0": "0th",
|
||||
"1": "1st",
|
||||
"2": "2nd",
|
||||
"3": "3rd",
|
||||
"4": "4th",
|
||||
"5": "5th",
|
||||
"6": "6th",
|
||||
"7": "7th",
|
||||
"8": "8th",
|
||||
"9": "9th",
|
||||
"10": "10th",
|
||||
"11": "11th",
|
||||
"12": "12th",
|
||||
"13": "13th",
|
||||
"14": "14th",
|
||||
"20": "20th",
|
||||
"21": "21st",
|
||||
"22": "22nd",
|
||||
"23": "23rd",
|
||||
"24": "24th",
|
||||
"100": "100th",
|
||||
"101": "101st",
|
||||
"102": "102nd",
|
||||
"103": "103rd",
|
||||
"104": "104th",
|
||||
"110": "110th",
|
||||
"111": "111th",
|
||||
"112": "112th",
|
||||
"113": "113th",
|
||||
"1000": "1000th",
|
||||
"1001": "1001st"
|
||||
},
|
||||
UnderscoresToDashes: {
|
||||
"street": "street",
|
||||
"street_address": "street-address",
|
||||
"person_street_address": "person-street-address"
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
87
js/apps/system/aardvark/node_modules/i/test/inflector/inflections-test.js
generated
vendored
Normal file
87
js/apps/system/aardvark/node_modules/i/test/inflector/inflections-test.js
generated
vendored
Normal file
|
@ -0,0 +1,87 @@
|
|||
(function() {
|
||||
var assert, vows;
|
||||
|
||||
vows = require('vows');
|
||||
|
||||
assert = require('assert');
|
||||
|
||||
vows.describe('Module Inflector inflections').addBatch({
|
||||
'Test inflector inflections': {
|
||||
topic: require('../../lib/inflections'),
|
||||
'clear': {
|
||||
'single': function(topic) {
|
||||
topic.uncountables = [1, 2, 3];
|
||||
topic.humans = [1, 2, 3];
|
||||
topic.clear('uncountables');
|
||||
assert.isEmpty(topic.uncountables);
|
||||
return assert.deepEqual(topic.humans, [1, 2, 3]);
|
||||
},
|
||||
'all': function(topic) {
|
||||
assert.deepEqual(topic.humans, [1, 2, 3]);
|
||||
topic.uncountables = [1, 2, 3];
|
||||
topic.clear();
|
||||
assert.isEmpty(topic.uncountables);
|
||||
return assert.isEmpty(topic.humans);
|
||||
}
|
||||
},
|
||||
'uncountable': {
|
||||
'one item': function(topic) {
|
||||
topic.clear();
|
||||
assert.isEmpty(topic.uncountables);
|
||||
topic.uncountable('money');
|
||||
return assert.deepEqual(topic.uncountables, ['money']);
|
||||
},
|
||||
'many items': function(topic) {
|
||||
topic.clear();
|
||||
assert.isEmpty(topic.uncountables);
|
||||
topic.uncountable(['money', 'rice']);
|
||||
return assert.deepEqual(topic.uncountables, ['money', 'rice']);
|
||||
}
|
||||
},
|
||||
'human': function(topic) {
|
||||
topic.clear();
|
||||
assert.isEmpty(topic.humans);
|
||||
topic.human("legacy_col_person_name", "Name");
|
||||
return assert.deepEqual(topic.humans, [["legacy_col_person_name", "Name"]]);
|
||||
},
|
||||
'plural': function(topic) {
|
||||
topic.clear();
|
||||
assert.isEmpty(topic.plurals);
|
||||
topic.plural('ox', 'oxen');
|
||||
assert.deepEqual(topic.plurals, [['ox', 'oxen']]);
|
||||
topic.uncountable('money');
|
||||
assert.deepEqual(topic.uncountables, ['money']);
|
||||
topic.uncountable('monies');
|
||||
topic.plural('money', 'monies');
|
||||
assert.deepEqual(topic.plurals, [['money', 'monies'], ['ox', 'oxen']]);
|
||||
return assert.isEmpty(topic.uncountables);
|
||||
},
|
||||
'singular': function(topic) {
|
||||
topic.clear();
|
||||
assert.isEmpty(topic.singulars);
|
||||
topic.singular('ox', 'oxen');
|
||||
assert.deepEqual(topic.singulars, [['ox', 'oxen']]);
|
||||
topic.uncountable('money');
|
||||
assert.deepEqual(topic.uncountables, ['money']);
|
||||
topic.uncountable('monies');
|
||||
topic.singular('money', 'monies');
|
||||
assert.deepEqual(topic.singulars, [['money', 'monies'], ['ox', 'oxen']]);
|
||||
return assert.isEmpty(topic.uncountables);
|
||||
},
|
||||
'irregular': function(topic) {
|
||||
topic.clear();
|
||||
topic.uncountable(['octopi', 'octopus']);
|
||||
assert.deepEqual(topic.uncountables, ['octopi', 'octopus']);
|
||||
topic.irregular('octopus', 'octopi');
|
||||
assert.isEmpty(topic.uncountables);
|
||||
assert.equal(topic.singulars[0][0].toString(), /(o)ctopi$/i.toString());
|
||||
assert.equal(topic.singulars[0][1], '$1ctopus');
|
||||
assert.equal(topic.plurals[0][0].toString(), /(o)ctopi$/i.toString());
|
||||
assert.equal(topic.plurals[0][1], '$1ctopi');
|
||||
assert.equal(topic.plurals[1][0].toString(), /(o)ctopus$/i.toString());
|
||||
return assert.equal(topic.plurals[1][1].toString(), '$1ctopi');
|
||||
}
|
||||
}
|
||||
})["export"](module);
|
||||
|
||||
}).call(this);
|
342
js/apps/system/aardvark/node_modules/i/test/inflector/methods-test.js
generated
vendored
Normal file
342
js/apps/system/aardvark/node_modules/i/test/inflector/methods-test.js
generated
vendored
Normal file
|
@ -0,0 +1,342 @@
|
|||
(function() {
|
||||
var assert, cases, vows, util;
|
||||
|
||||
vows = require('vows');
|
||||
|
||||
assert = require('assert');
|
||||
|
||||
util = require('../../lib/util');
|
||||
|
||||
cases = require('./cases');
|
||||
|
||||
vows.describe('Module Inflector methods').addBatch({
|
||||
'Test inflector method': {
|
||||
topic: require('../../lib/methods'),
|
||||
'camelize': {
|
||||
'word': function(topic) {
|
||||
var i, words, _i, _len, _ref, _results;
|
||||
words = cases.CamelToUnderscore;
|
||||
_ref = Object.keys(words);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
_results.push(assert.equal(topic.camelize(words[i]), i));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
'word with first letter lower': function(topic) {
|
||||
var i, words, _i, _len, _ref, _results;
|
||||
words = cases.UnderscoreToLowerCamel;
|
||||
_ref = Object.keys(words);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
_results.push(assert.equal(topic.camelize(i, false), words[i]));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
'path': function(topic) {
|
||||
var i, words, _i, _len, _ref, _results;
|
||||
words = cases.CamelWithModuleToUnderscoreWithSlash;
|
||||
_ref = Object.keys(words);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
_results.push(assert.equal(topic.camelize(words[i]), i));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
'path with first letter lower': function(topic) {
|
||||
return assert.equal(topic.camelize('bullet_record/errors', false), 'bulletRecord.Errors');
|
||||
}
|
||||
},
|
||||
'underscore': {
|
||||
'word': function(topic) {
|
||||
var i, words, _i, _j, _len, _len2, _ref, _ref2, _results;
|
||||
words = cases.CamelToUnderscore;
|
||||
_ref = Object.keys(words);
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
assert.equal(topic.underscore(i), words[i]);
|
||||
}
|
||||
words = cases.CamelToUnderscoreWithoutReverse;
|
||||
_ref2 = Object.keys(words);
|
||||
_results = [];
|
||||
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
||||
i = _ref2[_j];
|
||||
_results.push(assert.equal(topic.underscore(i), words[i]));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
'path': function(topic) {
|
||||
var i, words, _i, _len, _ref, _results;
|
||||
words = cases.CamelWithModuleToUnderscoreWithSlash;
|
||||
_ref = Object.keys(words);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
_results.push(assert.equal(topic.underscore(i), words[i]));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
'from dasherize': function(topic) {
|
||||
var i, words, _i, _len, _ref, _results;
|
||||
words = cases.UnderscoresToDashes;
|
||||
_ref = Object.keys(words);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
_results.push(assert.equal(topic.underscore(topic.dasherize(i)), i));
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
},
|
||||
'dasherize': {
|
||||
'underscored_word': function(topic) {
|
||||
var i, words, _i, _len, _ref, _results;
|
||||
words = cases.UnderscoresToDashes;
|
||||
_ref = Object.keys(words);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
_results.push(assert.equal(topic.dasherize(i), words[i]));
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
},
|
||||
'demodulize': {
|
||||
'module name': function(topic) {
|
||||
return assert.equal(topic.demodulize('BulletRecord.CoreExtensions.Inflections'), 'Inflections');
|
||||
},
|
||||
'isolated module name': function(topic) {
|
||||
return assert.equal(topic.demodulize('Inflections'), 'Inflections');
|
||||
}
|
||||
},
|
||||
'foreign_key': {
|
||||
'normal': function(topic) {
|
||||
var i, words, _i, _len, _ref, _results;
|
||||
words = cases.ClassNameToForeignKeyWithoutUnderscore;
|
||||
_ref = Object.keys(words);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
_results.push(assert.equal(topic.foreign_key(i, false), words[i]));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
'with_underscore': function(topic) {
|
||||
var i, words, _i, _len, _ref, _results;
|
||||
words = cases.ClassNameToForeignKeyWithUnderscore;
|
||||
_ref = Object.keys(words);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
_results.push(assert.equal(topic.foreign_key(i), words[i]));
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
},
|
||||
'ordinalize': function(topic) {
|
||||
var i, words, _i, _len, _ref, _results;
|
||||
words = cases.OrdinalNumbers;
|
||||
_ref = Object.keys(words);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
_results.push(assert.equal(topic.ordinalize(i), words[i]));
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
'Test inflector inflection methods': {
|
||||
topic: function() {
|
||||
var Inflector;
|
||||
Inflector = require('../../lib/methods');
|
||||
Inflector.inflections["default"]();
|
||||
return Inflector;
|
||||
},
|
||||
'pluralize': {
|
||||
'empty': function(topic) {
|
||||
return assert.equal(topic.pluralize(''), '');
|
||||
},
|
||||
'uncountable': function(topic) {
|
||||
return assert.equal(topic.pluralize('money'), 'money');
|
||||
},
|
||||
'normal': function(topic) {
|
||||
topic.inflections.irregular('octopus', 'octopi');
|
||||
return assert.equal(topic.pluralize('octopus'), 'octopi');
|
||||
},
|
||||
'cases': function(topic) {
|
||||
var i, words, _i, _j, _len, _len2, _ref, _ref2, _results;
|
||||
words = cases.SingularToPlural;
|
||||
_ref = Object.keys(words);
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
assert.equal(topic.pluralize(i), words[i]);
|
||||
}
|
||||
_ref2 = Object.keys(words);
|
||||
_results = [];
|
||||
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
||||
i = _ref2[_j];
|
||||
_results.push(assert.equal(topic.pluralize(util.string.capitalize(i)), util.string.capitalize(words[i])));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
'cases plural': function(topic) {
|
||||
var i, words, _i, _j, _len, _len2, _ref, _ref2, _results;
|
||||
words = cases.SingularToPlural;
|
||||
_ref = Object.keys(words);
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
assert.equal(topic.pluralize(words[i]), words[i]);
|
||||
}
|
||||
_ref2 = Object.keys(words);
|
||||
_results = [];
|
||||
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
||||
i = _ref2[_j];
|
||||
_results.push(assert.equal(topic.pluralize(util.string.capitalize(words[i])), util.string.capitalize(words[i])));
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
},
|
||||
'singuralize': {
|
||||
'empty': function(topic) {
|
||||
return assert.equal(topic.singularize(''), '');
|
||||
},
|
||||
'uncountable': function(topic) {
|
||||
return assert.equal(topic.singularize('money'), 'money');
|
||||
},
|
||||
'normal': function(topic) {
|
||||
topic.inflections.irregular('octopus', 'octopi');
|
||||
return assert.equal(topic.singularize('octopi'), 'octopus');
|
||||
},
|
||||
'cases': function(topic) {
|
||||
var i, words, _i, _j, _len, _len2, _ref, _ref2, _results;
|
||||
words = cases.SingularToPlural;
|
||||
_ref = Object.keys(words);
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
assert.equal(topic.singularize(words[i]), i);
|
||||
}
|
||||
_ref2 = Object.keys(words);
|
||||
_results = [];
|
||||
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
||||
i = _ref2[_j];
|
||||
_results.push(assert.equal(topic.singularize(util.string.capitalize(words[i])), util.string.capitalize(i)));
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
},
|
||||
'uncountablility': {
|
||||
'normal': function(topic) {
|
||||
var i, words, _i, _j, _k, _len, _len2, _len3, _results;
|
||||
words = topic.inflections.uncountables;
|
||||
for (_i = 0, _len = words.length; _i < _len; _i++) {
|
||||
i = words[_i];
|
||||
assert.equal(topic.singularize(i), i);
|
||||
}
|
||||
for (_j = 0, _len2 = words.length; _j < _len2; _j++) {
|
||||
i = words[_j];
|
||||
assert.equal(topic.pluralize(i), i);
|
||||
}
|
||||
_results = [];
|
||||
for (_k = 0, _len3 = words.length; _k < _len3; _k++) {
|
||||
i = words[_k];
|
||||
_results.push(assert.equal(topic.singularize(i), topic.pluralize(i)));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
'greedy': function(topic) {
|
||||
var countable_word, uncountable_word;
|
||||
uncountable_word = "ors";
|
||||
countable_word = "sponsor";
|
||||
topic.inflections.uncountable(uncountable_word);
|
||||
assert.equal(topic.singularize(uncountable_word), uncountable_word);
|
||||
assert.equal(topic.pluralize(uncountable_word), uncountable_word);
|
||||
assert.equal(topic.pluralize(uncountable_word), topic.singularize(uncountable_word));
|
||||
assert.equal(topic.singularize(countable_word), 'sponsor');
|
||||
assert.equal(topic.pluralize(countable_word), 'sponsors');
|
||||
return assert.equal(topic.singularize(topic.pluralize(countable_word)), 'sponsor');
|
||||
}
|
||||
},
|
||||
'humanize': {
|
||||
'normal': function(topic) {
|
||||
var i, words, _i, _len, _ref, _results;
|
||||
words = cases.UnderscoreToHuman;
|
||||
_ref = Object.keys(words);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
_results.push(assert.equal(topic.humanize(i), words[i]));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
'with rule': function(topic) {
|
||||
topic.inflections.human(/^(.*)_cnt$/i, '$1_count');
|
||||
topic.inflections.human(/^prefix_(.*)$/i, '$1');
|
||||
assert.equal(topic.humanize('jargon_cnt'), 'Jargon count');
|
||||
return assert.equal(topic.humanize('prefix_request'), 'Request');
|
||||
},
|
||||
'with string': function(topic) {
|
||||
topic.inflections.human('col_rpted_bugs', 'Reported bugs');
|
||||
assert.equal(topic.humanize('col_rpted_bugs'), 'Reported bugs');
|
||||
return assert.equal(topic.humanize('COL_rpted_bugs'), 'Col rpted bugs');
|
||||
},
|
||||
'with _id': function(topic) {
|
||||
return assert.equal(topic.humanize('author_id'), 'Author');
|
||||
}
|
||||
},
|
||||
'titleize': {
|
||||
'normal': function(topic) {
|
||||
var i, words, _i, _len, _ref, _results;
|
||||
words = cases.MixtureToTitleCase;
|
||||
_ref = Object.keys(words);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
_results.push(assert.equal(topic.titleize(i), words[i]));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
'with hyphens': function(topic) {
|
||||
return assert.equal(topic.titleize('x-men: the last stand'), 'X Men: The Last Stand');
|
||||
}
|
||||
},
|
||||
'tableize': function(topic) {
|
||||
var i, words, _i, _len, _ref, _results;
|
||||
words = cases.ClassNameToTableName;
|
||||
_ref = Object.keys(words);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
_results.push(assert.equal(topic.tableize(i), words[i]));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
'classify': {
|
||||
'underscore': function(topic) {
|
||||
var i, words, _i, _j, _len, _len2, _ref, _ref2, _results;
|
||||
words = cases.ClassNameToTableName;
|
||||
_ref = Object.keys(words);
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
i = _ref[_i];
|
||||
assert.equal(topic.classify(words[i]), i);
|
||||
}
|
||||
_ref2 = Object.keys(words);
|
||||
_results = [];
|
||||
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
||||
i = _ref2[_j];
|
||||
_results.push(assert.equal(topic.classify('table_prefix.' + words[i]), i));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
'normal': function(topic) {
|
||||
topic.inflections.irregular('octopus', 'octopi');
|
||||
return assert.equal(topic.classify('octopi'), 'Octopus');
|
||||
}
|
||||
}
|
||||
}
|
||||
})["export"](module);
|
||||
|
||||
}).call(this);
|
|
@ -0,0 +1,39 @@
|
|||
(function() {
|
||||
var assert, vows, util;
|
||||
|
||||
vows = require('vows');
|
||||
|
||||
assert = require('assert');
|
||||
|
||||
util = require('../../lib/util');
|
||||
|
||||
vows.describe('Module core extension Array').addBatch({
|
||||
'Testing del': {
|
||||
topic: ['a', 'b', 'c'],
|
||||
'element exists': {
|
||||
'first element': function(topic) {
|
||||
return assert.deepEqual(util.array.del(topic, 'a'), ['b', 'c']);
|
||||
},
|
||||
'middle element': function(topic) {
|
||||
return assert.deepEqual(util.array.del(topic, 'b'), ['a', 'c']);
|
||||
},
|
||||
'last element': function(topic) {
|
||||
return assert.deepEqual(util.array.del(topic, 'c'), ['a', 'b']);
|
||||
}
|
||||
},
|
||||
'element does not exist': function(topic) {
|
||||
return assert.deepEqual(util.array.del(topic, 'd'), ['a', 'b', 'c']);
|
||||
}
|
||||
},
|
||||
'Testing utils': {
|
||||
topic: ['a', 'b', 'c'],
|
||||
'first': function(topic) {
|
||||
return assert.equal(util.array.first(topic), 'a');
|
||||
},
|
||||
'last': function(topic) {
|
||||
return assert.equal(util.array.last(topic), 'c');
|
||||
}
|
||||
}
|
||||
})["export"](module);
|
||||
|
||||
}).call(this);
|
|
@ -0,0 +1,88 @@
|
|||
(function() {
|
||||
var assert, vows, util;
|
||||
|
||||
vows = require('vows');
|
||||
|
||||
assert = require('assert');
|
||||
|
||||
util = require('../../lib/util');
|
||||
|
||||
vows.describe('Module core extension String').addBatch({
|
||||
'Testing value': {
|
||||
topic: 'bullet',
|
||||
'join the keys': function(topic) {
|
||||
return assert.equal(util.string.value(topic), 'bullet');
|
||||
}
|
||||
},
|
||||
'Testing gsub': {
|
||||
topic: 'bullet',
|
||||
'when no args': function(topic) {
|
||||
return assert.equal(util.string.gsub(topic), 'bullet');
|
||||
},
|
||||
'when only 1 arg': function(topic) {
|
||||
return assert.equal(util.string.gsub(topic, /./), 'bullet');
|
||||
},
|
||||
'when given proper args': function(topic) {
|
||||
return assert.equal(util.string.gsub(topic, /[aeiou]/, '*'), 'b*ll*t');
|
||||
},
|
||||
'when replacement is a function': {
|
||||
'with many groups': function(topic) {
|
||||
var str;
|
||||
str = util.string.gsub(topic, /([aeiou])(.)/, function($) {
|
||||
return "<" + $[1] + ">" + $[2];
|
||||
});
|
||||
return assert.equal(str, 'b<u>ll<e>t');
|
||||
},
|
||||
'with no groups': function(topic) {
|
||||
var str;
|
||||
str = util.string.gsub(topic, /[aeiou]/, function($) {
|
||||
return "<" + $[1] + ">";
|
||||
});
|
||||
return assert.equal(str, 'b<u>ll<e>t');
|
||||
}
|
||||
},
|
||||
'when replacement is special': {
|
||||
'with many groups': function(topic) {
|
||||
return assert.equal(util.string.gsub(topic, /([aeiou])(.)/, '<$1>$2'), 'b<u>ll<e>t');
|
||||
},
|
||||
'with no groups': function(topic) {
|
||||
return assert.equal(util.string.gsub(topic, /[aeiou]/, '<$1>'), 'b<u>ll<e>t');
|
||||
}
|
||||
}
|
||||
},
|
||||
'Testing capitalize': {
|
||||
topic: 'employee salary',
|
||||
'normal': function(topic) {
|
||||
return assert.equal(util.string.capitalize(topic), 'Employee Salary');
|
||||
}
|
||||
},
|
||||
'Testing upcase': {
|
||||
topic: 'bullet',
|
||||
'only first letter should be upcase': function(topic) {
|
||||
return assert.equal(util.string.upcase(topic), 'Bullet');
|
||||
},
|
||||
'letter after underscore': function(topic) {
|
||||
return assert.equal(util.string.upcase('bullet_record'), 'Bullet_Record');
|
||||
},
|
||||
'letter after slash': function(topic) {
|
||||
return assert.equal(util.string.upcase('bullet_record/errors'), 'Bullet_Record/Errors');
|
||||
},
|
||||
'no letter after space': function(topic) {
|
||||
return assert.equal(util.string.upcase('employee salary'), 'Employee salary');
|
||||
}
|
||||
},
|
||||
'Testing downcase': {
|
||||
topic: 'BULLET',
|
||||
'only first letter should be downcase': function(topic) {
|
||||
return assert.equal(util.string.downcase(topic), 'bULLET');
|
||||
},
|
||||
'letter after underscore': function(topic) {
|
||||
return assert.equal(util.string.downcase('BULLET_RECORD'), 'bULLET_rECORD');
|
||||
},
|
||||
'letter after slash': function(topic) {
|
||||
return assert.equal(util.string.downcase('BULLET_RECORD/ERRORS'), 'bULLET_rECORD/eRRORS');
|
||||
}
|
||||
}
|
||||
})["export"](module);
|
||||
|
||||
}).call(this);
|
Loading…
Reference in New Issue