How to use the ember-inflector.singularize function in ember-inflector

To help you get started, we’ve selected a few ember-inflector 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 funkensturm / ember-local-storage / addon / helpers / import-export.js View on Github external
content.data.forEach((record) => {
      const type = record.type;
      const adapter = store.adapterFor(singularize(type));

      adapter._getIndex(type).forEach((storageKey) => {
        delete get(adapter, '_storage')[storageKey];
      });

      adapter._getIndex(type).reset();

      // unload from store
      store.unloadAll(singularize(type));
    });
  }
github funkensturm / ember-local-storage / addon / helpers / import-export.js View on Github external
const promises = content.data.map((record) => {
    const adapter = store.adapterFor(singularize(record.type));

    // collect types to reload
    reloadTypes.push(singularize(record.type));

    return adapter._handleStorageRequest(null, 'POST', {
      data: {data: record}
    });
  });
github hashicorp / consul / ui / packages / consul-ui / app / services / data-source / protocols / http.js View on Github external
source(src, configuration) {
    const [, , , model] = src.split('/');
    const owner = getOwner(this);
    const route = match(src);
    const find = route.cb(route.params, owner);

    const repo = this[model] || owner.lookup(`service:repository/${singularize(model)}`);
    configuration.createEvent = function(result = {}, configuration) {
      const event = {
        type: 'message',
        data: result,
      };
      const meta = get(event, 'data.meta') || {};
      if (typeof meta.range === 'undefined') {
        repo.reconcile(meta);
      }
      return event;
    };
    return this.type.source(find, configuration);
  }
}
github CenterForOpenScience / ember-osf-web / mirage / views / osf-resource.ts View on Github external
export function osfNestedResource(
    server: Server,
    parentModelName: K,
    relationshipName: string & RelationshipsFor,
    options?: Partial,
) {
    const opts: NestedResourceOptions = Object.assign({
        path: `/${pluralize(underscore(parentModelName))}/:parentID/${underscore(relationshipName)}`,
        relatedModelName: singularize(relationshipName),
        defaultSortKey: '-id',
    }, options);
    const mirageParentModelName = pluralize(camelize(parentModelName));
    const mirageRelatedModelName = pluralize(camelize(opts.relatedModelName));
    const detailPath = `${opts.path}/:id`;
    const actions = gatherResourceActions(opts);

    if (actions.includes('index')) {
        server.get(opts.path, function(schema, request) {
            const data = schema[mirageParentModelName]
                .find(request.params.parentID)[relationshipName]
                .models
                .filter((m: ModelInstance) => filter(m, request))
                .map((model: ModelInstance) => this.serialize(model).data);
            return process(schema, request, this, data, opts);
        });
github ilios / frontend / app / services / reporting.js View on Github external
getQuery(subject, object, objectId, school){
    const query = {
      filters: {}
    };

    if(object && objectId){
      let what = pluralize(object.camelize());
      if(object === 'mesh term'){
        what = 'meshDescriptors';
      }

      if(subject === 'session'){
        const sessionSingulars = ['sessionTypes', 'courses'];
        if(sessionSingulars.includes(what)){
          what = singularize(what);
        }
      }
      if(subject === 'instructor'){
        const specialInstructed = ['learningMaterials', 'sessionTypes', 'courses', 'sessions'];
        if(specialInstructed.includes(what)){
          what = 'instructed' + what.capitalize();
        }
      }
      if(subject === 'learning material' && object === 'course'){
        what = 'fullCourses';
      }
      query.filters[what] = objectId;
    } else {
      if(subject !== 'mesh term' && subject !== 'instructor' && subject !== 'learning material' && school){
        query.filters['schools'] = [school.id];
      }
github CenterForOpenScience / ember-osf-web / mirage / views / osf-resource.ts View on Github external
server.patch(opts.path, (schema: Schema, request: Request) => {
            const { parentID } = request.params;
            const parentModel = schema[mirageParentModelName].find(parentID);
            const { data: relatedRefs } = JSON.parse(request.requestBody) as {
                data: Array>,
            };
            const relatedIdsKey = `${singularize(relationshipName)}Ids`;

            parentModel.update({
                [relatedIdsKey]: relatedRefs.mapBy('id'),
            });

            return { data: relatedRefs };
        });
    }
github CenterForOpenScience / ember-osf / addon / adapters / osf-adapter.js View on Github external
return this._doRelatedRequest(store, snapshot, updatedSnapshots, relationship, url, 'PATCH', isBulk).then(res => {
            var relatedType = singularize(snapshot.record[relationship].meta().type);
            res.data.forEach(item => {
                var record = store.push(store.normalize(relatedType, item));
                snapshot.record.resolveRelationship(relationship).addCanonicalRecord(record._internalModel);
            });
            return res;
        });
    },
github cardstack / cardstack / packages / search / addon / components / cardstack-search.js View on Github external
return A(rawPayload.data.map(model => {
    let ModelClass = store.modelFor(singularize(model.type));

    let jsonApiPayload = serializer.normalizeResponse(store, ModelClass, Object.assign({}, rawPayload, {
      data: model
    }), null, 'query');

    return store.push(jsonApiPayload);
  }));
}
github linkedin / WhereHows / datahub-web / @datahub / lists / addon / components / entity-list-container.ts View on Github external
get name(): string {
    const { entity } = this;
    return entity ? singularize(entity.displayName) : '';
  }
github CenterForOpenScience / ember-osf-web / app / models / guid.ts View on Github external
get referentType() {
        const { relationships } = this.links;
        if (relationships &&
            'data' in relationships.referent &&
            relationships.referent.data &&
            'type' in relationships.referent.data) {
            return singularize(relationships.referent.data.type) as ReferentModelName;
        }
        return undefined;
    }

ember-inflector

The default blueprint for Embroider v2 addons.

MIT
Latest version published 29 days ago

Package Health Score

78 / 100
Full package analysis