How to use inflection - 10 common examples

To help you get started, we’ve selected a few inflection examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dreamerslab / coke / lib / cli / generators / public.js View on Github external
dirs.push( 'app/controllers/' + namespace + '/' );
        dirs.push( 'app/views/' + namespace + '/' );
      }

      dirs.push( view_path );
      // start manipulation
      lib.init();
      // check if dir exists, if not creates it
      dirs.forEach( lib.create_dir );

      model = lib.valid_model_name( splited_controller );

      replace.init({
        capital   : model,
        plural    : splited_controller,
        singular  : inflection.singularize( splited_controller ),
        view_path : controller
      });

      var replace_rules = [
        replace.capital,
        replace.plural,
        replace.singular,
        replace.view_path
      ];

      generate_model( args, model, true );
      generate_view( args, controller, splited_controller, model, view_path, replace_rules );
      lib.create_file_by_template( controller_path, 'controllers/scaffold.js', replace_rules );
      generate_route( args, controller, has_namespace, true );
    });
  }
github kieran / barista / lib / resource.js View on Github external
var Resource = exports.Resource = function( base, controller ){

  var controller_slug = inflection.underscore(inflection.pluralize(controller))

  this.routes = []

  // set up the actual routes for the resource
  this.routes.push(
    this.collection_route =
    base.get('/'+controller_slug+'(.:format)', 'GET').to(controller+'.index')
  , base.post('/'+controller_slug+'(.:format)', 'POST').to(controller+'.create')
  , base.get('/'+controller_slug+'/add(.:format)', 'GET').to(controller+'.add')
  , this.member_route =
    base.get('/'+controller_slug+'/:id(.:format)', 'GET').to(controller+'.show')
  , base.get('/'+controller_slug+'/:id/edit(.:format)', 'GET').to(controller+'.edit')
  , base.put('/'+controller_slug+'/:id(.:format)', 'PUT').to(controller+'.update')
  , base.del('/'+controller_slug+'/:id(.:format)', 'DELETE').to(controller+'.destroy')
  )
  this.collection_route.collection = true
github bootstrap-styled / ra-ui / src / components / detail / ShowGuesser.js View on Github external
const inferredElements = getElementsFromRecords(
        [record],
        showFieldTypes
      );
      const inferredChild = new InferredElement(
        showFieldTypes.show,
        null,
        inferredElements
      );

      process.env.NODE_ENV !== 'production' // eslint-disable-line
      // eslint-disable-next-line no-console
      && console.log(
        `Guessed Show:

export const ${inflection.capitalize(
    inflection.singularize(resource)
  )}Show = props => (
    
${inferredChild.getRepresentation()}
    
);`
      );
      this.setState({ inferredChild: inferredChild.getElement() }); // eslint-disable-line
    }
  }
