UNPKG

@swell/cli

Version:

Swell's command line interface/utility

27 lines (26 loc) 1.38 kB
import { dasherize, pluralize, titleize, underscore } from 'inflection'; // Example: 'My Thing' => 'my-thing' const toFileName = (value) => dasherize(underscore(value.split('.')[0].replace(' ', '_'))).toLowerCase(); // Example: 'my-things' => 'My Things' const toAppName = (value) => titleize(value) .replaceAll(/[_\s-:./-]+/g, ' ') .replaceAll(/([a-z])([A-Z])/g, '$1 $2') .replaceAll(/(\d)([a-z])/gi, '$1 $2') .replaceAll(/([a-z])(\d)/gi, '$1 $2'); // Example: 'My App' => 'my_app' const toAppId = (value) => String(value || '') .replaceAll(/[^\s\w./:-]/g, '') .replaceAll(/[_\s-:./]+/g, '_') .replaceAll(/^_+|_+$/g, '') .replaceAll(/([a-z])([A-Z])/g, '$1_$2') .toLowerCase(); // Example: 'My Thing' => 'my-thing' // And: 'myThing' => 'myThing' const toFunctionFileName = (value) => value.split('.')[0].replace(' ', '-'); // Example: 'My Thing' => 'my-things' const toCollectionName = (value) => pluralize(value.replaceAll(/[^A-Za-z]/g, '-').replace(' ', '')).toLowerCase(); // Example: 'my-things' => 'My Things' const toCollectionLabel = (value) => pluralize(titleize(value).replace('-', ' ')); // Example: 'order-receipt' => 'Order Receipt' const toNotificationLabel = (value) => titleize(value).replace('-', ' '); export { toAppId, toAppName, toCollectionLabel, toCollectionName, toFileName, toFunctionFileName, toNotificationLabel, };