
Product
Introducing Pull Request Stories to Help Security Teams Track Supply Chain Risks
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
CoCookie is a minimalistic accurate JavaScript ES6 package that provides a convenient interface to work with cookies.
The API is as simple as possible. The documented code is clean and transparent. See the usage in examples below.
import cookie from "cocookie";
// Set cookie "key" to value "bR6o1x"
cookie("key").set("bR6o1x");
// Set cookie "key" to value "bR6o1x" with additional attributes
cookie("key").set("bR6o1x", {
domain: "my.domain.com", // domain to bind cookie to
expires: new Date(Date.now() + 1000*60*60*24*7), // date when cookie expires
maxAge: 60*60*24, // max time in seconds the cookie lives
path: "/", // the URL path the cookie will be bind to
secure: true // restrict cookie transport to HTTPS only
});
// Get value of cookie "key"
let key = cookie("key").get();
// Delete cookie "key"
cookie("key").delete();
// When cookie is already set, you can just update its without touching its value.
cookie("key").update({
expires: new Date(Date.now() + 1000*60*60*24*7) // refresh the cookie for 1 more week
});
// Delete cookie "key" with optional attributes
cookie("key").delete({
domain: "my.domain.com",
path: "/"
});
// Need the list of cookies to iterate through? Here you go:
import { cookies } from "cocookie";
cookies().forEach(name => cookie(name).delete());
// Note that you cannot delete cookies from other domains/paths in this way.
// Do delete the cookie from known path/domain use delete attributes (see delete above).
// If you need to store JSON in cookies (which is not common), use the following pattern.
cookie("key").set(JSON.stringify({ base: "bR6o1x", salt: "j5p9Qz" }));
let object = JSON.stringify(cookie("key").get());
npm install --save-dev cocookie
Install CoCookie as a npm dependency. Use this package with any module bundler like Webpack until ES6 modules standard will be implemented natively.
If your module bundler cannot resolve ES6 code, use import cookie from "cocookie/umd.js";
. For
usage from browser directly use the script tag (or download this script):
<script type="text/javascript" src="https://cdn.rawgit.com/ZitRos/cocookie/master/umd.js"></script>
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.