github madhums / node-genem / lib / genem.js View on Github external
'    }',
    '  ))',
    '}'
  ];

  var consumerkey = 'consumerKey';
  var consumersec = 'consumerSecret';
  if (auth === 'facebook' || auth === 'github') {
    consumerkey = 'clientID';
    consumersec = 'clientSecret';
  }

  var authStrategy = [
    '',
    '  // use '+ auth +' strategy',
    '  passport.use(new '+ inflection.capitalize(auth) +'Strategy({',
    '      '+ consumerkey +': config.'+ auth +'.clientID,',
    '      '+ consumersec +': config.'+ auth +'.clientSecret,',
    '      callbackURL: config.'+ auth +'.callbackURL',
    '    },',
    '    function(token, tokenSecret, profile, done) {',
    '      User.findOne({ \''+ auth +'.id\': profile.id }, function (err, user) {',
    '        if (err) { return done(err) }',
    '        if (!user) {',
    '          user = new User({',
    '            name: profile.displayName,',
    '            username: profile.username,',
    '            provider: \''+ auth +'\',',
    '            '+ auth +': profile._json',
    '          })',
    '          user.save(function (err, user) {',
    '            if (err) console.log(err)',
github cesarandreu / quad-blog / scripts / update-posts.js View on Github external
async function updatePosts () {
  console.log('starting update-posts')

  console.log(`reading posts in dir "${dir}"`)
  const postList = await readPosts(dir)
  console.log('finished reading posts')

  console.log(`synchronizing ${postList.length} posts`)
  const {created, destroyed} = await syncPosts(models, postList)
  console.log(`added ${created} ${inflection.inflect('post', created)}`)
  console.log(`deleted ${destroyed} ${inflection.inflect('post', destroyed)}`)

  console.log('finished updating posts')

  try {
    // Destroy all database connections so it finishes faster
    await models.sequelize.connectionManager.pool.destroyAllNow()
  } catch (err) {}
}
github d3estudio / d3-digest / src / collector / bot.js View on Github external
.map(c => c.name);
        var forgottenChannels = slackChannels
            .filter(c => c.is_member)
            .filter(c => settings.channels.indexOf(c.name) == -1)
            .map(c => c.name);
        var validChannels = settings.channels
            .filter(c => unwatchableChannels.indexOf(c) == -1 && forgottenChannels.indexOf(c) == -1);

        this.channels = validChannels;

        if(unwatchableChannels.length > 0) {
            logger.warn('Bot', `Whoa! I'm trying to watch ${inflection.inflect('', unwatchableChannels.length, 'a channel', 'channels')}${inflection.inflect('', unwatchableChannels.length, '', ' in')} which I'm not a member of: ${unwatchableChannels.join(', ')}`);
        }

        if(forgottenChannels.length > 0) {
            logger.warn('Bot', `Hey! I belong to ${inflection.inflect('an', forgottenChannels.length, null, 'some')} unwatched ${inflection.inflect('channel', forgottenChannels.length)}: ${forgottenChannels.join(', ')}`);
        }

        if(validChannels.length === 0) {
            logger.error('Bot', 'Hmm. Looks like I have nothing to watch! Nothing to do! Yay! See you later, alligator.');
            process.exit(1);
            return;
        } else {
            logger.info('Bot', `Okay, I will watch ${inflection.inflect('', validChannels.length, 'this', 'these')} ${inflection.inflect('channel', validChannels.length)}: ${validChannels.join(', ')}`);
        }

        // Defines which message types must be accepted
        this.expectedMessages = ['message', 'reaction_added', 'reaction_removed', 'emoji_changed',
                                'group_joined', 'channel_joined', 'message_deleted'];

        /**
         * Messages which type is defined in this array are checked against the list of watched
github jondot / hygen / src / context.js View on Github external
// @flow
import type { RunnerConfig } from './types'

const inflection = require('inflection')
const changeCase = require('change-case')

// supports kebab-case to KebabCase
inflection.undasherize = str =>
  str
    .split(/[-_]/)
    .map(w => w[0].toUpperCase() + w.slice(1).toLowerCase())
    .join('')

const helpers = {
  capitalize(string) {
    return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()
  },
  inflection,
  changeCase,
}

const doCapitalization = (hsh, [key, value]) => {
  hsh[key] = value
github jondot / hygen / lib / context.js View on Github external
"use strict";

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

const inflection = require('inflection');

const changeCase = require('change-case'); // supports kebab-case to KebabCase


inflection.undasherize = str => str.split(/[-_]/).map(w => w[0].toUpperCase() + w.slice(1).toLowerCase()).join('');

const helpers = {
  capitalize(string) {
    return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
  },

  inflection,
  changeCase
};

const doCapitalization = (hsh, [key, value]) => {
  hsh[key] = value;
  if (localsToCapitalize.includes(key)) hsh[helpers.capitalize(key)] = helpers.capitalize(value);
  return hsh;
};
github strongloop / loopback-datasource-juggler / lib / relation-definition.js View on Github external
if (typeof polymorphic == 'object') {
    selector = polymorphic.selector || polymorphic.as;
  }

  // relationName is eventually used as selector if provided and selector not already defined
  // it ultimately defaults to 'reference'
  selector = selector || relationName || 'reference';

  // make sure polymorphic is an object
  if (typeof polymorphic !== 'object') {
    polymorphic = {};
  }

  polymorphic.selector = selector;
  polymorphic.foreignKey = polymorphic.foreignKey || i8n.camelize(selector + '_id', true); // defaults to {{selector}}Id
  polymorphic.discriminator = polymorphic.discriminator || i8n.camelize(selector + '_type', true); // defaults to {{selectorName}}Type

  return polymorphic;
}
github ozum / sequelize-pg-generator / lib / index.js View on Github external
function getColumnDetails(column) {
    logger.debug('column details are calculated for: %s', column.name());
    var result = filterAttributes({
        source              : 'generator',
        accessorName        : getSpecificConfig(column.table().name(), 'generate.columnAccessorCamelCase') ? inflection.camelize(inflection.underscore(column.name()), true) : column.name(),
        name                : column.name(),
        primaryKey          : column.isPrimaryKey(),
        autoIncrement       : column.isAutoIncrement() && getSpecificConfig(column.table().name(), 'generate.columnAutoIncrement') ? true : undefined,
        allowNull           : column.allowNull(),
        defaultValue        : getSpecificConfig(column.table().name(), 'generate.columnDefault') && column.default() !== null ? clearDefaultValue(column.default()) : undefined,
        unique              : column.unique(),
        comment             : getSpecificConfig(column.table().name(), 'generate.columnDescription') ? column.description() : undefined,
        references          : column.foreignKeyConstraint() ? getModelNameFor(column.foreignKeyConstraint().referencesTable()) : undefined,
        referencesKey       : column.foreignKeyConstraint() ? column.foreignKeyConstraint().foreignKey(0).name() : undefined,
        onUpdate            : column.onUpdate(),
        onDelete            : column.onDelete()
    });

    result.type = sequelizeType(column, getSpecificConfig(column.table().name(), 'generate.dataTypeVariable')); // To prevent type having quotes.
    //result.type = column.sequelizeType(getSpecificConfig(column.table().name(), 'generate.dataTypeVariable')); // To prevent type having quotes.
    return result;