JAVASCRIPT   98

argsToParams.js

Guest on 29th July 2021 03:16:19 PM

  1. import { error } from '../utils/utils.js'
  2.  
  3. export const argsToParams = (args) => {
  4.   const params = {}
  5.   switch (typeof args[0]) {
  6.     case 'object':
  7.       Object.assign(params, args[0])
  8.       break
  9.  
  10.     default:
  11.       ['title', 'html', 'type'].forEach((name, index) => {
  12.         switch (typeof args[index]) {
  13.           case 'string':
  14.             params[name] = args[index]
  15.             break
  16.           case 'undefined':
  17.             break
  18.           default:
  19.             error(`Unexpected type of ${name}! Expected "string", got ${typeof args[index]}`)
  20.         }
  21.       })
  22.   }
  23.   return params
  24. }

Raw Paste


Login or Register to edit or fork this paste. It's free.