From 22a5db7b53623e54827bceda2d30e3f1ba2ad123 Mon Sep 17 00:00:00 2001 From: Ritchie Date: Fri, 24 May 2013 07:59:59 -0700 Subject: [PATCH] Add rest middleware --- lib/middleware/rest.js | 53 ++ node_modules/inflection/.npmignore | 4 + node_modules/inflection/History.md | 65 +++ node_modules/inflection/Readme.md | 413 +++++++++++++++ node_modules/inflection/lib/inflection.js | 601 ++++++++++++++++++++++ node_modules/inflection/package.json | 67 +++ node_modules/sl-remoting | 1 + 7 files changed, 1204 insertions(+) create mode 100644 lib/middleware/rest.js create mode 100644 node_modules/inflection/.npmignore create mode 100644 node_modules/inflection/History.md create mode 100644 node_modules/inflection/Readme.md create mode 100644 node_modules/inflection/lib/inflection.js create mode 100644 node_modules/inflection/package.json create mode 120000 node_modules/sl-remoting diff --git a/lib/middleware/rest.js b/lib/middleware/rest.js new file mode 100644 index 00000000..36c58394 --- /dev/null +++ b/lib/middleware/rest.js @@ -0,0 +1,53 @@ +/** + * Module dependencies. + */ + +var asteroid = require('../asteroid'); +var RemoteObjects = require('sl-remoting') + +/** + * Export the middleware. + */ + +module.exports = rest; + +/** + * Build a temp app for mounting resources. + */ + +function rest() { + return function (req, res, next) { + var app = req.app; + var remotes = app.remotes(); + + + + // get models + var models = app.models(); + + // export the models as remote objects + remotes.exports = models; + + Object.keys(models).forEach(function (name) { + var Model = models[name]; + + Model.sharedCtor = function (id, fn) { + // TODO this should be agnostic of behavior + Model.find(id, fn); + } + Model.sharedCtor.accepts = {arg: 'id', type: 'any'}; + }); + + var handler = remotes.handler('rest'); + + if(req.url === '/routes') { + res.send(handler.adapter.allRoutes()); + } else if(req.url === '/models') { + return res.send(remotes.toJSON()); + } else { + handler(req, res, next); + } + } +} + + diff --git a/node_modules/inflection/.npmignore b/node_modules/inflection/.npmignore new file mode 100644 index 00000000..f1250e58 --- /dev/null +++ b/node_modules/inflection/.npmignore @@ -0,0 +1,4 @@ +support +test +examples +*.sock diff --git a/node_modules/inflection/History.md b/node_modules/inflection/History.md new file mode 100644 index 00000000..21ac78a3 --- /dev/null +++ b/node_modules/inflection/History.md @@ -0,0 +1,65 @@ +# History + +## 1.2.5 / 2013-01-09 + +- [refactoring] Allow all caps strings to be returned from underscore + + + +## 1.2.4 / 2013-01-06 + +- [bug fix] window obj does not have `call` method + + + +## 1.2.3 / 2012-08-02 + +- [bug fix] Singularize `status` produces `statu` +- [update packages] should->v1.1.0 + + + +## 1.2.2 / 2012-07-23 + +- [update packages] node.flow->v1.1.3 & should->v1.0.0 + + + +## 1.2.1 / 2012-06-22 + +- [bug fix] Singularize `address` produces `addres` + + + +## 1.2.0 / 2012-04-10 + +- [new feature] Browser support +- [update packages] node.flow->v1.1.1 + + + +## 1.1.1 / 2012-02-13 + +- [update packages] node.flow->v1.1.0 + + + +## 1.1.0 / 2012-02-13 + +- [update packages] node.flow->v1.0.0 +- [refactoring] Read version number from package.json + + + +## 1.0.0 / 2012-02-08 + +- Remove make file +- Add pluralize rules +- Add pluralize tests +- [refactoring] Use object.jey instead of for in + + + +## 0.0.1 / 2012-01-16 + +- Initial release diff --git a/node_modules/inflection/Readme.md b/node_modules/inflection/Readme.md new file mode 100644 index 00000000..9e321c6f --- /dev/null +++ b/node_modules/inflection/Readme.md @@ -0,0 +1,413 @@ +# inflection + +A port of inflection-js to node.js module + + + +## Description +[inflection-js](http://code.google.com/p/inflection-js/) is a port of the functionality from Ruby on Rails' Active Support Inflection classes into Javascript. `inflection` is a port of `inflection-js` to node.js npm package. Instead of [extending JavaScript native](http://wonko.com/post/extending-javascript-natives) String object like `inflection-js` does, `inflection` separate the methods to a independent package to avoid unexpected behaviors. + + + +## Requires + +Checkout `package.json` for dependencies. + + + +## Installation + +Install inflection through npm + + npm install inflection + + + +## API + +- inflection.indexOf( arr, item, fromIndex, compareFunc ); +- inflection.pluralize( str, plural ); +- inflection.singularize( str, singular ); +- inflection.camelize( str, lowFirstLetter ); +- inflection.underscore( str, allUpperCase ); +- inflection.humanize( str, lowFirstLetter ); +- inflection.capitalize( str ); +- inflection.dasherize( str ); +- inflection.titleize( str ); +- inflection.demodulize( str ); +- inflection.tableize( str ); +- inflection.classify( str ); +- inflection.foreign_key( str, dropIdUbar ); +- inflection.ordinalize( str ); + + + +## Usage + +> Require the module before using + + var inflection = require( 'inflection' ); + + + +### inflection.indexOf( arr, item, fromIndex, compareFunc ); + +This lets us detect if an Array contains a given element. + +#### Arguments + +> arr + + type: Array + desc: The subject array. + +> item + + type: Object + desc: Object to locate in the Array. + +> fromIndex + + type: Number + desc: Starts checking from this position in the Array.(optional) + +> compareFunc + + type: Function + desc: Function used to compare Array item vs passed item.(optional) + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.indexOf([ 'hi','there' ], 'guys' ); // === -1 + inflection.indexOf([ 'hi','there' ], 'hi' ); // === 0 + + + +### inflection.pluralize( str, plural ); + +This function adds pluralization support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +> plural + + type: String + desc: Overrides normal output with said String.(optional) + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.pluralize( 'person' ); // === 'people' + inflection.pluralize( 'octopus' ); // === "octopi" + inflection.pluralize( 'Hat' ); // === 'Hats' + inflection.pluralize( 'person', 'guys' ); // === 'guys' + + + +### inflection.singularize( str, singular ); + +This function adds singularization support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +> singular + + type: String + desc: Overrides normal output with said String.(optional) + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.singularize( 'people' ); // === 'person' + inflection.singularize( 'octopi' ); // === "octopus" + inflection.singularize( 'Hats' ); // === 'Hat' + inflection.singularize( 'guys', 'person' ); // === 'person' + + + +### inflection.camelize( str, lowFirstLetter ); + +This function adds camelization support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +> lowFirstLetter + + type: Boolean + desc: Default is to capitalize the first letter of the results. Passing true will lowercase it. (optional) + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.camelize( 'message_properties' ); // === 'MessageProperties' + inflection.camelize( 'message_properties', true ); // === 'messageProperties' + + + +### inflection.underscore( str, allUpperCase ); + +This function adds underscore support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +> allUpperCase + + type: Boolean + desc: Default is to lowercase and add underscore prefix + + + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.underscore( 'MessageProperties' ); // === 'message_properties' + inflection.underscore( 'messageProperties' ); // === 'message_properties' + inflection.underscore( 'MP' ); // === 'm_p' + inflection.underscore( 'MP', true ); // === 'MP' + + + +### inflection.humanize( str, lowFirstLetter ); + +This function adds humanize support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +> lowFirstLetter + + type: Boolean + desc: Default is to capitalize the first letter of the results. Passing true will lowercase it. (optional) + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.humanize( 'message_properties' ); // === 'Message properties' + inflection.humanize( 'message_properties', true ); // === 'message properties' + + + +### inflection.capitalize( str ); + +This function adds capitalization support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.capitalize( 'message_properties' ); // === 'Message_properties' + inflection.capitalize( 'message properties', true ); // === 'Message properties' + + + +### inflection.dasherize( str ); + +This function adds dasherization support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.dasherize( 'message_properties' ); // === 'message-properties' + inflection.dasherize( 'Message Properties' ); // === 'Message-Properties' + + + +### inflection.titleize( str ); + +This function adds titleize support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.titleize( 'message_properties' ); // === 'Message Properties' + inflection.titleize( 'message properties to keep' ); // === 'Message Properties to Keep' + + + +### inflection.demodulize( str ); + +This function adds demodulize support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.demodulize( 'Message::Bus::Properties' ); // === 'Properties' + + + +### inflection.tableize( str ); + +This function adds tableize support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.tableize( 'MessageBusProperty' ); // === 'message_bus_properties' + + + +### inflection.classify( str ); + +This function adds classification support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.classify( 'message_bus_properties' ); // === 'MessageBusProperty' + + + +### inflection.foreign_key( str, dropIdUbar ); + +This function adds foreign key support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +> lowFirstLetter + + type: Boolean + desc: Default is to seperate id with an underbar at the end of the class name, you can pass true to skip it.(optional) + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.foreign_key( 'MessageBusProperty' ); // === 'message_bus_property_id' + inflection.foreign_key( 'MessageBusProperty', true ); // === 'message_bus_propertyid' + + + +### inflection.ordinalize( str ); + +This function adds ordinalize support to every String object. + +#### Arguments + +> str + + type: String + desc: The subject string. + +#### Example code + + var inflection = require( 'inflection' ); + + inflection.ordinalize( 'the 1 pitch' ); // === 'the 1st pitch' + + + +## Credit + +- Ryan Schuft +- Lance Pollard (Browser support) +- brandondewitt + + + +## License + +(The MIT License) + +Copyright (c) 2011 dreamerslab <ben@dreamerslab.com> + +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. diff --git a/node_modules/inflection/lib/inflection.js b/node_modules/inflection/lib/inflection.js new file mode 100644 index 00000000..dc0e5f6b --- /dev/null +++ b/node_modules/inflection/lib/inflection.js @@ -0,0 +1,601 @@ +/*! + * inflection + * Copyright(c) 2011 Ben Lin + * MIT Licensed + * + * @fileoverview + * A port of inflection-js to node.js module. + */ + +( function ( root ){ + + /** + * @description This is a list of nouns that use the same form for both singular and plural. + * This list should remain entirely in lower case to correctly match Strings. + * @private + */ + var uncountable_words = [ + 'equipment', 'information', 'rice', 'money', 'species', + 'series', 'fish', 'sheep', 'moose', 'deer', 'news' + ]; + + /** + * @description These rules translate from the singular form of a noun to its plural form. + * @private + */ + var plural_rules = [ + + // do not replace if its already a plural word + [ new RegExp( '(m)en$', 'gi' )], + [ new RegExp( '(pe)ople$', 'gi' )], + [ new RegExp( '(child)ren$', 'gi' )], + [ new RegExp( '([ti])a$', 'gi' )], + [ new RegExp( '((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$','gi' )], + [ new RegExp( '(hive)s$', 'gi' )], + [ new RegExp( '(tive)s$', 'gi' )], + [ new RegExp( '(curve)s$', 'gi' )], + [ new RegExp( '([lr])ves$', 'gi' )], + [ new RegExp( '([^fo])ves$', 'gi' )], + [ new RegExp( '([^aeiouy]|qu)ies$', 'gi' )], + [ new RegExp( '(s)eries$', 'gi' )], + [ new RegExp( '(m)ovies$', 'gi' )], + [ new RegExp( '(x|ch|ss|sh)es$', 'gi' )], + [ new RegExp( '([m|l])ice$', 'gi' )], + [ new RegExp( '(bus)es$', 'gi' )], + [ new RegExp( '(o)es$', 'gi' )], + [ new RegExp( '(shoe)s$', 'gi' )], + [ new RegExp( '(cris|ax|test)es$', 'gi' )], + [ new RegExp( '(octop|vir)i$', 'gi' )], + [ new RegExp( '(alias|status)es$', 'gi' )], + [ new RegExp( '^(ox)en', 'gi' )], + [ new RegExp( '(vert|ind)ices$', 'gi' )], + [ new RegExp( '(matr)ices$', 'gi' )], + [ new RegExp( '(quiz)zes$', 'gi' )], + + // original rule + [ new RegExp( '(m)an$', 'gi' ), '$1en' ], + [ new RegExp( '(pe)rson$', 'gi' ), '$1ople' ], + [ new RegExp( '(child)$', 'gi' ), '$1ren' ], + [ new RegExp( '^(ox)$', 'gi' ), '$1en' ], + [ new RegExp( '(ax|test)is$', 'gi' ), '$1es' ], + [ new RegExp( '(octop|vir)us$', 'gi' ), '$1i' ], + [ new RegExp( '(alias|status)$', 'gi' ), '$1es' ], + [ new RegExp( '(bu)s$', 'gi' ), '$1ses' ], + [ new RegExp( '(buffal|tomat|potat)o$', 'gi' ), '$1oes' ], + [ new RegExp( '([ti])um$', 'gi' ), '$1a' ], + [ new RegExp( 'sis$', 'gi' ), 'ses' ], + [ new RegExp( '(?:([^f])fe|([lr])f)$', 'gi' ), '$1$2ves' ], + [ new RegExp( '(hive)$', 'gi' ), '$1s' ], + [ new RegExp( '([^aeiouy]|qu)y$', 'gi' ), '$1ies' ], + [ new RegExp( '(x|ch|ss|sh)$', 'gi' ), '$1es' ], + [ new RegExp( '(matr|vert|ind)ix|ex$', 'gi' ), '$1ices' ], + [ new RegExp( '([m|l])ouse$', 'gi' ), '$1ice' ], + [ new RegExp( '(quiz)$', 'gi' ), '$1zes' ], + + [ new RegExp( 's$', 'gi' ), 's' ], + [ new RegExp( '$', 'gi' ), 's' ] + ]; + + /** + * @description These rules translate from the plural form of a noun to its singular form. + * @private + */ + var singular_rules = [ + + // do not replace if its already a singular word + [ new RegExp( '(m)an$', 'gi' )], + [ new RegExp( '(pe)rson$', 'gi' )], + [ new RegExp( '(child)$', 'gi' )], + [ new RegExp( '^(ox)$', 'gi' )], + [ new RegExp( '(ax|test)is$', 'gi' )], + [ new RegExp( '(octop|vir)us$', 'gi' )], + [ new RegExp( '(alias|status)$', 'gi' )], + [ new RegExp( '(bu)s$', 'gi' )], + [ new RegExp( '(buffal|tomat|potat)o$', 'gi' )], + [ new RegExp( '([ti])um$', 'gi' )], + [ new RegExp( 'sis$', 'gi' )], + [ new RegExp( '(?:([^f])fe|([lr])f)$', 'gi' )], + [ new RegExp( '(hive)$', 'gi' )], + [ new RegExp( '([^aeiouy]|qu)y$', 'gi' )], + [ new RegExp( '(x|ch|ss|sh)$', 'gi' )], + [ new RegExp( '(matr|vert|ind)ix|ex$', 'gi' )], + [ new RegExp( '([m|l])ouse$', 'gi' )], + [ new RegExp( '(quiz)$', 'gi' )], + + // original rule + [ new RegExp( '(m)en$', 'gi' ), '$1an' ], + [ new RegExp( '(pe)ople$', 'gi' ), '$1rson' ], + [ new RegExp( '(child)ren$', 'gi' ), '$1' ], + [ new RegExp( '([ti])a$', 'gi' ), '$1um' ], + [ new RegExp( '((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$','gi' ), '$1$2sis' ], + [ new RegExp( '(hive)s$', 'gi' ), '$1' ], + [ new RegExp( '(tive)s$', 'gi' ), '$1' ], + [ new RegExp( '(curve)s$', 'gi' ), '$1' ], + [ new RegExp( '([lr])ves$', 'gi' ), '$1f' ], + [ new RegExp( '([^fo])ves$', 'gi' ), '$1fe' ], + [ new RegExp( '([^aeiouy]|qu)ies$', 'gi' ), '$1y' ], + [ new RegExp( '(s)eries$', 'gi' ), '$1eries' ], + [ new RegExp( '(m)ovies$', 'gi' ), '$1ovie' ], + [ new RegExp( '(x|ch|ss|sh)es$', 'gi' ), '$1' ], + [ new RegExp( '([m|l])ice$', 'gi' ), '$1ouse' ], + [ new RegExp( '(bus)es$', 'gi' ), '$1' ], + [ new RegExp( '(o)es$', 'gi' ), '$1' ], + [ new RegExp( '(shoe)s$', 'gi' ), '$1' ], + [ new RegExp( '(cris|ax|test)es$', 'gi' ), '$1is' ], + [ new RegExp( '(octop|vir)i$', 'gi' ), '$1us' ], + [ new RegExp( '(alias|status)es$', 'gi' ), '$1' ], + [ new RegExp( '^(ox)en', 'gi' ), '$1' ], + [ new RegExp( '(vert|ind)ices$', 'gi' ), '$1ex' ], + [ new RegExp( '(matr)ices$', 'gi' ), '$1ix' ], + [ new RegExp( '(quiz)zes$', 'gi' ), '$1' ], + [ new RegExp( 'ss$', 'gi' ), 'ss' ], + [ new RegExp( 's$', 'gi' ), '' ] + ]; + + /** + * @description This is a list of words that should not be capitalized for title case. + * @private + */ + var non_titlecased_words = [ + 'and', 'or', 'nor', 'a', 'an', 'the', 'so', 'but', 'to', 'of', 'at','by', + 'from', 'into', 'on', 'onto', 'off', 'out', 'in', 'over', 'with', 'for' + ]; + + /** + * @description These are regular expressions used for converting between String formats. + * @private + */ + var id_suffix = new RegExp( '(_ids|_id)$', 'g' ); + var underbar = new RegExp( '_', 'g' ); + var space_or_underbar = new RegExp( '[\ _]', 'g' ); + var uppercase = new RegExp( '([A-Z])', 'g' ); + var underbar_prefix = new RegExp( '^_' ); + + var inflector = { + + /** + * A helper method that applies rules based replacement to a String. + * @private + * @function + * @param {String} str String to modify and return based on the passed rules. + * @param {Array: [RegExp, String]} rules Regexp to match paired with String to use for replacement + * @param {Array: [String]} skip Strings to skip if they match + * @param {String} override String to return as though this method succeeded (used to conform to APIs) + * @returns {String} Return passed String modified by passed rules. + * @example + * + * this._apply_rules( 'cows', singular_rules ); // === 'cow' + */ + _apply_rules : function( str, rules, skip, override ){ + if( override ){ + str = override; + }else{ + var ignore = ( this.indexOf( skip, str.toLowerCase()) > -1 ); + + if( !ignore ){ + var i = 0; + var j = rules.length; + + for( ; i < j; i++ ){ + if( str.match( rules[ i ][ 0 ])){ + if( rules[ i ][ 1 ] !== undefined ){ + str = str.replace( rules[ i ][ 0 ], rules[ i ][ 1 ]); + } + break; + } + } + } + } + + return str; + }, + + + + /** + * This lets us detect if an Array contains a given element. + * @public + * @function + * @param {Array} arr The subject array. + * @param {Object} item Object to locate in the Array. + * @param {Number} fromIndex Starts checking from this position in the Array.(optional) + * @param {Function} compareFunc Function used to compare Array item vs passed item.(optional) + * @returns {Number} Return index position in the Array of the passed item. + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.indexOf([ 'hi','there' ], 'guys' ); // === -1 + * inflection.indexOf([ 'hi','there' ], 'hi' ); // === 0 + */ + indexOf : function( arr, item, fromIndex, compareFunc ){ + if( !fromIndex ){ + fromIndex = -1; + } + + var index = -1; + var i = fromIndex; + var j = arr.length; + + for( ; i < j; i++ ){ + if( arr[ i ] === item || compareFunc && compareFunc( arr[ i ], item )){ + index = i; + break; + } + } + + return index; + }, + + + + /** + * This function adds pluralization support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @param {String} plural Overrides normal output with said String.(optional) + * @returns {String} Singular English language nouns are returned in plural form. + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.pluralize( 'person' ); // === 'people' + * inflection.pluralize( 'octopus' ); // === "octopi" + * inflection.pluralize( 'Hat' ); // === 'Hats' + * inflection.pluralize( 'person', 'guys' ); // === 'guys' + */ + pluralize : function ( str, plural ){ + return this._apply_rules( str, plural_rules, uncountable_words, plural ); + }, + + + + /** + * This function adds singularization support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @param {String} singular Overrides normal output with said String.(optional) + * @returns {String} Plural English language nouns are returned in singular form. + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.singularize( 'people' ); // === 'person' + * inflection.singularize( 'octopi' ); // === "octopus" + * inflection.singularize( 'Hats' ); // === 'Hat' + * inflection.singularize( 'guys', 'person' ); // === 'person' + */ + singularize : function ( str, singular ){ + return this._apply_rules( str, singular_rules, uncountable_words, singular ); + }, + + + + /** + * This function adds camelization support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @param {Boolean} lowFirstLetter Default is to capitalize the first letter of the results.(optional) + * Passing true will lowercase it. + * @returns {String} Lower case underscored words will be returned in camel case. + * additionally '/' is translated to '::' + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.camelize( 'message_properties' ); // === 'MessageProperties' + * inflection.camelize( 'message_properties', true ); // === 'messageProperties' + */ + camelize : function ( str, lowFirstLetter ){ + var str_path = str.toLowerCase().split( '/' ); + var i = 0; + var j = str_path.length; + + for( ; i < j; i++ ){ + var str_arr = str_path[ i ].split( '_' ); + var initX = (( lowFirstLetter && i + 1 === j ) ? ( 1 ) : ( 0 )); + var k = initX; + var l = str_arr.length; + + for( ; k < l; k++ ){ + str_arr[ k ] = str_arr[ k ].charAt( 0 ).toUpperCase() + str_arr[ k ].substring( 1 ); + } + + str_path[ i ] = str_arr.join( '' ); + } + + return str_path.join( '::' ); + }, + + + + /** + * This function adds underscore support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @param {Boolean} allUpperCase Default is to lowercase and add underscore prefix.(optional) + * Passing true will return as entered. + * @returns {String} Camel cased words are returned as lower cased and underscored. + * additionally '::' is translated to '/'. + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.underscore( 'MessageProperties' ); // === 'message_properties' + * inflection.underscore( 'messageProperties' ); // === 'message_properties' + * inflection.underscore( 'MP', true ); // === 'MP' + */ + underscore : function ( str, allUpperCase ){ + if( allUpperCase && str === str.toUpperCase()) return str; + + var str_path = str.split( '::' ); + var i = 0; + var j = str_path.length; + + for( ; i < j; i++ ){ + str_path[ i ] = str_path[ i ].replace( uppercase, '_$1' ); + str_path[ i ] = str_path[ i ].replace( underbar_prefix, '' ); + } + + return str_path.join( '/' ).toLowerCase(); + }, + + + + /** + * This function adds humanize support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @param {Boolean} lowFirstLetter Default is to capitalize the first letter of the results.(optional) + * Passing true will lowercase it. + * @returns {String} Lower case underscored words will be returned in humanized form. + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.humanize( 'message_properties' ); // === 'Message properties' + * inflection.humanize( 'message_properties', true ); // === 'message properties' + */ + humanize : function( str, lowFirstLetter ){ + str = str.toLowerCase(); + str = str.replace( id_suffix, '' ); + str = str.replace( underbar, ' ' ); + + if( !lowFirstLetter ){ + str = this.capitalize( str ); + } + + return str; + }, + + + + /** + * This function adds capitalization support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @returns {String} All characters will be lower case and the first will be upper. + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.capitalize( 'message_properties' ); // === 'Message_properties' + * inflection.capitalize( 'message properties', true ); // === 'Message properties' + */ + capitalize : function ( str ){ + str = str.toLowerCase(); + + return str.substring( 0, 1 ).toUpperCase() + str.substring( 1 ); + }, + + + + /** + * This function adds dasherization support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @returns {String} Replaces all spaces or underbars with dashes. + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.dasherize( 'message_properties' ); // === 'message-properties' + * inflection.dasherize( 'Message Properties' ); // === 'Message-Properties' + */ + dasherize : function ( str ){ + return str.replace( space_or_underbar, '-' ); + }, + + + + /** + * This function adds titleize support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @returns {String} Capitalizes words as you would for a book title. + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.titleize( 'message_properties' ); // === 'Message Properties' + * inflection.titleize( 'message properties to keep' ); // === 'Message Properties to Keep' + */ + titleize : function ( str ){ + str = str.toLowerCase().replace( underbar, ' '); + var str_arr = str.split(' '); + var i = 0; + var j = str_arr.length; + + for( ; i < j; i++ ){ + var d = str_arr[ i ].split( '-' ); + var k = 0; + var l = d.length; + + for( ; k < l; k++){ + if( this.indexOf( non_titlecased_words, d[ k ].toLowerCase()) < 0 ){ + d[ k ] = this.capitalize( d[ k ]); + } + } + + str_arr[ i ] = d.join( '-' ); + } + + str = str_arr.join( ' ' ); + str = str.substring( 0, 1 ).toUpperCase() + str.substring( 1 ); + + return str; + }, + + + + /** + * This function adds demodulize support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @returns {String} Removes module names leaving only class names.(Ruby style) + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.demodulize( 'Message::Bus::Properties' ); // === 'Properties' + */ + demodulize : function ( str ){ + var str_arr = str.split( '::' ); + + return str_arr[ str_arr.length - 1 ]; + }, + + + + /** + * This function adds tableize support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @returns {String} Return camel cased words into their underscored plural form. + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.tableize( 'MessageBusProperty' ); // === 'message_bus_properties' + */ + tableize : function ( str ){ + str = this.underscore( str ); + str = this.pluralize( str ); + + return str; + }, + + + + /** + * This function adds classification support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @returns {String} Underscored plural nouns become the camel cased singular form. + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.classify( 'message_bus_properties' ); // === 'MessageBusProperty' + */ + classify : function ( str ){ + str = this.camelize( str ); + str = this.singularize( str ); + + return str; + }, + + + + /** + * This function adds foreign key support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @param {Boolean} dropIdUbar Default is to seperate id with an underbar at the end of the class name, + you can pass true to skip it.(optional) + * @returns {String} Underscored plural nouns become the camel cased singular form. + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.foreign_key( 'MessageBusProperty' ); // === 'message_bus_property_id' + * inflection.foreign_key( 'MessageBusProperty', true ); // === 'message_bus_propertyid' + */ + foreign_key : function( str, dropIdUbar ){ + str = this.demodulize( str ); + str = this.underscore( str ) + (( dropIdUbar ) ? ( '' ) : ( '_' )) + 'id'; + + return str; + }, + + + + /** + * This function adds ordinalize support to every String object. + * @public + * @function + * @param {String} str The subject string. + * @returns {String} Return all found numbers their sequence like "22nd". + * @example + * + * var inflection = require( 'inflection' ); + * + * inflection.ordinalize( 'the 1 pitch' ); // === 'the 1st pitch' + */ + ordinalize : function ( str ){ + var str_arr = str.split(' '); + var i = 0; + var j = str_arr.length; + + for( ; i < j; i++ ){ + var k = parseInt( str_arr[ i ], 10 ); + + if( !isNaN( k )){ + var ltd = str_arr[ i ].substring( str_arr[ i ].length - 2 ); + var ld = str_arr[ i ].substring( str_arr[ i ].length - 1 ); + var suf = 'th'; + + if( ltd != '11' && ltd != '12' && ltd != '13' ){ + if( ld === '1' ){ + suf = 'st'; + }else if( ld === '2' ){ + suf = 'nd'; + }else if( ld === '3' ){ + suf = 'rd'; + } + } + + str_arr[ i ] += suf; + } + } + + return str_arr.join( ' ' ); + } + }; + + if( typeof exports === 'undefined' ) return root.inflection = inflector; + +/** + * @public + */ + inflector.version = JSON.parse( + require( 'fs' ).readFileSync( __dirname + '/../package.json', 'utf8' ) + ).version; + +/** + * Exports module. + */ + module.exports = inflector; +})( this ); diff --git a/node_modules/inflection/package.json b/node_modules/inflection/package.json new file mode 100644 index 00000000..ee9479ed --- /dev/null +++ b/node_modules/inflection/package.json @@ -0,0 +1,67 @@ +{ + "name": "inflection", + "version": "1.2.5", + "description": "A port of inflection-js to node.js module", + "keywords": [ + "inflection", + "inflections", + "inflection-js", + "pluralize", + "singularize", + "camelize", + "underscore", + "humanize", + "capitalize", + "dasherize", + "titleize", + "demodulize", + "tableize", + "classify", + "foreign_key", + "ordinalize" + ], + "author": { + "name": "dreamerslab", + "email": "ben@dreamerslab.com" + }, + "contributors": [ + { + "name": "Ryan Schuft", + "email": "ryan.schuft@gmail.com" + }, + { + "name": "Ben Lin", + "email": "ben@dreamerslab.com" + }, + { + "name": "Lance Pollard", + "email": "lancejpollard@gmail.com" + }, + { + "name": "brandondewitt" + } + ], + "dependencies": {}, + "devDependencies": { + "node.flow": "1.2.2", + "should": "1.2.1" + }, + "main": "./lib/inflection.js", + "repository": { + "type": "git", + "url": "https://github.com/dreamerslab/node.inflection.git" + }, + "engines": [ + "node >= 0.4.0" + ], + "licenses": [ + { + "type": "MIT", + "url": "http://en.wikipedia.org/wiki/MIT_License" + } + ], + "readme": "# inflection\n\nA port of inflection-js to node.js module\n\n\n\n## Description\n[inflection-js](http://code.google.com/p/inflection-js/) is a port of the functionality from Ruby on Rails' Active Support Inflection classes into Javascript. `inflection` is a port of `inflection-js` to node.js npm package. Instead of [extending JavaScript native](http://wonko.com/post/extending-javascript-natives) String object like `inflection-js` does, `inflection` separate the methods to a independent package to avoid unexpected behaviors.\n\n\n\n## Requires\n\nCheckout `package.json` for dependencies.\n\n\n\n## Installation\n\nInstall inflection through npm\n\n\tnpm install inflection\n\n\n\n## API\n\n- inflection.indexOf( arr, item, fromIndex, compareFunc );\n- inflection.pluralize( str, plural );\n- inflection.singularize( str, singular );\n- inflection.camelize( str, lowFirstLetter );\n- inflection.underscore( str, allUpperCase );\n- inflection.humanize( str, lowFirstLetter );\n- inflection.capitalize( str );\n- inflection.dasherize( str );\n- inflection.titleize( str );\n- inflection.demodulize( str );\n- inflection.tableize( str );\n- inflection.classify( str );\n- inflection.foreign_key( str, dropIdUbar );\n- inflection.ordinalize( str );\n\n\n\n## Usage\n\n> Require the module before using\n\n\tvar inflection = require( 'inflection' );\n\n\n\n### inflection.indexOf( arr, item, fromIndex, compareFunc );\n\nThis lets us detect if an Array contains a given element.\n\n#### Arguments\n\n> arr\n\n\ttype: Array\n\tdesc: The subject array.\n\n> item\n\n\ttype: Object\n\tdesc: Object to locate in the Array.\n\n> fromIndex\n\n\ttype: Number\n\tdesc: Starts checking from this position in the Array.(optional)\n\n> compareFunc\n\n\ttype: Function\n\tdesc: Function used to compare Array item vs passed item.(optional)\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.indexOf([ 'hi','there' ], 'guys' ); // === -1\n\tinflection.indexOf([ 'hi','there' ], 'hi' ); // === 0\n\n\n\n### inflection.pluralize( str, plural );\n\nThis function adds pluralization support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n> plural\n\n\ttype: String\n\tdesc: Overrides normal output with said String.(optional)\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.pluralize( 'person' ); // === 'people'\n\tinflection.pluralize( 'octopus' ); // === \"octopi\"\n\tinflection.pluralize( 'Hat' ); // === 'Hats'\n\tinflection.pluralize( 'person', 'guys' ); // === 'guys'\n\n\n\n### inflection.singularize( str, singular );\n\nThis function adds singularization support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n> singular\n\n\ttype: String\n\tdesc: Overrides normal output with said String.(optional)\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.singularize( 'people' ); // === 'person'\n\tinflection.singularize( 'octopi' ); // === \"octopus\"\n\tinflection.singularize( 'Hats' ); // === 'Hat'\n\tinflection.singularize( 'guys', 'person' ); // === 'person'\n\n\n\n### inflection.camelize( str, lowFirstLetter );\n\nThis function adds camelization support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n> lowFirstLetter\n\n\ttype: Boolean\n\tdesc: Default is to capitalize the first letter of the results. Passing true will lowercase it. (optional)\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.camelize( 'message_properties' ); // === 'MessageProperties'\n\tinflection.camelize( 'message_properties', true ); // === 'messageProperties'\n\n\n\n### inflection.underscore( str, allUpperCase );\n\nThis function adds underscore support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n> allUpperCase\n\n\ttype: Boolean\n\tdesc: Default is to lowercase and add underscore prefix\n\n\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.underscore( 'MessageProperties' ); // === 'message_properties'\n\tinflection.underscore( 'messageProperties' ); // === 'message_properties'\n\tinflection.underscore( 'MP' ); // === 'm_p'\n\tinflection.underscore( 'MP', true ); // === 'MP'\n\n\n\n### inflection.humanize( str, lowFirstLetter );\n\nThis function adds humanize support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n> lowFirstLetter\n\n\ttype: Boolean\n\tdesc: Default is to capitalize the first letter of the results. Passing true will lowercase it. (optional)\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.humanize( 'message_properties' ); // === 'Message properties'\n\tinflection.humanize( 'message_properties', true ); // === 'message properties'\n\n\n\n### inflection.capitalize( str );\n\nThis function adds capitalization support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.capitalize( 'message_properties' ); // === 'Message_properties'\n\tinflection.capitalize( 'message properties', true ); // === 'Message properties'\n\n\n\n### inflection.dasherize( str );\n\nThis function adds dasherization support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.dasherize( 'message_properties' ); // === 'message-properties'\n\tinflection.dasherize( 'Message Properties' ); // === 'Message-Properties'\n\n\n\n### inflection.titleize( str );\n\nThis function adds titleize support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.titleize( 'message_properties' ); // === 'Message Properties'\n\tinflection.titleize( 'message properties to keep' ); // === 'Message Properties to Keep'\n\n\n\n### inflection.demodulize( str );\n\nThis function adds demodulize support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.demodulize( 'Message::Bus::Properties' ); // === 'Properties'\n\n\n\n### inflection.tableize( str );\n\nThis function adds tableize support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.tableize( 'MessageBusProperty' ); // === 'message_bus_properties'\n\n\n\n### inflection.classify( str );\n\nThis function adds classification support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.classify( 'message_bus_properties' ); // === 'MessageBusProperty'\n\n\n\n### inflection.foreign_key( str, dropIdUbar );\n\nThis function adds foreign key support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n> lowFirstLetter\n\n\ttype: Boolean\n\tdesc: Default is to seperate id with an underbar at the end of the class name, you can pass true to skip it.(optional)\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.foreign_key( 'MessageBusProperty' ); // === 'message_bus_property_id'\n\tinflection.foreign_key( 'MessageBusProperty', true ); // === 'message_bus_propertyid'\n\n\n\n### inflection.ordinalize( str );\n\nThis function adds ordinalize support to every String object.\n\n#### Arguments\n\n> str\n\n\ttype: String\n\tdesc: The subject string.\n\n#### Example code\n\n\tvar inflection = require( 'inflection' );\n\n\tinflection.ordinalize( 'the 1 pitch' ); // === 'the 1st pitch'\n\n\n\n## Credit\n\n- Ryan Schuft \n- Lance Pollard (Browser support)\n- brandondewitt\n\n\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2011 dreamerslab <ben@dreamerslab.com>\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n", + "readmeFilename": "Readme.md", + "_id": "inflection@1.2.5", + "_from": "inflection@" +} diff --git a/node_modules/sl-remoting b/node_modules/sl-remoting new file mode 120000 index 00000000..a69abe37 --- /dev/null +++ b/node_modules/sl-remoting @@ -0,0 +1 @@ +/usr/local/lib/node_modules/sl-remoting \ No newline at end of file