/** * @Method: Returns the Plural form of any noun. * @Param {string} * @Return {string} */ export function getPlural (str: any) : string { return pluralize.plural(str) }
const resolveName = (name) => { const plural = pluralize.plural(path.basename(name, '.js')); const serviceName = `${capitalize(plural)}Service`; debug(`resolve service name: ${serviceName}`); return serviceName; }
Object.keys(queries).forEach(type => { // The query cannot be built. if (_.isError(queries[type])) { strapi.log.error(queries[type]); strapi.stop(); } // Only create query if the function is available. if (_.isFunction(queries[type])) { if (type === 'singular') { Object.assign(acc.query, { [`${pluralize.singular(name)}(id: ID!)`]: model.globalId, }); } else { Object.assign(acc.query, { [`${pluralize.plural( name, )}(sort: String, limit: Int, start: Int, where: JSON)`]: `[${ model.globalId }]`, }); } _.merge(acc.resolver.Query, { [type === 'singular' ? pluralize.singular(name) : pluralize.plural(name)]: queries[type], }); } });
// Returns document ids that have unsatisfied relations // Example: a comment that references a post that doesn't exist function getRemovable(db, opts) { const _ = this const removable = [] _.each(db, (coll, collName) => { _.each(coll, doc => { _.each(doc, (value, key) => { if (new RegExp(`${opts.foreignKeySuffix}$`).test(key)) { // Remove foreign key suffix and pluralize it // Example postId -> posts const refName = pluralize.plural( key.replace(new RegExp(`${opts.foreignKeySuffix}$`), '') ) // Test if table exists if (db[refName]) { // Test if references is defined in table const ref = _.getById(db[refName], value) if (_.isUndefined(ref)) { removable.push({ name: collName, id: doc.id }) } } } }) }) }) return removable }
pluralizedName = pluralize.plural(opts.name), router = this;
const nameCameCaseUpperFirst = nameCameCase.replace(/^(.)/, nameCameCase[0].toLocaleUpperCase()); const pluralized = plural(nameCameCaseUpperFirst); const nameSnakeCase = snakeCase(pluralized); const unix = new Date()
const resolveName = (name) => { const plural = pluralize.plural(path.basename(name, '.js')); const controllerName = `${capitalize(plural)}Controller`; debug(`resolve controller name: ${controllerName}`); return controllerName; }