set-component
Advanced tools
Comparing version 0.0.4 to 1.0.0
@@ -70,3 +70,3 @@ /** | ||
|| require.modules[orig] && orig | ||
|| null; | ||
|| require.aliases[index]; | ||
}; | ||
@@ -86,3 +86,2 @@ | ||
// foo | ||
if ('.' != path.charAt(0)) return path; | ||
@@ -160,4 +159,2 @@ | ||
path = fn.resolve(path); | ||
var alias = require.aliases[path + '/index.js']; | ||
if (alias) path = alias; | ||
return require(path, parent, orig); | ||
@@ -193,89 +190,6 @@ } | ||
return fn; | ||
};require.register("component-indexof/index.js", function(module, exports, require){ | ||
};require.register("component-assert/index.js", function(module, exports, require){ | ||
var indexOf = [].indexOf; | ||
module.exports = function(arr, obj){ | ||
if (indexOf) return arr.indexOf(obj); | ||
for (var i = 0; i < arr.length; ++i) { | ||
if (arr[i] === obj) return i; | ||
} | ||
return -1; | ||
}; | ||
}); | ||
require.register("component-stack/index.js", function(module, exports, require){ | ||
/** | ||
* Expose `stack()`. | ||
*/ | ||
module.exports = stack; | ||
/** | ||
* Return the stack. | ||
* | ||
* @return {Array} | ||
* @api public | ||
*/ | ||
function stack() { | ||
var orig = Error.prepareStackTrace; | ||
Error.prepareStackTrace = function(_, stack){ return stack; }; | ||
var err = new Error; | ||
Error.captureStackTrace(err, arguments.callee); | ||
var stack = err.stack; | ||
Error.prepareStackTrace = orig; | ||
return stack; | ||
} | ||
}); | ||
require.register("component-assert/index.js", function(module, exports, require){ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var stack = require('stack'); | ||
/** | ||
* Load contents of `script`. | ||
* | ||
* @param {String} script | ||
* @return {String} | ||
* @api private | ||
*/ | ||
function getScript(script) { | ||
var xhr = new XMLHttpRequest; | ||
xhr.open('GET', script, false); | ||
xhr.send(null); | ||
return xhr.responseText; | ||
} | ||
/** | ||
* Assert `expr` with optional failure `msg`. | ||
* | ||
* @param {Mixed} expr | ||
* @param {String} [msg] | ||
* @api public | ||
*/ | ||
module.exports = function(expr, msg){ | ||
if (expr) return; | ||
if (!msg) { | ||
if (Error.captureStackTrace) { | ||
var callsite = stack()[1]; | ||
var fn = callsite.fun.toString(); | ||
var file = callsite.getFileName(); | ||
var line = callsite.getLineNumber() - 1; | ||
var col = callsite.getColumnNumber() - 1; | ||
var src = getScript(file); | ||
line = src.split('\n')[line].slice(col); | ||
expr = line.match(/assert\((.*)\)/)[1].trim(); | ||
msg = expr; | ||
} else { | ||
msg = 'assertion failed'; | ||
} | ||
} | ||
throw new Error(msg); | ||
if (!expr) throw new Error(msg || 'assertion failed'); | ||
}; | ||
@@ -286,8 +200,2 @@ }); | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var indexof = require('indexof'); | ||
/** | ||
* Expose `Set`. | ||
@@ -336,6 +244,23 @@ */ | ||
Set.prototype.has = function(val){ | ||
return !! ~indexof(this.vals, val); | ||
return !! ~this.indexOf(val); | ||
}; | ||
/** | ||
* Return the indexof `val`. | ||
* | ||
* @param {Mixed} val | ||
* @return {Number} | ||
* @api private | ||
*/ | ||
Set.prototype.indexOf = function(val){ | ||
for (var i = 0, len = this.vals.length; i < len; ++i) { | ||
var obj = this.vals[i]; | ||
if (obj.equals && obj.equals(val)) return i; | ||
if (obj == val) return i; | ||
} | ||
return -1; | ||
}; | ||
/** | ||
* Iterate each member and invoke `fn(val)`. | ||
@@ -400,3 +325,3 @@ * | ||
Set.prototype.remove = function(val){ | ||
var i = indexof(this.vals, val); | ||
var i = this.indexOf(val); | ||
if (~i) this.vals.splice(i, 1); | ||
@@ -464,5 +389,2 @@ return !! ~i; | ||
}); | ||
require.alias("component-indexof/index.js", "set/deps/indexof/index.js"); | ||
require.alias("component-assert/index.js", "set/deps/assert/index.js"); | ||
require.alias("component-stack/index.js", "component-assert/deps/stack/index.js"); |
{ | ||
"name": "set", | ||
"version": "0.0.4", | ||
"version": "1.0.0", | ||
"description": "set container", | ||
"keywords": ["set"], | ||
"scripts": ["index.js"], | ||
"dependencies": { | ||
"component/indexof": "*" | ||
}, | ||
"development": { | ||
@@ -11,0 +8,0 @@ "component/assert": "*" |
{ | ||
"name": "assert", | ||
"description": "Assertion lib", | ||
"version": "0.1.1", | ||
"version": "0.0.1", | ||
"keywords": [ | ||
@@ -9,5 +9,3 @@ "assert", | ||
], | ||
"dependencies": { | ||
"component/stack": "*" | ||
}, | ||
"dependencies": {}, | ||
"scripts": [ | ||
@@ -14,0 +12,0 @@ "index.js" |
/** | ||
* Module dependencies. | ||
*/ | ||
var stack = require('stack'); | ||
/** | ||
* Load contents of `script`. | ||
* | ||
* @param {String} script | ||
* @return {String} | ||
* @api private | ||
*/ | ||
function getScript(script) { | ||
var xhr = new XMLHttpRequest; | ||
xhr.open('GET', script, false); | ||
xhr.send(null); | ||
return xhr.responseText; | ||
} | ||
/** | ||
* Assert `expr` with optional failure `msg`. | ||
* | ||
* @param {Mixed} expr | ||
* @param {String} [msg] | ||
* @api public | ||
*/ | ||
module.exports = function(expr, msg){ | ||
if (expr) return; | ||
if (!msg) { | ||
if (Error.captureStackTrace) { | ||
var callsite = stack()[1]; | ||
var fn = callsite.fun.toString(); | ||
var file = callsite.getFileName(); | ||
var line = callsite.getLineNumber() - 1; | ||
var col = callsite.getColumnNumber() - 1; | ||
var src = getScript(file); | ||
line = src.split('\n')[line].slice(col); | ||
expr = line.match(/assert\((.*)\)/)[1].trim(); | ||
msg = expr; | ||
} else { | ||
msg = 'assertion failed'; | ||
} | ||
} | ||
throw new Error(msg); | ||
if (!expr) throw new Error(msg || 'assertion failed'); | ||
}; |
1.0.0 / 2012-11-07 | ||
================== | ||
* add .equals(other) support | ||
0.0.4 / 2012-10-17 | ||
@@ -3,0 +8,0 @@ ================== |
27
index.js
/** | ||
* Module dependencies. | ||
*/ | ||
var indexof = require('indexof'); | ||
/** | ||
* Expose `Set`. | ||
@@ -52,6 +46,23 @@ */ | ||
Set.prototype.has = function(val){ | ||
return !! ~indexof(this.vals, val); | ||
return !! ~this.indexOf(val); | ||
}; | ||
/** | ||
* Return the indexof `val`. | ||
* | ||
* @param {Mixed} val | ||
* @return {Number} | ||
* @api private | ||
*/ | ||
Set.prototype.indexOf = function(val){ | ||
for (var i = 0, len = this.vals.length; i < len; ++i) { | ||
var obj = this.vals[i]; | ||
if (obj.equals && obj.equals(val)) return i; | ||
if (obj == val) return i; | ||
} | ||
return -1; | ||
}; | ||
/** | ||
* Iterate each member and invoke `fn(val)`. | ||
@@ -116,3 +127,3 @@ * | ||
Set.prototype.remove = function(val){ | ||
var i = indexof(this.vals, val); | ||
var i = this.indexOf(val); | ||
if (~i) this.vals.splice(i, 1); | ||
@@ -119,0 +130,0 @@ return !! ~i; |
{ | ||
"name": "set-component", | ||
"version": "0.0.4", | ||
"version": "1.0.0", | ||
"description": "Set container", | ||
"keywords": ["set"], | ||
"dependencies": { | ||
"indexof": "*" | ||
}, | ||
"component": { | ||
@@ -10,0 +7,0 @@ "scripts": { |
@@ -27,2 +27,14 @@ | ||
## Equality | ||
Set supports an `.equals(other)` method when present, | ||
for example you may then add two separate `User` instances | ||
that are identified as being the same via their name: | ||
```js | ||
User.prototype.equals = function(user){ | ||
return this.name == user.name; | ||
}; | ||
``` | ||
## API | ||
@@ -29,0 +41,0 @@ |
Sorry, the diff of this file is not supported yet
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
1
1
94
12620
14
519
- Removedindexof@*
- Removedindexof@0.0.1(transitive)