From 4818e76ad9f53537abcda1b7c3f8676969457868 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 15 Jun 2015 21:52:15 +0800 Subject: [PATCH] :memo: add cookies doc. --- docs/README.md | 1 + docs/api/cookies.md | 63 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 docs/api/cookies.md diff --git a/docs/README.md b/docs/README.md index 98b4219d3432..c01a748d05ee 100644 --- a/docs/README.md +++ b/docs/README.md @@ -32,6 +32,7 @@ Modules for the main process: * [auto-updater](api/auto-updater.md) * [browser-window](api/browser-window.md) * [content-tracing](api/content-tracing.md) +* [cookies](api/cookies.md) * [dialog](api/dialog.md) * [global-shortcut](api/global-shortcut.md) * [ipc (main process)](api/ipc-main-process.md) diff --git a/docs/api/cookies.md b/docs/api/cookies.md new file mode 100644 index 000000000000..d84e871be8d9 --- /dev/null +++ b/docs/api/cookies.md @@ -0,0 +1,63 @@ +# cookies + +The `cookies` module gives you ability to query and modify cookies, an example +is: + +```javascipt +var cookies = require('cookies'); + +// Query all cookies. +cookies.get({}, function(error, cookies) { + if (error) throw error; + console.log(cookies); +}); + +// Query all cookies that are associated with a specific url. +cookies.get({ url : "http://www.github.com" }, function(error, cookies) { + if (error) throw error; + console.log(cookies); +}); + +// Set a cookie with the given cookie data; may overwrite equivalent cookies if they exist. +cookies.set({ url : "http://www.github.com", name : "dummy_name", value : "dummy"}, + function(error, cookies) { + if (error) throw error; + console.log(cookies); +}); +``` + +## cookies.get(details, callback) + +* `details` Object + * `url` String - Retrieves cookies which are associated with `url`. Empty imples retrieving cookies of all urls. + * `name` String - Filters cookies by name + * `domain` String - Retrieves cookies whose domains match or are subdomains of `domains` + * `path` String - Retrieves cookies whose path matches `path` + * `secure` Boolean - Filters cookies by their Secure property + * `session` Boolean - Filters out session or persistent cookies. +* `callback` Function - function(error, cookies) + * `error` Error + * `cookies` Array - array of cookie objects. + +## cookies.set(details, callback) + +* `details` Object + * `url` String - Retrieves cookies which are associated with `url` + * `name` String - The name of the cookie. Empty by default if omitted. + * `value` String - The value of the cookie. Empty by default if omitted. + * `domain` String - The domain of the cookie. Empty by default if omitted. + * `path` String - The path of the cookie. Empty by default if omitted. + * `secure` Boolean - Whether the cookie should be marked as Secure. Defaults to false. + * `session` Boolean - Whether the cookie should be marked as HttpOnly. Defaults to false. + * `expirationDate` Double - The expiration date of the cookie as the number of seconds since the UNIX epoch. If omitted, the cookie becomes a session cookie. + +* `callback` Function - function(error) + * `error` Error + +## cookies.remove(details, callback) + +* `details` Object + * `url` String - The URL associated with the cookie + * `name` String - The name of cookie to remove +* `callback` Function - function(error) + * `error` Error