You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					96 lines
				
				1.8 KiB
			
		
		
			
		
	
	
					96 lines
				
				1.8 KiB
			| 
											3 years ago
										 | module.exports = pluralize; | ||
|  | 
 | ||
|  | /** | ||
|  |  * Pluralization rules. | ||
|  |  * | ||
|  |  * These rules are applied while processing the argument to `toCollectionName`. | ||
|  |  * | ||
|  |  * @deprecated remove in 4.x gh-1350 | ||
|  |  */ | ||
|  | 
 | ||
|  | exports.pluralization = [ | ||
|  |   [/(m)an$/gi, '$1en'], | ||
|  |   [/(pe)rson$/gi, '$1ople'], | ||
|  |   [/(child)$/gi, '$1ren'], | ||
|  |   [/^(ox)$/gi, '$1en'], | ||
|  |   [/(ax|test)is$/gi, '$1es'], | ||
|  |   [/(octop|vir)us$/gi, '$1i'], | ||
|  |   [/(alias|status)$/gi, '$1es'], | ||
|  |   [/(bu)s$/gi, '$1ses'], | ||
|  |   [/(buffal|tomat|potat)o$/gi, '$1oes'], | ||
|  |   [/([ti])um$/gi, '$1a'], | ||
|  |   [/sis$/gi, 'ses'], | ||
|  |   [/(?:([^f])fe|([lr])f)$/gi, '$1$2ves'], | ||
|  |   [/(hive)$/gi, '$1s'], | ||
|  |   [/([^aeiouy]|qu)y$/gi, '$1ies'], | ||
|  |   [/(x|ch|ss|sh)$/gi, '$1es'], | ||
|  |   [/(matr|vert|ind)ix|ex$/gi, '$1ices'], | ||
|  |   [/([m|l])ouse$/gi, '$1ice'], | ||
|  |   [/(kn|w|l)ife$/gi, '$1ives'], | ||
|  |   [/(quiz)$/gi, '$1zes'], | ||
|  |   [/s$/gi, 's'], | ||
|  |   [/([^a-z])$/, '$1'], | ||
|  |   [/$/gi, 's'] | ||
|  | ]; | ||
|  | var rules = exports.pluralization; | ||
|  | 
 | ||
|  | /** | ||
|  |  * Uncountable words. | ||
|  |  * | ||
|  |  * These words are applied while processing the argument to `toCollectionName`. | ||
|  |  * @api public | ||
|  |  */ | ||
|  | 
 | ||
|  | exports.uncountables = [ | ||
|  |   'advice', | ||
|  |   'energy', | ||
|  |   'excretion', | ||
|  |   'digestion', | ||
|  |   'cooperation', | ||
|  |   'health', | ||
|  |   'justice', | ||
|  |   'labour', | ||
|  |   'machinery', | ||
|  |   'equipment', | ||
|  |   'information', | ||
|  |   'pollution', | ||
|  |   'sewage', | ||
|  |   'paper', | ||
|  |   'money', | ||
|  |   'species', | ||
|  |   'series', | ||
|  |   'rain', | ||
|  |   'rice', | ||
|  |   'fish', | ||
|  |   'sheep', | ||
|  |   'moose', | ||
|  |   'deer', | ||
|  |   'news', | ||
|  |   'expertise', | ||
|  |   'status', | ||
|  |   'media' | ||
|  | ]; | ||
|  | var uncountables = exports.uncountables; | ||
|  | 
 | ||
|  | /*! | ||
|  |  * Pluralize function. | ||
|  |  * | ||
|  |  * @author TJ Holowaychuk (extracted from _ext.js_) | ||
|  |  * @param {String} string to pluralize | ||
|  |  * @api private | ||
|  |  */ | ||
|  | 
 | ||
|  | function pluralize(str) { | ||
|  |   var found; | ||
|  |   str = str.toLowerCase(); | ||
|  |   if (!~uncountables.indexOf(str)) { | ||
|  |     found = rules.filter(function(rule) { | ||
|  |       return str.match(rule[0]); | ||
|  |     }); | ||
|  |     if (found[0]) { | ||
|  |       return str.replace(found[0][0], found[0][1]); | ||
|  |     } | ||
|  |   } | ||
|  |   return str; | ||
|  | } |