How to use the pluralize.singular function in pluralize

To help you get started, we’ve selected a few pluralize 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 nicoespeon / abracadabra / src / refactorings / convert-for-to-foreach / convert-for-to-foreach.ts View on Github external
createVisitor(selection, (path, accessor, list) => {
      const { body } = path.node;

      const item = t.identifier(singular(getListName(list)));
      const forEachBody = t.isBlockStatement(body)
        ? body
        : t.blockStatement([body]);

      replaceListWithItemIn(forEachBody, list, accessor, item, path.scope);

      // After we replaced, we check if there are remaining accessors.
      const params = isAccessorReferencedIn(forEachBody, accessor)
        ? [item, accessor]
        : [item];

      path.replaceWith(t.forEach(list, params, forEachBody));
    })
  );
github strapi / strapi / packages / strapi-bookshelf / lib / index.js View on Github external
case 'belongsTo':
                loadedModel[name] = function () {
                  return this.belongsTo(global[_.capitalize(details.model)], name);
                };
                break;

              case 'belongsToMany':
                const tableName = _.map(_.sortBy([strapi.models[details.collection].attributes[details.via], details], 'collection'), function (table) {
                  return _.snakeCase(pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via));
                }).join('__');

                const relationship = _.clone(strapi.models[details.collection].attributes[details.via]);

                // Force singular foreign key
                relationship.attribute = pluralize.singular(relationship.collection);
                details.attribute = pluralize.singular(details.collection);

                // Define PK column
                details.column = utils.getPK(model, strapi.models);
                relationship.column = utils.getPK(details.collection, strapi.models);

                // Sometimes the many-to-many relationships
                // is on the same keys on the same models (ex: `friends` key in model `User`)
                if (details.attribute + '_' + details.column === relationship.attribute + '_' + relationship.column) {
                  relationship.attribute = pluralize.singular(details.via);
                }

                loadedModel[name] = function () {
                  return this.belongsToMany(global[_.capitalize(details.collection)], tableName, relationship.attribute + '_' + relationship.column, details.attribute + '_' + details.column);
                };
                break;
github duyluonglc / lucid-mongo / lib / util.js View on Github external
util.makePivotCollectionName = function (modelName, relatedModelName, camelCase = false) {
  modelName = _.camelCase(pluralize.singular(modelName))
  relatedModelName = camelCase
    ? _.upperFirst(_.camelCase(pluralize.singular(relatedModelName)))
    : _.snakeCase(pluralize.singular(relatedModelName))
  return _.sortBy([modelName, relatedModelName]).join(camelCase ? '' : '_')
}
github garbin / koapi / lib / graphql / helper.js View on Github external
return async (root, args, ctx, info) => {
      const {
        getLoader = ctx => ctx.loader,
        parent = root.constructor,
        foreignKey = `${pluralize.singular(root.constructor.prototype.tableName)}_id`,
        mappingKey = pluralize.singular(root.constructor.prototype.tableName),
        list = true,
        model
      } = options
      const loader = getLoader(ctx)
      const data = await loader.acquire(`${parent.name}-${model.name}`, parents => {
        if (list) {
          return model.forge().query(q => q.whereIn(foreignKey, parents.map(parent => parent.id)))
            .fetchAll().then(items => parents.map(parent => items.filter(item => {
              if (item.get(foreignKey) === parent.id) {
                item[mappingKey] = item
                return true
              }
              return false
            })))
        } else {
github generaptr / generaptr / src / utils / text.ts View on Github external
export const toTitleCase: (word: string) => string = (word: string): string =>
  pluralize.singular(word.charAt(0).toUpperCase() + word.substring(1));
github HeskeyBaozi / umi-plugin-mobx / lib / index.js View on Github external
function transformWord(word, toSingular) {
    if (pluralize.isPlural(word)) {
        return toSingular ? pluralize.singular(word) : word;
    }
    else {
        return toSingular ? word : pluralize.plural(word);
    }
}
function optsToArray(item) {
github fega / mongo-server / lib / index.js View on Github external
const getPopulatePipeline = ($populate, resource, config, request) => {
  const prePopulate1 = `____${$populate}`;
  const prePopulate2 = `__${$populate}`;
  
  const foreignField = `${pluralize.singular(resource)}_id`

  const lookupPipeline1 = config
    ? { 
      pipeline: getLookupPipeline(config, foreignField, request), 
      let: {[foreignField]: `$_id`} }
    : false
  const lookupPipeline2 = config
    ? { 
      pipeline: getLookupPipeline(config, foreignField+'s', request), 
      let: {[foreignField+'s']: `$_id`} }
    : false

  const fields1 = { localField: '_id', foreignField };
  const fields2 = { localField: '_id', foreignField: foreignField+'s' };

  const pipeline = [
github Canner / canner / packages / canner-graphql-interface / src / utils.ts View on Github external
return mapValues(schema, item => {
    if (item && item.items) {
      item.items = createSchemaForResolver(item.items);
      return item;
    }

    if (item && item.relation) {
      item.relation.typename = capitalizeFirstLetter(pluralize.singular(item.relation.to));
    }
    return item;
  });
};
github zhangkaiyulw / scaffold-kit / executor / pushInstruction.js View on Github external
const toSingularInstName = (name) => {
  const specialCommandNames = { 'keepDirectoriesInGit': 'keepDirectoryInGit' };
  return specialCommandNames[name] || singular(name);
};
github resource-watch / resource-watch / layout / admin / data-detail / component.js View on Github external
getName() {
    const { query: { tab, id } } = this.props;
    const { data } = this.state;

    if (id === 'new') return `New ${singular(tab)}`;
    if (data && data.name) return data.name;

    return '-';
  }