voltace / browser-cookies

Tiny cookies library for the browser
The Unlicense
89 stars 18 forks source link

Unable to write Object/boolean #17

Closed dawsbot closed 6 years ago

dawsbot commented 6 years ago

It looks like this strictly allows strings as the "value", is this true? That should be documented somewhere, it's misleading.

browserCookies.set('hi', false)
VM98:1 Uncaught TypeError: n.replace is not a function
    at Object.o.set (<anonymous>:1:1215)
    at <anonymous>:1:16
o.set @ VM98:1
(anonymous) @ VM117:1
browserCookies.set('bye', {test: 'failure'})
VM98:1 Uncaught TypeError: n.replace is not a function
    at Object.o.set (<anonymous>:1:1215)
    at <anonymous>:1:16

Test by pasting this page content directly in your browser console: https://wzrd.in/standalone/browser-cookies@latest

voltace commented 6 years ago

Correct, browser-cookies only allows a string as cookie value. The API description for cookies.set() currently has the following description:

argument type description
value string The value to save, percent encoding will automatically be applied.

I'm proposing to extend the description to explicitly mention only strings are allowed as a value. As for the JSON example in your comment the examples section shows how to save JSON data, I can also refer to this example in the API documentation.

dawsbot commented 6 years ago

Thanks for the info, this makes sense. We ended up relying on js-cookie, it's a similar bundle size, and heavily used/tested.