UNPKG

kitsu-core

Version:

Simple, lightweight & framework agnostic JSON:API (de)serialsation components

12 lines (10 loc) 424 B
function splitModel(url, options = {}) { if (!options.pluralModel) options.pluralModel = s => s; if (!options.resourceCase) options.resourceCase = s => s; const urlSegments = url.split('/'); const resourceModel = urlSegments.pop() || ''; urlSegments.push(options.pluralModel(options.resourceCase(resourceModel))); const newUrl = urlSegments.join('/'); return [resourceModel, newUrl]; } export { splitModel };