Comparing version 0.1.0 to 0.2.0
28
index.js
@@ -10,14 +10,16 @@ function Caseless (dict) { | ||
} else { | ||
if (clobber === undefined) clobber = true | ||
if (clobber || !this.has(name)) this.dict[name] = value | ||
else this.dict[this.has(name)] += ',' + value | ||
return this | ||
if (typeof clobber === 'undefined') clobber = true | ||
var has = this.has(name) | ||
if (!clobber && has) this.dict[has] = this.dict[has] + ',' + value | ||
else this.dict[has || name] = value | ||
return has | ||
} | ||
} | ||
Caseless.prototype.has = function (name) { | ||
var lheaders = this.dict.map(function (h) {return h.toLowerCase()}) | ||
var keys = Object.keys(this.dict) | ||
, name = name.toLowerCase() | ||
; | ||
name = name.toLowerCase() | ||
for (var i=0;i<lheaders.length;i++) { | ||
if (lheaders[i] === name) return lheaders[i] | ||
for (var i=0;i<keys.length;i++) { | ||
if (keys[i].toLowerCase() === name) return keys[i] | ||
} | ||
@@ -28,3 +30,3 @@ return false | ||
var result, re, match | ||
var headers = this.headers | ||
var headers = this.dict | ||
Object.keys(headers).forEach(function (key) { | ||
@@ -37,3 +39,9 @@ re = new RegExp(name, 'i') | ||
} | ||
Caseless.prototype.swap = function (name) { | ||
var has = this.has(name) | ||
if (!has) throw new Error('There is no header than matches "'+name+'"') | ||
this.dict[name] = this.dict[has] | ||
delete this.dict[has] | ||
} | ||
module.exports = function (dict) {return new Caseless(dict)} | ||
module.exports = function (dict) {return new Caseless(dict)} |
{ | ||
"name": "caseless", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Caseless object set/get/has, very useful when working with HTTP headers.", | ||
@@ -18,2 +18,3 @@ "main": "index.js", | ||
], | ||
"test": "node test.js", | ||
"author": "Mikeal Rogers <mikeal.rogers@gmail.com>", | ||
@@ -23,3 +24,6 @@ "license": "BSD", | ||
"url": "https://github.com/mikeal/caseless/issues" | ||
}, | ||
"devDependencies": { | ||
"tape": "^2.10.2" | ||
} | ||
} |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
3612
4
65
0
46
1