UNPKG

@web3r/flowerkit

Version:

A collection of more than 60 often used utility JS functions that simplify frontend development.

14 lines (13 loc) 676 B
import ow from"ow";import{getDocument}from"ssr-window"; /** * Gets the Cookie value * @param name{String} - name of Cookie * @return {string|undefined} * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie * @example * // How to get value of Cookie? * setCookie("myCookieName", "myValue"); * const savedValue = getCookie("myCookieName"); * console.log(savedValue); // => "myValue" */const getCookie=name=>{ow(name,ow.string);const matches=getDocument().cookie.match(new RegExp("(?:^|; )"+name.replace(/([$?*|{}\]\\^])/g,"\\$1")+"=([^;]*)"));return matches?decodeURIComponent(matches[1]):void 0};export{getCookie}; //# sourceMappingURL=index.js.map