Necesito Programar Más

    rescript-cookie

    1.0.1 • Public • Published

    rescript-cookie


    ReScript Bindings for Cookie, basic cookie parser and serializer.

    Installation

    1. Install package from npm:

      npm install --save rescript-cookie
      

      or

      yarn add rescript-cookie
      
    2. Add rescript-url to bs-dependencies section of bsconfig.json:

      "bs-dependencies": [
       "rescript-cookie"
       ]
      

    Usage

    Parse

    open Cookie
    
    let cookie = parse(~str="foo=bar", ())
    cookie // {"foo": "bar"}
    
    // with spaces
    let cookie = parse(~str="foo =         123; baz   =       228;", ())
    cookie // {"foo": 123, "baz": 228}
    
    // custom decoder
    let cookie = parse(~str="foo=bar", ~options={decode: Some(str => str ++ str)} ())
    cookie // {"foo": "barbar"}

    Serialize

    open Cookie
    
    let cookie = serialize(~name="foo", ~value="bar", ())
    cookie // "foo=bar"
    
    // secure option
    let cookie = serialize(~name="foo", ~value="bar", ~secure=Some(true), ())
    cookie // "foo=bar; Secure"
    
    // domain option
    let cookie = serialize(~name="foo", ~value="bar", ~secure=Some(true), ~domain=Some("example.com"), ())
    cookie // "foo=bar; Secure; Domain=example.com"
    
    // sameSite option
    let cookie = serialize(~name="foo", ~value="bar", ~sameSite=Some("Strict"), ())
    cookie // "foo=bar; SameSite=Strict"

    More usage examples

    Install

    npm i rescript-cookie

    DownloadsWeekly Downloads

    2

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    6.44 kB

    Total Files

    6

    Last publish

    Collaborators

    • glebskr