model-name-to-model-key.js 488 B

1234567891011121314151617
  1. import {InvalidArgumentError} from '../errors/index.js';
  2. /**
  3. * Model name to model key.
  4. *
  5. * @param {string} modelName
  6. * @returns {string}
  7. */
  8. export function modelNameToModelKey(modelName) {
  9. if (!modelName || typeof modelName !== 'string' || /\s/.test(modelName))
  10. throw new InvalidArgumentError(
  11. 'The model name should be a non-empty String ' +
  12. 'without spaces, but %v was given.',
  13. modelName,
  14. );
  15. return modelName.toLowerCase().replace(/[-_]/g, '');
  16. }