UNPKG

@justgage/reason-cookie

Version:

a simple way to use cross-browser cookies that contain JSON.

86 lines (64 loc) 3.65 kB
<!doctype html> <meta charset=utf8> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel=stylesheet href='./styles.css'> <script defer src='./script.js'></script> <title>Home</title> <body> <script>window.relativeToRoot="."</script> <div id='error-message'> ⚠️ Oops! This page doesn't appear to define a <span>type</span> called <code>_</code>. </div> <div class='container'> <div class='sidebar-wrapper'> <div class='sidebar-expander'>Show navigation</div> <div class='sidebar'> <a href="./search.html" style="display: block; padding: 0 8px;">Search</a> <div class='docs-listing'><a href="./index.html">Home</a></div> <div class='table-of-contents'> <div class='toc-header'>Page Contents</div> <a href="#reasoncookie" class='level-1 header'>ReasonCookie</a> <a href="#is-it-ready-for-prime-time-" class='level-1 header'>Is it ready for prime time?</a> <a href="#install" class='level-1 header'>Install</a> <a href="#api" class='level-1 header'>API</a> <a href="#working-with-string-values" class='level-3 header'>Working with string values</a> <a href="#working-json" class='level-3 header'>working JSON</a> <a href="#set-path-expiry" class='level-3 header'>set path/expiry</a> </div> <div class='project-listing'><div class='project-title'>Package modules</div><a href="./api/CookieTest-JustgageReasonCookie.html">CookieTest-JustgageReasonCookie</a> <a href="./api/JustgageReasonCookie.html">JustgageReasonCookie</a> <a href="./api/Cookie-JustgageReasonCookie.html">Cookie-JustgageReasonCookie</a> <a href="./api/Example-JustgageReasonCookie.html">Example-JustgageReasonCookie</a></div> </div> </div> <div class='main'> <a href="#reasoncookie" id="reasoncookie"><h1>ReasonCookie</h1></a> <p>a simple way to use cross-browser cookies that contain JSON.</p> <p>Note this wrapps <a href="https://github.com/js-cookie/js-cookie" target="_blank" rel="noopener nofollow" title="" class="external-link">js-cookie</a></p> <a href="#is-it-ready-for-prime-time-" id="is-it-ready-for-prime-time-"><h1>Is it ready for prime time?</h1></a> <p>I use it on my side project. The library that&#39;s wrapped is pretty battle tested.</p> <a href="#install" id="install"><h1>Install</h1></a> <pre><code>npm install --save @justgage/reason-cookie</code></pre> <p>Then in your <code>bsconfig.json</code>.</p> <pre><code> &quot;bs-dependencies&quot;: [&quot;@justgage/reason-cookie&quot;],</code></pre> <a href="#api" id="api"><h1>API</h1></a> <a href="#working-with-string-values" id="working-with-string-values"><h3>Working with string values</h3></a> <pre class='reason'><code class='reason'>Cookie.getAsString(&quot;hello&quot;) /* None */ Cookie.setString(&quot;hello&quot;, &quot;test&quot;); Cookie.getAsString(&quot;hello&quot;) /* Some(&quot;test&quot;) */</code></pre> <a href="#working-json" id="working-json"><h3>working JSON</h3></a> <pre class='reason'><code class='reason'>let obj = Js.Dict.empty(); Js.Dict.set(obj, &quot;a&quot;, Js.Json.number(2.)); let obj = Js.Json.object_(obj); Cookie.setJson(&quot;hello&quot;, obj); let maybeCookie = Cookie.getAsJson(&quot;hello&quot;);</code></pre> <a href="#set-path-expiry" id="set-path-expiry"><h3>set path/expiry</h3></a> <ul><li><strong>expires</strong>: number of days</li><li><strong>path</strong>: where this is valid for</li></ul> <pre class='reason'><code class='reason'>Cookie.setJsonConfig( &quot;hello&quot;, obj, Cookie.makeConfig(~path=&quot;&quot;, ~expires=2, ()), );</code></pre> </div> <div class='right-blank'></div> </div>