How to use the inflection.transform function in inflection

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 fortunejs / fortune-json-api / lib / index.js View on Github external
}
        output[reservedKeys.primary] = []
        // Set top-level pagination links.
        if (count > limit) {
          let queryLength = 0

          if (query) {
            delete query[pageOffset]
            delete query[pageLimit]
            queryLength = Object.keys(query).length
          }

          const paged = prefix + uriTemplate.fillFromObject({
            query,
            type: inflectType[type] ?
              inflection.transform(type, typeInflections[1]) : type
          })

          Object.assign(output[reservedKeys.links], {
            [reservedKeys.first]: `${paged}${queryLength ? '&' : '?'}` +
              `${encodedOffset}=0` +
              `&${encodeURIComponent(pageLimit)}=${limit}`,
            [reservedKeys.last]: `${paged}${queryLength ? '&' : '?'}` +
              `${encodedOffset}=${Math.floor((count - 1) / limit) * limit}` +
              `&${encodedLimit}=${limit}`
          },
          limit + (offset || 0) < count ? {
            [reservedKeys.next]: `${paged}${queryLength ? '&' : '?'}` +
              `${encodedOffset}=${(Math.floor((offset || 0) / limit) + 1) *
                limit}&${encodedLimit}=${limit}`
          } : null,
          (offset || 0) >= limit ? {
github fortunejs / fortune-json-api / lib / index.js View on Github external
ids: records.map(record => record[keys.primary])
            })
      }
      else if (relatedField)
        output[reservedKeys.primary] =
      recordTypes[originalType][relatedField][keys.isArray] ? [] : null

      // Set related records.
      if (relatedField)
        output[reservedKeys.links] = {
          [reservedKeys.self]: prefix + uriTemplate.fillFromObject({
            type: inflectType[originalType] ?
              inflection.transform(originalType, typeInflections[1]) :
              originalType,
            ids: originalIds,
            relatedField: inflectKeys ? inflection.transform(relatedField,
              [ 'underscore', 'dasherize' ]) : relatedField
          })
        }

      // To show included records, we have to flatten them :(
      if (include) {
        output[reservedKeys.included] = []

        for (const type of Object.keys(include))
          Array.prototype.push.apply(output[reservedKeys.included],
            include[type].map(mapRecord.bind(this, type)))
      }

      if (Object.keys(output).length)
        contextResponse.payload = output
github fortunejs / fortune / lib / serializer / serializers / json_api / index.js View on Github external
type: inflectType ? inflection.pluralize(type) : type,
            ids: records.map(record => record[keys.primary])
          })
    }
    else if (relatedField)
      output[reservedKeys.primary] =
    recordTypes[originalType][relatedField][keys.isArray] ? [] : null

    // Set related records.
    if (relatedField)
      output[reservedKeys.links] = {
        [reservedKeys.self]: prefix + uriTemplate.fillFromObject({
          type: inflectType ?
            inflection.pluralize(originalType) : originalType,
          ids: originalIds,
          relatedField: inflectKeys ? inflection.transform(relatedField,
            [ 'underscore', 'dasherize' ]) : relatedField
        })
      }

    // To show included records, we have to flatten them :(
    if (include) {
      output[reservedKeys.included] = []

      for (let type of Object.keys(include))
        output[reservedKeys.included].push(...include[type]
          .map(mapRecord.bind(this, type)))
    }

    if (Object.keys(output).length)
      response.payload = output
