Comparing version 0.0.6 to 0.1.0
102
es5/array.js
/* | ||
array | ||
- es5 array shell | ||
- array es5 shell | ||
*/"use strict" | ||
var shell = require("../util/shell") | ||
var array = require("../shell")["array"] | ||
var proto = Array.prototype | ||
var names = ( | ||
"pop,push,reverse,shift,sort,splice,unshift,concat,join,slice,toString,indexOf,lastIndexOf,forEach,every,some" + | ||
",filter,map,reduce,reduceRight" | ||
).split(",") | ||
var array = shell({ | ||
for (var methods = {}, i = 0, name, method; name = names[i++];) if ((method = Array.prototype[name])) methods[name] = method | ||
filter: proto.filter/*(es5 && array.filter)?*/ || function(fn, context){ | ||
var results = [] | ||
for (var i = 0, l = this.length >>> 0; i < l; i++) if (i in this){ | ||
var value = this[i] | ||
if (fn.call(context, value, i, this)) results.push(value) | ||
} | ||
return results | ||
}/*:*/, | ||
if (!methods.filter) methods.filter = function(fn, context){ | ||
var results = [] | ||
for (var i = 0, l = this.length >>> 0; i < l; i++) if (i in this){ | ||
var value = this[i] | ||
if (fn.call(context, value, i, this)) results.push(value) | ||
} | ||
return results | ||
} | ||
indexOf: proto.indexOf/*(es5 && array.indexOf)?*/ || function(item, from){ | ||
for (var l = this.length >>> 0, i = (from < 0) ? Math.max(0, l + from) : from || 0; i < l; i++){ | ||
if ((i in this) && this[i] === item) return i | ||
} | ||
return -1 | ||
}/*:*/, | ||
if (!methods.indexOf) methods.indexOf = function(item, from){ | ||
for (var l = this.length >>> 0, i = (from < 0) ? Math.max(0, l + from) : from || 0; i < l; i++){ | ||
if ((i in this) && this[i] === item) return i | ||
} | ||
return -1 | ||
} | ||
map: proto.map/*(es5 && array.map)?*/ || function(fn, context){ | ||
var length = this.length >>> 0, results = Array(length) | ||
for (var i = 0, l = length; i < l; i++){ | ||
if (i in this) results[i] = fn.call(context, this[i], i, this) | ||
} | ||
return results | ||
}/*:*/, | ||
if (!methods.map) methods.map = function(fn, context){ | ||
var length = this.length >>> 0, results = Array(length) | ||
for (var i = 0, l = length; i < l; i++){ | ||
if (i in this) results[i] = fn.call(context, this[i], i, this) | ||
} | ||
return results | ||
} | ||
forEach: proto.forEach/*(es5 && array.forEach)?*/ || function(fn, context){ | ||
for (var i = 0, l = this.length >>> 0; i < l; i++){ | ||
if (i in this) fn.call(context, this[i], i, this) | ||
} | ||
}/*:*/, | ||
if (!methods.every) methods.every = function(fn, context){ | ||
for (var i = 0, l = this.length >>> 0; i < l; i++){ | ||
if ((i in this) && !fn.call(context, this[i], i, this)) return false | ||
} | ||
return true | ||
} | ||
every: proto.every/*(es5 && array.every)?*/ || function(fn, context){ | ||
for (var i = 0, l = this.length >>> 0; i < l; i++){ | ||
if ((i in this) && !fn.call(context, this[i], i, this)) return false | ||
} | ||
return true | ||
}/*:*/, | ||
if (!methods.some) methods.some = function(fn, context){ | ||
for (var i = 0, l = this.length >>> 0; i < l; i++){ | ||
if ((i in this) && fn.call(context, this[i], i, this)) return true | ||
} | ||
return false | ||
} | ||
some: proto.some/*(es5 && array.some)?*/ || function(fn, context){ | ||
for (var i = 0, l = this.length >>> 0; i < l; i++){ | ||
if ((i in this) && fn.call(context, this[i], i, this)) return true | ||
} | ||
return false | ||
}/*:*/ | ||
if (!methods.forEach) methods.forEach = function(fn, context){ | ||
for (var i = 0, l = this.length >>> 0; i < l; i++){ | ||
if (i in this) fn.call(context, this[i], i, this) | ||
} | ||
} | ||
}) | ||
var toString = Object.prototype.toString | ||
array.isArray = Array.isArray/*(es5 && array.isArray)?*/ || function(self){ | ||
return Object.prototype.toString.call(self) === "[object Array]" | ||
}/*:*/ | ||
array.isArray = Array.isArray || function(self){ | ||
return toString.call(self) === "[object Array]" | ||
} | ||
var methods = {} | ||
var names = "pop,push,reverse,shift,sort,splice,unshift,concat,join,slice,lastIndexOf,reduce,reduceRight".split(",") | ||
for (var i = 0, name, method; name = names[i++];) if ((method = proto[name])) methods[name] = method | ||
array.implement(methods) | ||
module.exports = array | ||
module.exports = array.implement(methods) |
/* | ||
function | ||
- es5 function shell | ||
- function es5 shell | ||
*/"use strict" | ||
var shell = require("../util/shell") | ||
var function_ = require("../shell")["function"] | ||
var proto = Function.prototype | ||
var names = "apply,bind,call,isGenerator,toString".split(",") | ||
module.exports = shell({ | ||
apply: proto.apply, | ||
call: proto.call, | ||
bind: proto.bind | ||
}) | ||
for (var methods = {}, i = 0, name, method; name = names[i++];) if ((method = Function.prototype[name])) methods[name] = method | ||
module.exports = function_.implement(methods) |
/* | ||
number | ||
- es5 number shell | ||
- number es5 shell | ||
*/"use strict" | ||
var shell = require("../util/shell") | ||
var number = require("../shell")["number"] | ||
var proto = Number.prototype | ||
var names = "toExponential,toFixed,toLocaleString,toPrecision,toString,valueOf".split(",") | ||
var number = shell({ | ||
toExponential: proto.toExponential, | ||
toFixed: proto.toFixed, | ||
toPrecision: proto.toPrecision | ||
}) | ||
for (var methods = {}, i = 0, name, method; name = names[i++];) if ((method = Number.prototype[name])) methods[name] = method | ||
module.exports = number | ||
module.exports = number.implement(methods) |
/* | ||
regexp | ||
- es5 regexp shell | ||
- regexp es5 shell | ||
*/"use strict" | ||
var shell = require("../util/shell") | ||
var regexp = require("../shell")["regexp"] | ||
var proto = RegExp.prototype | ||
var names = "exec,test,toString".split(",") | ||
var regexp = shell({test: proto.test, exec: proto.exec}) | ||
for (var methods = {}, i = 0, name, method; name = names[i++];) if ((method = RegExp.prototype[name])) methods[name] = method | ||
module.exports = regexp | ||
module.exports = regexp.implement(methods) |
/* | ||
string | ||
- es5 string shell | ||
- string es5 shell | ||
*/"use strict" | ||
var shell = require("../util/shell") | ||
var string = require("../shell")["string"] | ||
var proto = String.prototype | ||
var names = ( | ||
"charAt,charCodeAt,concat,contains,endsWith,indexOf,lastIndexOf,localeCompare,match,replace,search,slice,split" + | ||
",startsWith,substr,substring,toLocaleLowerCase,toLocaleUpperCase,toLowerCase,toString,toUpperCase,trim,valueOf" | ||
).split(",") | ||
var string = shell({ | ||
for (var methods = {}, i = 0, name, method; name = names[i++];) if ((method = String.prototype[name])) methods[name] = method | ||
trim: proto.trim/*(es5 && string.trim)?*/ || function(){ | ||
return (this + '').replace(/^\s+|\s+$/g, '') | ||
}/*:*/ | ||
if (!methods.trim) methods.trim = function(){ | ||
return (this + '').replace(/^\s+|\s+$/g, '') | ||
} | ||
}) | ||
var methods = {} | ||
var names = "charAt,charCodeAt,concat,indexOf,lastIndexOf,match,quote,replace,search,slice,split,substr,substring,toLowerCase,toUpperCase".split(",") | ||
for (var i = 0, name, method; name = names[i++];) if ((method = proto[name])) methods[name] = method | ||
string.implement(methods) | ||
module.exports = string | ||
module.exports = string.implement(methods) |
{ | ||
"name": "prime", | ||
"homepage": "https://github.com/mootools/prime", | ||
"version": "0.0.6", | ||
"main": "./prime/index.js", | ||
"version": "0.1.0", | ||
"main": "./index.js", | ||
"description": "prime, an OOP javascript library for node and the web.", | ||
@@ -18,4 +18,3 @@ "keywords": [ | ||
"Arian Stolwijk <@arian> (http://aryweb.nl)", | ||
"Olmo Maldonado <@ibolmo> (http://github.com/ibolmo)", | ||
"Christoph Pojer <@cpojer> (http://cpojer.net)" | ||
"Cristian Carlesso <@kentaromiura> (http://github.com/kentaromiura)" | ||
], | ||
@@ -32,3 +31,3 @@ "bugs": { | ||
"devDependencies": { | ||
"mocha": "1.6", | ||
"mocha": "1.8", | ||
"expect.js": "0.1", | ||
@@ -35,0 +34,0 @@ "wrapup": "0.10", |
163
README.md
#prime |prīm| | ||
1. fundamental, basic, essential. | ||
2. make (something) ready for use or action. | ||
3. archetypal, prototypical, typical, classic. | ||
1. fundamental, basic, essential. | ||
2. make (something) ready for use or action. | ||
3. archetypal, prototypical, typical, classic. | ||
## Description | ||
prime is an Object Oriented JavaScript library. It helps you with prototypal inheritance and contains generic utilities for every-day JavaScripting. | ||
No Native JavaScript Objects were harmed in the making of this library. | ||
## Modules Overview | ||
A short overview of the available modules. For more information, refer to the [documentation](https://github.com/mootools/prime/blob/master/doc/prime.md). | ||
### prime | ||
The function to create new primes. | ||
```js | ||
var prime = require("prime") | ||
var Animal = prime({ | ||
say: function(){ | ||
return "!!" | ||
} | ||
}) | ||
var Cat = prime({ | ||
inherits: Animal, | ||
say: function(){ | ||
return "meaow" + Cat.parent.say.call(this) | ||
} | ||
}) | ||
``` | ||
### prime/shell | ||
The base shell. As you require more shells, the base shell will be augmented. | ||
Requiring specific shells gives you access to generic methods as well. | ||
```js | ||
var array = require("prime/shell/array") | ||
array.indexOf([1,2,3], 3) // 3 | ||
var _ = require("prime/shell") | ||
_([1,2,3]).remove(1).each(function(number){ | ||
console.log(number) | ||
}) | ||
``` | ||
### prime/emitter | ||
The event emitter. | ||
```js | ||
var Emitter = require("prime/emitter") | ||
var Dog = prime({ | ||
inherits: Animal, | ||
say: function(){ | ||
var word = "wuff" + Dog.parent.say.call(this) | ||
this.emit("say", word) | ||
return word | ||
} | ||
}) | ||
Dog.implement(new Emitter) | ||
var barkley = new Dog | ||
barkley.on("say", function(word){ | ||
console.log("barkley barked", word) | ||
}) | ||
``` | ||
### prime/map | ||
Simple WeakMap implementation. | ||
```js | ||
var Map = require("prime/map") | ||
var map = new Map() | ||
map.set(domElement, "header") | ||
map.set(domElement2, "footer") | ||
map.get(domElement) // "header" | ||
map.get(domElement2) // "footer" | ||
``` | ||
### prime/type | ||
Type checker. | ||
```js | ||
var type = require("prime/type") | ||
type("string") // "string" | ||
type([]) // "array" | ||
type(function(){}) // "function" | ||
type(/regexp/) // "regexp" | ||
type(new Date) // "date" | ||
type(10) // "number" | ||
type(false) // "boolean" | ||
type({}) // "object" | ||
type(arguments) // "object" | ||
type(null) // "null" | ||
type(undefined) // "null" | ||
type(NaN) // "null" | ||
``` | ||
### prime/shell/array | ||
Array methods. | ||
```js | ||
require("prime/shell/array") | ||
``` | ||
### prime/shell/object | ||
Object methods. | ||
```js | ||
require("prime/shell/object") | ||
``` | ||
### prime/shell/string | ||
String methods. | ||
```js | ||
require("prime/shell/string") | ||
``` | ||
### prime/shell/number | ||
Number methods. | ||
```js | ||
require("prime/shell/number") | ||
``` | ||
### prime/shell/function | ||
Function methods. | ||
```js | ||
require("prime/shell/function") | ||
``` | ||
### prime/shell/regexp | ||
Regexp methods. | ||
```js | ||
require("prime/shell/regexp") | ||
``` | ||
### prime/shell/date | ||
Date methods. | ||
```js | ||
require("prime/shell/date") | ||
``` | ||
[![Build Status](https://secure.travis-ci.org/mootools/prime.png?branch=master)](http://travis-ci.org/mootools/prime) |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
167
23363
22
594
1