Skip to content

Instantly share code, notes, and snippets.

@gmbarroso
Created November 18, 2021 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmbarroso/c031023f66d1373ca7cba22baf94a343 to your computer and use it in GitHub Desktop.
Save gmbarroso/c031023f66d1373ca7cba22baf94a343 to your computer and use it in GitHub Desktop.
const url = "https://raiadrogasil.myvtex.com/checkout/cart/add/?sku=70288&qty=1&seller=1&sc=1?sku=12345&qty=1&seller=1&sc=1?sku=10253&qty=1&seller=1&sc=1"
let items = []
const parameters = url.match(/\A?sku=[^&]+&\A?qty=[^&]+&*\A?seller=[^&]+&*/g)
console.log(parameters)
simulation = parameters.map(value => {
let obj = {
"id": value.match(/([\d]+)/g)[0],
"quantity": value.match(/([\d]+)/g)[1],
"seller": "1"
}
return obj
})
console.log(JSON.stringify(simulation))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment