UNPKG

kitsu-core

Version:

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

14 lines (11 loc) 449 B
'use strict'; 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]; } exports.splitModel = splitModel;