Skip to content

Commit

Permalink
Refactor format function: use destructuring, template literals, and f…
Browse files Browse the repository at this point in the history
…or...of loop
  • Loading branch information
Ayoub-Mabrouk committed Nov 11, 2024
1 parent 4b4684a commit 905a8ce
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,29 +224,25 @@ function createparams (filename, fallback) {
*/

function format (obj) {
var parameters = obj.parameters
var type = obj.type
const { parameters, type } = obj

if (!type || typeof type !== 'string' || !TOKEN_REGEXP.test(type)) {
throw new TypeError('invalid type')
}

// start with normalized type
var string = String(type).toLowerCase()
let string = String(type).toLowerCase()

// append parameters
if (parameters && typeof parameters === 'object') {
var param
var params = Object.keys(parameters).sort()
const params = Object.keys(parameters).sort()

for (var i = 0; i < params.length; i++) {
param = params[i]

var val = param.slice(-1) === '*'
for (const param of params) {
const val = param.slice(-1) === '*'
? ustring(parameters[param])
: qstring(parameters[param])

string += '; ' + param + '=' + val
string += `; ${param}=${val}`
}
}

Expand Down

0 comments on commit 905a8ce

Please sign in to comment.