UNPKG

@swell/cli

Version:

Swell's command line interface/utility

26 lines (25 loc) 1.3 kB
import { dasherize, pluralize, titleize, underscore } from 'inflection'; // Example: 'My Thing' => 'my-thing' export const toFileName = (value) => dasherize(underscore(value.split('.')[0].replace(' ', '_'))).toLowerCase(); // Example: 'my-things' => 'My Things' export 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' export 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' export const toFunctionFileName = (value) => value.split('.')[0].replace(' ', '-'); // Example: 'My Thing' => 'my-things' export const toCollectionName = (value) => pluralize(value.replaceAll(/[^A-Za-z]/g, '-').replace(' ', '')).toLowerCase(); // Example: 'my-things' => 'My Things' export const toCollectionLabel = (value) => pluralize(titleize(value).replace('-', ' ')); // Example: 'order-receipt' => 'Order Receipt' export const toNotificationLabel = (value) => titleize(value).replace('-', ' ');