Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { dasherize, camelize, capitalize, classify, decamelize, loc, underscore, w } from '@ember/string';
dasherize(); // $ExpectError
dasherize('blue man group'); // $ExpectType string
dasherize('', ''); // $ExpectError
camelize(); // $ExpectError
camelize('blue man group'); // $ExpectType string
camelize('', ''); // $ExpectError
decamelize(); // $ExpectError
decamelize('blue man group'); // $ExpectType string
decamelize('', ''); // $ExpectError
underscore(); // $ExpectError
underscore('blue man group'); // $ExpectType string
underscore('', ''); // $ExpectError
w(); // $ExpectError
w('blue man group'); // $ExpectType string[]
w('', ''); // $ExpectError
classify(); // $ExpectError
classify('blue man group'); // $ExpectType string
classify('', ''); // $ExpectError
capitalize(); // $ExpectError
capitalize('blue man group'); // $ExpectType string
capitalize('', ''); // $ExpectError
loc(); // $ExpectError
loc("_Hello World"); // $ExpectType string
async modifyM2MRelationship(
this: T,
action: 'post' | 'delete',
relationshipName: RelationshipsFor & string,
relatedModel: OsfModel,
) {
const apiRelationshipName = underscore(relationshipName);
const url = getSelfHref(this.relationshipLinks[apiRelationshipName]);
const data = JSON.stringify({
data: [{
id: relatedModel.id,
type: relatedModel.apiType,
}],
});
if (!url) {
throw new Error(`Couldn't find self link for ${apiRelationshipName} relationship`);
}
assert(`The related object is required to ${action} a relationship`, Boolean(relatedModel));
const options: JQuery.AjaxSettings = {
url,
keyForRelationship(key, typeClass, method) {
if (method === 'serialize') {
return underscore(key);
}
return `${underscore(key)}_id`;
}
});
keyForAttribute(attr) {
return underscore(attr);
}
});
keyForAttribute(key) {
return underscore(key);
},
return ajax(url).then(result => {
const typeName = underscore(this.pluralize(adapter.apiNameFor(type)));
const content = result[typeName].map(obj =>
this._hydrate(type, obj, result)
);
resultSet.set("content", content);
});
},
export function osfToManyRelationship(
server: Server,
parentModelName: K,
relationshipName: string & RelationshipsFor,
options?: Partial,
) {
const opts: RelationshipOptions = Object.assign({
path: `/${pluralize(underscore(parentModelName))}/:parentID/relationships/${underscore(relationshipName)}`,
relatedModelName: relationshipName,
defaultSortKey: '-id',
}, options);
const mirageParentModelName = pluralize(camelize(parentModelName));
const actions = gatherRelationshipActions(opts);
if (actions.includes('related')) {
const relationshipRelatedPath = opts.path.replace('relationships/', '');
server.get(relationshipRelatedPath, 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, { defaultSortKey: opts.defaultSortKey });
});
pathForType: function(type) {
var plural = pluralize(type);
return underscore(plural);
},
keyForAttribute(attr) {
return underscore(attr);
}
}
get apiType() {
return pluralize(underscore(this.modelName));
}