github martijndeh / fire / lib / modules / controllers / router.js View on Github external
function getPath(verb, method, methodName, basePath) {
	// TODO: Maybe this should be more in express-style also so we can re-use it in the client-side?!
	var remotePath = '';

	basePath.forEach(function(_) {
		remotePath += '/' + _;
	});

	var nameWithoutVerb = utils.captureOne(methodName, /^[a-z]+(.*)$/);
	if(nameWithoutVerb && nameWithoutVerb.length) {
		// If the method is a RESTful call, we pluralize the names.
		// If it's not a RESTful call, e.g. a verb-based call (RPCish), we leave the name as-is.
		if(isRESTMethod(methodName)) {
			remotePath += '/' + inflection.transform(nameWithoutVerb, ['tableize', 'dasherize']);
		}
		else {
			remotePath += '/' + inflection.transform(nameWithoutVerb, ['dasherize']).toLowerCase();
		}
	}

	var args = utils.getMethodArgumentNames(method);
	args.forEach(function(arg) {
		if(arg.length && arg[0] == '$') {
			throw new Error('Starting argument names with `$` is no longer neccesary. Please remove the $ in `' + methodName + '` argument `' + arg + '`.');
		}

		remotePath += '/:' + arg;
	});

	// If nothing is specified in the path yet, make sure it's at least /.
github martijndeh / fire / lib / modules / controllers / router.js View on Github external
// TODO: Maybe this should be more in express-style also so we can re-use it in the client-side?!
	var remotePath = '';

	basePath.forEach(function(_) {
		remotePath += '/' + _;
	});

	var nameWithoutVerb = utils.captureOne(methodName, /^[a-z]+(.*)$/);
	if(nameWithoutVerb && nameWithoutVerb.length) {
		// If the method is a RESTful call, we pluralize the names.
		// If it's not a RESTful call, e.g. a verb-based call (RPCish), we leave the name as-is.
		if(isRESTMethod(methodName)) {
			remotePath += '/' + inflection.transform(nameWithoutVerb, ['tableize', 'dasherize']);
		}
		else {
			remotePath += '/' + inflection.transform(nameWithoutVerb, ['dasherize']).toLowerCase();
		}
	}

	var args = utils.getMethodArgumentNames(method);
	args.forEach(function(arg) {
		if(arg.length && arg[0] == '$') {
			throw new Error('Starting argument names with `$` is no longer neccesary. Please remove the $ in `' + methodName + '` argument `' + arg + '`.');
		}

		remotePath += '/:' + arg;
	});

	// If nothing is specified in the path yet, make sure it's at least /.
	if(remotePath.length === 0) {
		remotePath += '/';
	}
github ozum / pg-structure / lib / m2m-relation.js View on Github external
function getNameComplex() {
    let inflectionMethod =
        this.targetTable.name[0].toUpperCase() === this.targetTable.name[0] ? "camelize" : "underscore";
    const separator = inflectionMethod === "camelize" ? "" : "_";
    const tableName = inflection.transform(this.joinTable.name, [inflectionMethod]);
    const fkToRelationName = inflection.transform(
        helper.fkToRelationName(this.targetConstraint.columns.array[0].name),
        ["pluralize", inflectionMethod]
    );
    return tableName + separator + fkToRelationName;
}
github martijndeh / fire / lib / modules / api / index.js View on Github external
Object.keys(propertiesMap).forEach(function(propertyName) {
		var property = propertiesMap[propertyName];

		if(!property.options.isPrivate) {
			properties.push({
				name: property.name,
				resource: inflection.transform(property.name, ['underscore', 'dasherize']).toLowerCase(),
				capitalName: inflection.capitalize(property.name),

				singularName: utils.ucfirst(inflection.singularize(property.name)),
				pluralName: utils.ucfirst(inflection.pluralize(property.name)),

				isManyToMany: property.isManyToMany(),
				isOneToMany: !property.isManyToMany() && !!property.options.hasMany,
				isOneToOne: !!property.options.belongsTo || !!property.options.hasOne,
				hasMany: !!property.options.hasMany,

				throughModelDependencyName: property.options.through ? (property.options.through.getName() + 'Model') : null
			});
		}
	});
github fortunejs / fortune-json-api / lib / index.js View on Github external
'Can only show relationships for one record at a time.')

      if (method !== methods.find) {
        delete contextResponse.payload
        return contextResponse
      }

      const output = {
        [reservedKeys.jsonapi]: jsonapi,
        [reservedKeys.links]: {
          [reservedKeys.self]: prefix + uriTemplate.fillFromObject({
            type: inflectType[originalType] ?
              inflection.transform(originalType, typeInflections[1]) :
              originalType,
            ids: originalIds, relatedField: reservedKeys.relationships,
            relationship: inflectKeys ? inflection.transform(relatedField,
                [ 'underscore', 'dasherize' ]) : relatedField
          }),
          [reservedKeys.related]: prefix + uriTemplate.fillFromObject({
            type: inflectType[originalType] ?
              inflection.transform(originalType, typeInflections[1]) :
              originalType,
            ids: originalIds,
            relatedField: inflectKeys ? inflection.transform(relatedField,
              [ 'underscore', 'dasherize' ]) : relatedField
          })
        }
      }

      const isArray = recordTypes[originalType][relatedField][keys.isArray]
      const identifiers = records.map(record => ({
        [reservedKeys.type]: inflectType[type] ?
github martijndeh / fire / lib / modules / api / index.js View on Github external
throughModelDependencyName: property.options.through ? (property.options.through.getName() + 'Model') : null
			});
		}
	});

	var authenticator = model.models.getAuthenticator();

	return {
		name: model.getName(),
		dependencyName: model.getName() + 'Model',
		authenticatorDependencyName: authenticator ? authenticator.getName() + 'Model' : null,
		authenticatingPropertyName: model.options.authenticatingProperty ? model.options.authenticatingProperty.name : null,
		isAuthenticator: model.isAuthenticator(),
		isPasswordBasedAuthenticator: model.isAuthenticator() && model.options.isPasswordBased,
		isPasswordlessAuthenticator: model.isAuthenticator() && !model.options.isPasswordBased,
		resourceName: inflection.transform(model.getName(), ['tableize', 'dasherize']).toLowerCase(),
		pluralName: inflection.pluralize(model.getName()),
		lowerCaseName: inflection.camelize(model.getName(), true),
		properties: properties
	};
}
github fortunejs / fortune-json-api / lib / index.js View on Github external
[reservedKeys.jsonapi]: jsonapi,
        [reservedKeys.links]: {
          [reservedKeys.self]: prefix + uriTemplate.fillFromObject({
            type: inflectType[originalType] ?
              inflection.transform(originalType, typeInflections[1]) :
              originalType,
            ids: originalIds, relatedField: reservedKeys.relationships,
            relationship: inflectKeys ? inflection.transform(relatedField,
                [ 'underscore', 'dasherize' ]) : relatedField
          }),
          [reservedKeys.related]: prefix + uriTemplate.fillFromObject({
            type: inflectType[originalType] ?
              inflection.transform(originalType, typeInflections[1]) :
              originalType,
            ids: originalIds,
            relatedField: inflectKeys ? inflection.transform(relatedField,
              [ 'underscore', 'dasherize' ]) : relatedField
          })
        }
      }

      const isArray = recordTypes[originalType][relatedField][keys.isArray]
      const identifiers = records.map(record => ({
        [reservedKeys.type]: inflectType[type] ?
          inflection.transform(type, typeInflections[1]) : type,
        [reservedKeys.id]: record[keys.primary].toString()
      }))

      output[reservedKeys.primary] = isArray ? identifiers :
        identifiers.length ? identifiers[0] : null

      contextResponse.payload = output