Comparing version 1.1.0 to 1.2.0
@@ -53,6 +53,6 @@ var getDomains = require('./domains') | ||
cookie = splitCookie(cookies[i]) | ||
var cookienName = trim(cookie[0]) | ||
if (!name || cookienName === name) { | ||
var cookieName = trim(cookie[0]) | ||
if (!name || cookieName === name) { | ||
allCookies.push({ | ||
name: cookienName, | ||
name: cookieName, | ||
value: trim(cookie[1]) | ||
@@ -118,2 +118,14 @@ }) | ||
/** | ||
* gets the value of a cookie, or returns null | ||
* | ||
* @public | ||
* @param {String} name The cookie name | ||
* @returns {Null} or {Boolean} Returns null if the cookie is not found or the cookie's value | ||
*/ | ||
function cookieValue (name) { | ||
var cookies = getCookie(name) | ||
return cookies.length ? cookies[0].value : null | ||
} | ||
module.exports = { | ||
@@ -124,3 +136,4 @@ 'get': getCookie, | ||
'clear': clearCookie, | ||
'clearAll': clearAll | ||
'clearAll': clearAll, | ||
'val': cookieValue | ||
} |
{ | ||
"name": "cookieman", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"main": "lib/cookieman", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -25,2 +25,7 @@ # ![Cookieman](https://cloud.githubusercontent.com/assets/640611/11089200/f075ee22-885f-11e5-8cda-d620b6b79c69.png) | ||
``` | ||
### val | ||
Return the first value of a cookie that has been set on the page, or null if the cookie is not present | ||
```javascript | ||
cm.val('name') | ||
``` | ||
@@ -27,0 +32,0 @@ ### cookies |
@@ -214,3 +214,3 @@ var cookieman = require('../lib/cookieman') | ||
it("should clear cookies no matter what path/domain they're on", function () { | ||
it('should clear cookies no matter what path/domain they\'re on', function () { | ||
cookieman.set('flippy', 'magoo', { path: '/cookie' }) | ||
@@ -237,2 +237,24 @@ cookieman.clearAll('sweety') | ||
}) | ||
describe('val', function () { | ||
it('should return null if no cookie with that name has been set', function () { | ||
expect(cookieman.val('sweety')).to.eql(null) | ||
}) | ||
it('should return the value of the cookie if the cookie exists', function () { | ||
cookieman.set('sweety', 'darling', { path: '/cookie' }) | ||
expect(cookieman.val('sweety')).to.eql('darling') | ||
}) | ||
it('should return the value of the first cookie if multiple cookies with the same name exists', function () { | ||
cookieman.set('sweety', 'darling', { path: '/cookie' }) | ||
cookieman.set('sweety', 'pie', { path: '/' }) | ||
expect(cookieman.val('sweety')).to.eql('darling') | ||
}) | ||
it('should return an empty string if that is the value of the cookie', function () { | ||
cookieman.set('sweety', '', { path: '/cookie' }) | ||
expect(cookieman.val('sweety')).to.eql('') | ||
}) | ||
it('should return null if the cookie had no value set', function () { | ||
document.cookie = 'sweety=; path=/cookie; expires=' + new Date(1).toUTCString() | ||
expect(cookieman.val('sweety')).to.eql(null) | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19746
460
65