#595·js-cookie

Cookie name with brackets

Author: seahindenizCreated Feb 7, 2020Updated Apr 25, 2024
Labelsfeature request

Is your feature request related to a problem? Please describe. Because of escaping characters on the key, I can't able to add brackets in key without having escaped characters. https://github.com/js-cookie/js-cookie/blob/b1d83a073525e00f87d8b4effa4804b8cb741f12/src/api.mjs#L21-L23

Describe the solution you'd like I'm suggesting to have a additional way to override the key replacers same as with the value. https://github.com/js-cookie/js-cookie/blob/b1d83a073525e00f87d8b4effa4804b8cb741f12/README.md#L308-L312

to have something like this definition

javascript
Cookies.withConverter({
  write: function (value, name) {
    return String(value).toUpperCase()
  }
})

and in additional, this definition to have an overloaded return type to keep both definition exist.

javascript
Cookies.withConverter({
  write: function(value, key) {
    return {
      key: String(key),
      value: String(value).toUpperCase()
    }
  }
})

Describe alternatives you've considered Passing additional optional parameter to disable escapers.

javascript
Cookies.set('name', 'value', {
  unescapedName: true,
  unescapedValue: true,
  //...
});

Additional context I know this solution can expect this this answer https://github.com/js-cookie/js-cookie/issues/590#issuecomment-575628332 . I'm only suggesting to have an optional way to avoid complying to standards.

Such as this https://github.com/js-cookie/js-cookie/blob/b1d83a073525e00f87d8b4effa4804b8cb741f12/src/rfc6265.mjs#L5-L10