Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

browser-cookies

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-cookies - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

7

browser-cookies.js

@@ -45,4 +45,7 @@ exports.defaults = {};

// If a separator index is found, Decode the cookie name and compare to the requested cookie name
if (separatorIndex != -1 && decodeURIComponent(cookie.substring(0, separatorIndex).replace(/^\s+|\s+$/g,'')) == name) {
// IE<11 emits the equal sign when the cookie value is empty
separatorIndex = separatorIndex < 0 ? cookie.length : separatorIndex;
// Decode the cookie name and remove any leading/trailing spaces, then compare to the requested cookie name
if (decodeURIComponent(cookie.substring(0, separatorIndex).replace(/^\s+|\s+$/g,'')) == name) {
return decodeURIComponent(cookie.substring(separatorIndex + 1, cookie.length));

@@ -49,0 +52,0 @@ }

{
"name": "browser-cookies",
"description": "Tiny cookies library for the browser",
"version": "1.0.3",
"version": "1.0.4",
"main": "browser-cookies.js",

@@ -13,18 +13,18 @@ "files": [

"devDependencies": {
"browserify": "^9.0.7",
"co": "^4.5.1",
"coveralls": "^2.11.2",
"browserify": "9.0.x",
"co": "4.5.x",
"coveralls": "2.11.x",
"gulp": "git://github.com/gulpjs/gulp.git#4.0",
"gulp-rename": "^1.2.2",
"gulp-size": "^1.2.1",
"gulp-uglify": "^1.1.0",
"gulp-wrap": "^0.11.0",
"jasmine-core": "^2.2.0",
"karma": "^0.12.31",
"karma-browserify": "^4.1.2",
"karma-coverage": "^0.2.7",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "^0.1.4",
"karma-sauce-launcher": "^0.2.10",
"karma-spec-reporter": "0.0.18"
"gulp-rename": "1.2.x",
"gulp-size": "1.2.x",
"gulp-uglify": "1.2.x",
"gulp-wrap": "0.11.x",
"jasmine-core": "2.2.x",
"karma": "0.12.x",
"karma-browserify": "4.1.x",
"karma-coverage": "0.3.x",
"karma-jasmine": "0.3.x",
"karma-phantomjs-launcher": "0.1.x",
"karma-sauce-launcher": "0.2.x",
"karma-spec-reporter": "0.0.x"
},

@@ -52,2 +52,3 @@ "scripts": {

"browser",
"cookie",
"cookies",

@@ -54,0 +55,0 @@ "commonjs",

@@ -32,3 +32,3 @@ <img width="425" height="200" src="https://raw.githubusercontent.com/voltace/browser-cookies/master/browser-cookies.png"/>

[![Sauce Test Status][saucelabs-image]][saucelabs-url]
Or [run the unit tests](https://rawgit.com/voltace/browser-cookies/master/test/index.html) for your current browser right now.
Or [run the unit tests][ref-unittests] for your current browser right now.

@@ -57,30 +57,53 @@ ### Installation

### API
**cookies.set(** `name`, `value` [, `options`] **)**
> Method to save a cookie
> - **`name`** (string) the name of the cookie to save
> - **`value`** (string) the value to save
> - **`options`** (object) may contain any of the properties specified in [options](#options) below. If an option is not specified, the value configured in `cookies.defaults` will be used.
API contents:
- method [cookies.set(`name`, `value` [, `options`])](#cookies-set)
- method [cookies.get(`name`)](#cookies-get)
- method [cookies.set(`name`, [, `options`])](#cookies-erase)
- property [cookies.defaults](#cookies-defaults)
**cookies.get(** `name` **)**
> Method that returns a cookie value, or **null** if the cookie is not found
> - **`name`** (string) the name of the cookie to retrieve
<hr/>
<a name="cookies-set" href="#cookies-set">**cookies.set(** `name`, `value` [, `options`] **)**</a>
Method to save a cookie.
**cookies.erase(** `name` [, `options`] **)**
> Method to remove a cookie
> - **`name`** (string) the name of the cookie to remove
> - **`options`** (object) may contain the `domain` and `path` properties specified in [options](#options) below. If an option is not specified, the value configured in `cookies.defaults` will be used.
| argument | type | description
|---------------|--------|------------
| **`name`** | string | the name of the cookie to save.
| **`value`** | string | the value to save.
| **`options`** | object | may contain any of the properties specified in [options](#options) below. If an option is not specified, the value configured in [`cookies.defaults`](#cookies-defaults) will be used.
**cookies.defaults**
> This object may be used to change the default value of each option specified in [options](#options) below.
<hr/>
<a name="cookies-get" href="#cookies-get">**cookies.get(** `name` **)**</a>
Method that returns a cookie value, or **null** if the cookie is not found.
| argument | type | description
|---------------|--------|------------
| **`name`** | string | the name of the cookie to retrieve.
<hr/>
<a name="cookies-erase" href="#cookies-erase">**cookies.erase(** `name` [, `options`] **)**</a>
Method to remove a cookie.
| argument | type | description
|---------------|--------|------------
| **`name`** | string | the name of the cookie to remove.
| **`options`** | object | may contain the `domain` and `path` properties specified in [options](#options) below. If an option is not specified, the value configured in [`cookies.defaults`](#cookies-defaults) will be used.
<hr/>
<a name="cookies-defaults" href="#cookies-defaults">**cookies.defaults**</a>
This object may be used to change the default value of each option specified in [options](#options) below.
### Options
Options may be set globally using `cookies.defaults` or passed as function argument, see the [Examples](#examples) section below and the [API](#api) reference above for details.
Options may be set globally using [`cookies.defaults`](#cookies-defaults) or passed as function argument, see the [Examples](#examples) section below and the [API](#api) reference above for details.
| Name | Type | Default | Description
|------------|--------------------|---------|--------
| `expires` | `Number`, `Date`&nbsp;or `String` | `0` | Configure when the cookie expires by using one of the following types as value:<ul><li>A `Number` of days until the cookie expires.</li><li>A `Date` object such as `new Date(2018, 3, 27)`.</li><li>A `String` in a format recognized by [Date.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse).</li></ul>If set to `0` the cookie will expire at the end of the session.
| `domain` | `String` | `""` | The [domain](https://stackoverflow.com/questions/1062963/how-do-browser-cookie-domains-work) from where the cookie is readable.<br/><br/>If set to `""` the current domain will be used.
| `path` | `String` | `"/"` | The path from where the cookie is readable.<ul><li>The default value of `"/"` allows the cookie to be readable from all paths.</li><li>If set to `""` the cookie will only be readable from the current browser path.</li></ul><br/><br/>Note that cookies don't support relative paths such as `../../some/path`, paths must be absolute like `/some/path`.
| `secure` | `Boolean` | `false` | If true the cookie will only be transmitted over secure protocols like https.
| `httponly` | `Boolean` | `false` | If true the cookie may only be read by the web server. <br/><br/>This option may be set to [prevent malicious scripts from accessing cookies](http://blog.codinghorror.com/protecting-your-cookies-httponly/), not all browsers support this feature yet.
| Name | Type | Default | Description
|------------|----------------------------|---------|--------
| `expires` | `Number`, `Date`, `String` | `0` | Configure when the cookie expires by using one of the following types as value:<ul><li>A `Number` of days until the cookie expires. If set to `0` the cookie will expire at the end of the session.</li><li>A `Date` object such as `new Date(2018, 3, 27)`.</li><li>A `String` in a format recognized by [Date.parse()][ref-date-parse].</li></ul>
| `domain` | `String` | `""` | The [domain][ref-cookie-domain] from where the cookie is readable.<ul><li>If set to `""` the current domain will be used.</li></ul>
| `path` | `String` | `"/"` | The path from where the cookie is readable.<ul><li>The default value of `"/"` allows the cookie to be readable from all paths.</li><li>If set to `""` the cookie will only be readable from the current browser path.</li><li>Note that cookies don't support relative paths such as `"../../some/path"` so paths must be absolute like `"/some/path"`.</li></ul>
| `secure` | `Boolean` | `false` | If true the cookie will only be transmitted over secure protocols like https.
| `httponly` | `Boolean` | `false` | If true the cookie may only be read by the web server.<ul><li> This option may be set to [prevent malicious scripts from accessing cookies][ref-httponly], not all browsers support this feature yet.</li></ul>

@@ -130,3 +153,3 @@ ### Examples

- Additional tests:
- More test cases to verify proper encoding/decoding (stubbed and non-stubbed).
- Extend test cases to verify proper cookie name encoding/decoding (stubbed and non-stubbed).
- More bad weather scenarios.

@@ -138,3 +161,3 @@ - Mobile browser testing (Disabled automated testing for mobile browsers because the results varied per run).

- Cross browser consistency:
- When a domain is not specified most browsers only allow an exact domain match, but [IE sends cookies to all subdomains](http://erik.io/blog/2014/03/04/definitive-guide-to-cookie-domains/). Perhaps save cookies to all subdomains by default for consistent behavior amongst all browsers? Would need to investigate whether something like window.location.hostname is cross-browser supported though. Or check how other cookie libs solved this. But first of all need to decide on the desired behavior.
- When a domain is not specified most browsers only allow an exact domain match, but [IE sends cookies to all subdomains][ref-ie-cookies]. Perhaps save cookies to all subdomains by default for consistent behavior amongst all browsers? Would need to investigate whether something like window.location.hostname is cross-browser supported though. Or check how other cookie libs solved this. But first of all need to decide on the desired behavior.

@@ -144,3 +167,3 @@ ### Development

Development setup (requires [node](https://nodejs.org/download/) and [git](https://help.github.com/articles/set-up-git/) to be installed):
Development setup (requires [node][ref-node-download] and [git][ref-git-setup] to be installed):
```python

@@ -157,4 +180,15 @@ git clone https://github.com/voltace/browser-cookies.git

### License
Public Domain ([UNLICENSE](LICENSE))
Public Domain ([UNLICENSE][ref-licence])
<!--- References -->
[ref-cookie-domain]: https://stackoverflow.com/questions/1062963/how-do-browser-cookie-domains-work
[ref-date-parse]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
[ref-httponly]: http://blog.codinghorror.com/protecting-your-cookies-httponly/
[ref-ie-cookies]: http://erik.io/blog/2014/03/04/definitive-guide-to-cookie-domains/
[ref-node-download]: https://nodejs.org/download/
[ref-git-setup]: https://help.github.com/articles/set-up-git/
[ref-licence]: http://choosealicense.com/licenses/#unlicense
[ref-unittests]: https://rawgit.com/voltace/browser-cookies/master/test/index.html
<!--- Shields -->
[npm-url]: https://npmjs.org/package/browser-cookies

@@ -168,3 +202,3 @@ [npm-version-image]: https://img.shields.io/npm/v/browser-cookies.svg

[coveralls-url]: https://coveralls.io/r/voltace/browser-cookies
[coveralls-image]: http://img.shields.io/coveralls/voltace/browser-cookies/master.svg
[coveralls-image]: https://img.shields.io/coveralls/voltace/browser-cookies/master.svg

@@ -171,0 +205,0 @@ [david-url]: https://david-dm.org/voltace/browser-cookies#info=devDependencies

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc