Comparing version 0.3.1 to 0.3.2
@@ -18,2 +18,8 @@ # Arrays | ||
- `#first` | ||
-- Returns first element of *self*, or `undefined` if empty. | ||
- `#last` | ||
-- Returns last element of *self*, or `undefined` if empty. | ||
- `#sample` | ||
@@ -38,2 +44,14 @@ -- Returns a random value from the array. `undefined` if the array is empty. | ||
- `#at(index)` | ||
-- Returns the value in *self* at the `index`. If `index` is negative, position calculated from end of *self*. Does not wrap around indices. Out of bounds returns `undefined`. `index` defaults to position `0`. | ||
``` | ||
['a', 'b', 'c'].at(2) | ||
>> 'c' | ||
['x', 'y', 'z'].at(-1) | ||
>> 'z' | ||
['y', 'o'].at(2) | ||
>> undefined | ||
``` | ||
- `#count(var, bool)` | ||
@@ -40,0 +58,0 @@ -- Returns the number of elements in the array that strictly match *var*. If *var* is a function, it is treated a filter: `func(element, index) {}`, where truthy returns count as a match. To strictly check the array for functions, pass *bool* as `false`. |
@@ -0,0 +0,0 @@ # Booleans |
@@ -0,0 +0,0 @@ # Functions |
@@ -0,0 +0,0 @@ # Numbers |
@@ -0,0 +0,0 @@ # Objects |
@@ -0,0 +0,0 @@ # Documentation |
@@ -0,0 +0,0 @@ # Strings |
{ | ||
"name": "rubyisms", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Ruby style ES5 prototype extensions.", | ||
@@ -30,5 +30,5 @@ "keywords": [ | ||
"devDependencies": { | ||
"chai": "^3.0.0", | ||
"mocha": "^2.2.5" | ||
"chai": "~3.5.0", | ||
"mocha": "~2.4.0" | ||
} | ||
} |
@@ -0,0 +0,0 @@ <p align="center"> |
263
rubyisms.js
// Colin 'Oka' Hall-Coates | ||
// http://oka.io <yo@oka.io> | ||
// MIT, 2015 | ||
// MIT, 2016 | ||
@@ -8,24 +8,35 @@ ;(function (G) { | ||
var toString = Object.prototype.toString; | ||
// Prototypes | ||
var | ||
ArrayPrototype = Array.prototype, | ||
BooleanPrototype = Boolean.prototype, | ||
FunctionPrototype = Function.prototype, | ||
NumberPrototype = Number.prototype, | ||
ObjectPrototype = Object.prototype, | ||
StringPrototype = String.prototype; | ||
var types = { | ||
arr : '[object Array]', | ||
bool : '[object Boolean]', | ||
func : '[object Function]', | ||
nul : '[object Null]', | ||
num : '[object Number]', | ||
obj : '[object Object]', | ||
str : '[object String]', | ||
und : '[object Undefined]' | ||
}; | ||
// Types | ||
var | ||
ArrayType = '[object Array]', | ||
BooleanType = '[object Boolean]', | ||
FunctionType = '[object Function]', | ||
NullType = '[object Null]', | ||
NumberType = '[object Number]', | ||
ObjectType = '[object Object]', | ||
StringType = '[object String]', | ||
UndefinedType = '[object Undefined]'; | ||
var regex = { | ||
symbolWithCombiningMarks: /([\0-\u02FF\u0370-\u1AAF\u1B00-\u1DBF\u1E00-\u20CF\u2100-\uD7FF\uE000-\uFE1F\uFE30-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])([\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]+)/g, | ||
surrogatePair: /([\uD800-\uDBFF])([\uDC00-\uDFFF])/g, | ||
crlf: /\r\n/ | ||
}; | ||
// Regular Expressions | ||
var | ||
SymbolWithCombiningMarks = /([\0-\u02FF\u0370-\u1AAF\u1B00-\u1DBF\u1E00-\u20CF\u2100-\uD7FF\uE000-\uFE1F\uFE30-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])([\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]+)/g, | ||
SurrogatePair = /([\uD800-\uDBFF])([\uDC00-\uDFFF])/g, | ||
CRLF = /\r\n/; | ||
// Utilities | ||
var | ||
toString = ObjectPrototype.toString; | ||
/* jshint -W040 */ | ||
function define (property, value) { | ||
var isObject = (toString.call(this) === types.obj); | ||
var isObject = (toString.call(this) === ObjectType); | ||
@@ -69,3 +80,3 @@ Object.defineProperty(this, property, { | ||
minor(Array.prototype, { | ||
minor(ArrayPrototype, { | ||
clear: function () { | ||
@@ -91,2 +102,8 @@ while (this.length > 0) this.pop(); | ||
}, | ||
first: function () { | ||
return this[0]; | ||
}, | ||
last: function () { | ||
return this[this.length - 1]; | ||
}, | ||
sample: function () { | ||
@@ -96,13 +113,10 @@ return this[Math.floor(Math.random() * this.length)]; | ||
uniq: (function () { | ||
var arr = types.arr, | ||
bool = types.bool, | ||
func = types.func, | ||
nul = types.nul, | ||
num = types.num, | ||
obj = types.obj, | ||
str = types.str, | ||
und = types.und; | ||
return (function () { | ||
var s = {}, b = {}, n = {}, u = {}, o = [], r = [], p, c, | ||
var strings = {}, | ||
booleans = {}, | ||
numbers = {}, | ||
undef = {}, | ||
objects = [], | ||
output = [], | ||
pushFlag, objectCount, objectLength, | ||
item, type, length, index; | ||
@@ -116,27 +130,31 @@ | ||
type = toString.call(item); | ||
p = true; | ||
if (type === str && !s.hasOwnProperty(item)) { | ||
s[item] = true; r.push(item); | ||
} else if (type === bool && !b.hasOwnProperty(item)) { | ||
b[item] = true; r.push(item); | ||
} else if (type === num && !n.hasOwnProperty(item)) { | ||
n[item] = true; r.push(item); | ||
} else if (type === obj || type === func || type === arr) { | ||
pushFlag = true; | ||
if (type === StringType && !strings.hasOwnProperty(item)) { | ||
strings[item] = true; output.push(item); | ||
} else if (type === BooleanType && !booleans.hasOwnProperty(item)) { | ||
booleans[item] = true; output.push(item); | ||
} else if (type === NumberType && !numbers.hasOwnProperty(item)) { | ||
numbers[item] = true; output.push(item); | ||
} else if (type === ObjectType || | ||
type === FunctionType || | ||
type === ArrayType) { | ||
objs: | ||
for (c = 0; c < o.length; c++) { | ||
if (o[c] === item) { | ||
p = false; | ||
for (objectCount = 0, objectLength = objects.length; | ||
objectCount < objectLength; objectCount++) { | ||
if (objects[objectCount] === item) { | ||
pushFlag = false; | ||
break objs; | ||
} | ||
} | ||
if (p) { | ||
o.push(item); | ||
r.push(item); | ||
if (pushFlag) { | ||
objects.push(item); | ||
output.push(item); | ||
} | ||
} else if ((type === und || type === nul) && !u.hasOwnProperty(item)) { | ||
u[item] = true; r.push(item); | ||
} else if ((type === UndefinedType || type === NullType) && | ||
!undef.hasOwnProperty(item)) { | ||
undef[item] = true; output.push(item); | ||
} | ||
} | ||
return r; | ||
return output; | ||
}); | ||
@@ -146,3 +164,3 @@ }()) | ||
minor(Boolean.prototype, { | ||
minor(BooleanPrototype, { | ||
not: function () { | ||
@@ -153,3 +171,3 @@ return !this; | ||
minor(Function.prototype, { | ||
minor(FunctionPrototype, { | ||
clone: function () { | ||
@@ -160,3 +178,3 @@ return this.bind(null); | ||
minor(Number.prototype, { | ||
minor(NumberPrototype, { | ||
abs: function () { | ||
@@ -217,23 +235,21 @@ return Math.abs(this); | ||
minor(Object.prototype, { | ||
minor(ObjectPrototype, { | ||
array: function () { | ||
return toString.call(this) === types.arr; | ||
return toString.call(this) === ArrayType; | ||
}, | ||
bool: function () { | ||
return toString.call(this) === types.bool; | ||
return toString.call(this) === BooleanType; | ||
}, | ||
empty: function () { | ||
if (toString.call(this) === types.obj) { | ||
if (toString.call(this) === ObjectType) | ||
return Object.keys(this).length < 1; | ||
} | ||
}, | ||
func: function () { | ||
return toString.call(this) === types.func; | ||
return toString.call(this) === FunctionType; | ||
}, | ||
numeric: function () { | ||
return (toString.call(this) === types.num) && | ||
(this === this); | ||
return (toString.call(this) === NumberType) && (this === this); | ||
}, | ||
object: function () { | ||
return toString.call(this) === types.obj; | ||
return toString.call(this) === ObjectType; | ||
}, | ||
@@ -244,12 +260,12 @@ size: function () { | ||
if ( | ||
type === types.arr || | ||
type === types.str || | ||
type === types.func | ||
type === ArrayType || | ||
type === StringType || | ||
type === FunctionType | ||
) return this.length; | ||
else if (type === types.obj) return Object.keys(this).length; | ||
else if (type === types.bool) return (this ? 1 : 0); | ||
else if (type === types.num && this === this) return this; | ||
else if (type === ObjectType) return Object.keys(this).length; | ||
else if (type === BooleanType) return (this ? 1 : 0); | ||
else if (type === NumberType && this === this) return this; | ||
}, | ||
string: function () { | ||
return toString.call(this) === types.str; | ||
return toString.call(this) === StringType; | ||
}, | ||
@@ -265,3 +281,3 @@ type: function () { | ||
minor(String.prototype, { | ||
minor(StringPrototype, { | ||
capitalize: function () { | ||
@@ -280,11 +296,10 @@ return this.charAt(0).toUpperCase() + this.substring(1); | ||
if ( | ||
regex.surrogatePair.test(current) || | ||
regex.symbolWithCombiningMarks.test(current) | ||
SurrogatePair.test(current) || | ||
SymbolWithCombiningMarks.test(current) | ||
) { | ||
output.push(current); | ||
index++; | ||
} else { | ||
output.push(this.substr(index, 1)); | ||
} | ||
} else output.push(this.substr(index, 1)); | ||
} | ||
return output; | ||
@@ -296,11 +311,8 @@ }, | ||
if ( | ||
regex.crlf.test(end) || | ||
regex.surrogatePair.test(end) || | ||
regex.symbolWithCombiningMarks.test(end) | ||
) { | ||
return this.substr(0, length - 2); | ||
} else { | ||
return this.substring(0, length - 1); | ||
} | ||
return ( | ||
CRLF.test(end) || | ||
SurrogatePair.test(end) || | ||
SymbolWithCombiningMarks.test(end) | ||
) ? this.substr(0, length - 2) : | ||
this.substring(0, length - 1); | ||
}, | ||
@@ -310,8 +322,5 @@ chr: function () { | ||
if (regex.surrogatePair.test(front) || | ||
regex.symbolWithCombiningMarks.test(front)) { | ||
return front; | ||
} else { | ||
return this.charAt(0); | ||
} | ||
return (SurrogatePair.test(front) || | ||
SymbolWithCombiningMarks.test(front)) ? | ||
front : this.charAt(0); | ||
}, | ||
@@ -324,25 +333,21 @@ downcase: function () { | ||
}, | ||
reverse: (function () { | ||
reverse: function esrever () { | ||
// Credit Mathias Bynens, github.com/mathiasbynens/esrever | ||
function rev (string) { | ||
var output = '', | ||
index; | ||
// Revised for Rubyisms | ||
var output = '', | ||
string, | ||
index; | ||
string = string | ||
.replace(regex.symbolWithCombiningMarks, function ($0, $1, $2) { | ||
return rev($2) + $1; | ||
}) | ||
.replace(regex.surrogatePair, '$2$1'); | ||
string = this | ||
.replace(SymbolWithCombiningMarks, function (_, $1, $2) { | ||
return esrever.call($2) + $1; | ||
}) | ||
.replace(SurrogatePair, '$2$1'); | ||
index = string.length; | ||
index = string.length; | ||
while (index--) output += string.charAt(index); | ||
while (index--) output += string.charAt(index); | ||
return output; | ||
} | ||
return (function () { | ||
return rev(this); | ||
}); | ||
}()), | ||
return output; | ||
}, | ||
swapcase: function () { | ||
@@ -366,3 +371,3 @@ var output = '', | ||
major(Array.prototype, { | ||
major(ArrayPrototype, { | ||
assoc: function (key) { | ||
@@ -376,6 +381,14 @@ var length = this.length, | ||
if (toString.call(current) !== types.obj) continue; | ||
if (toString.call(current) !== ObjectType) continue; | ||
if (current.hasOwnProperty(key)) return current; | ||
} | ||
}, | ||
at: function (index) { | ||
if (!index) | ||
index = 0; | ||
else if (index < 0) | ||
index = this.length + index; | ||
return this[index]; | ||
}, | ||
count: function (obtest, usefunc) { | ||
@@ -442,3 +455,3 @@ var argc = arguments.length, | ||
}, | ||
drop: Array.prototype.slice, | ||
drop: ArrayPrototype.slice, | ||
fetch: function (index, substitute) { | ||
@@ -478,3 +491,3 @@ var length = this.length, | ||
}, | ||
select: Array.prototype.filter, | ||
select: ArrayPrototype.filter, | ||
take: function (length) { | ||
@@ -490,12 +503,9 @@ return this.slice().splice(0, length); | ||
if (length) { | ||
for (; index < argc; index++) { | ||
position = arguments[index]; | ||
if (length) for (; index < argc; index++) { | ||
position = arguments[index]; | ||
if (position < 0) { | ||
position = length + position; | ||
} | ||
if (position < 0) | ||
position = length + position; | ||
output.push(this[position]); | ||
} | ||
output.push(this[position]); | ||
} | ||
@@ -515,5 +525,4 @@ | ||
for (argIndex = 0; argIndex < argc; argIndex++) { | ||
for (argIndex = 0; argIndex < argc; argIndex++) | ||
tempArray.push(arguments[argIndex][index]); | ||
} | ||
@@ -527,11 +536,11 @@ output.push(tempArray); | ||
major(Boolean.prototype, {}); | ||
major(BooleanPrototype, {}); | ||
major(Function.prototype, {}); | ||
major(FunctionPrototype, {}); | ||
major(Number.prototype, { | ||
major(NumberPrototype, { | ||
downto: function (end, callback, after) { | ||
var start = this; | ||
if (toString.call(end) !== types.num || end.toFixed() != end) | ||
if (toString.call(end) !== NumberType || end.toFixed() != end) | ||
throw new TypeError('Integer value required'); | ||
@@ -561,3 +570,3 @@ else if (start != start.toFixed() || start === Infinity) | ||
if (toString.call(end) !== types.num || end.toFixed() != end) | ||
if (toString.call(end) !== NumberType || end.toFixed() != end) | ||
throw new TypeError('Integer value required'); | ||
@@ -575,7 +584,7 @@ else if (start != start.toFixed() || start === Infinity) | ||
major(Object.prototype, { | ||
major(ObjectPrototype, { | ||
each: function (callback, after) { | ||
var keys, length, index, property; | ||
if (toString.call(this) !== types.obj) | ||
if (toString.call(this) !== ObjectType) | ||
return; | ||
@@ -600,3 +609,3 @@ else if (typeof callback !== 'function') | ||
fetch: function (key, substitute) { | ||
if (toString.call(this) !== types.obj) | ||
if (toString.call(this) !== ObjectType) | ||
return; | ||
@@ -613,3 +622,3 @@ else if (arguments.length < 1) | ||
major(String.prototype, { | ||
major(StringPrototype, { | ||
each: function (callback, after) { | ||
@@ -616,0 +625,0 @@ var length, |
@@ -1,11 +0,14 @@ | ||
var chai = require('chai'), | ||
assert = chai.assert, | ||
expect = chai.expect, | ||
should = chai.should(); | ||
/* globals describe, it */ | ||
/* jshint -W030 */ | ||
var | ||
chai = require('chai'), | ||
assert = chai.assert, | ||
expect = chai.expect; | ||
chai.should(); | ||
require('../'); | ||
describe('Arrays', function () { | ||
// Minor methods | ||
describe('Arrays::MinorMethods', function () { | ||
describe('#clear', function () { | ||
@@ -21,3 +24,3 @@ it('should empty the array in place', function () { | ||
describe('#compact', function () { | ||
var foo = [1, 2, undefined, 3]; | ||
var foo = [1, 2, undefined, 3], | ||
bar = foo.compact; | ||
@@ -50,2 +53,36 @@ | ||
describe('#first', function () { | ||
var foo = ['z', 'y', 'x']; | ||
it('should return the first element of the array', function () { | ||
expect(foo.first).to.equal('z'); | ||
}); | ||
it('should not alter the original array', function () { | ||
expect(foo.first).to.equal('z'); | ||
assert.deepEqual(foo, ['z', 'y', 'x']); | ||
}); | ||
it('should return undefined on empty arrays', function () { | ||
expect([].first).to.be.undefined; | ||
}); | ||
}); | ||
describe('#last', function () { | ||
var foo = ['a', 'b', 'c']; | ||
it('should return the last element of the array', function () { | ||
expect(foo.last).to.equal('c'); | ||
}); | ||
it('should not alter the original array', function () { | ||
expect(foo.last).to.equal('c'); | ||
assert.deepEqual(foo, ['a', 'b', 'c']); | ||
}); | ||
it('should return undefined on empty arrays', function () { | ||
expect([].last).to.be.undefined; | ||
}); | ||
}); | ||
describe('#sample', function () { | ||
@@ -111,4 +148,4 @@ var foo = ['a', 'b'], | ||
// Major methods | ||
}); | ||
describe('Arrays::MajorMethods', function () { | ||
describe('#assoc()', function () { | ||
@@ -127,2 +164,26 @@ var foo = [{a: 1}, 'bar', {b: 2}, {b: 4}], | ||
describe('#at()', function () { | ||
var foo = ['a', 'b', 'c']; | ||
it('should return the value at the specified index', function () { | ||
expect(foo.at(2)).to.equal('c'); | ||
expect(foo.at(1)).to.equal('b'); | ||
expect(foo.at(0)).to.equal('a'); | ||
}); | ||
it('should calculate from the end of self, if index is negative', function () { | ||
expect(foo.at(-1)).to.equal('c'); | ||
expect(foo.at(-2)).to.equal('b'); | ||
expect(foo.at(-3)).to.equal('a'); | ||
}); | ||
it('should return the first element if no index given', function () { | ||
expect(foo.at()).to.equal('a'); | ||
}); | ||
it('should not alter the original array', function () { | ||
assert.deepEqual(foo, ['a', 'b', 'c']); | ||
}); | ||
}); | ||
describe('#count()', function () { | ||
@@ -129,0 +190,0 @@ var f = function () {}, |
@@ -1,11 +0,14 @@ | ||
var chai = require('chai'), | ||
assert = chai.assert, | ||
expect = chai.expect, | ||
should = chai.should(); | ||
/* globals describe, it */ | ||
/* jshint -W030 */ | ||
var | ||
chai = require('chai'), | ||
// assert = chai.assert, | ||
expect = chai.expect; | ||
chai.should(); | ||
require('../'); | ||
describe('Booleans', function () { | ||
// Minor methods | ||
describe('Booleans::MinorMethods', function () { | ||
describe('#not', function () { | ||
@@ -18,6 +21,4 @@ it('should return the inverse value', function () { | ||
expect(f.not).to.be.true; | ||
}) | ||
}); | ||
}); | ||
// Major methods | ||
}); | ||
}); |
@@ -1,11 +0,14 @@ | ||
var chai = require('chai'), | ||
assert = chai.assert, | ||
expect = chai.expect, | ||
should = chai.should(); | ||
/* globals describe, it */ | ||
/* jshint -W030 */ | ||
var | ||
chai = require('chai'), | ||
// assert = chai.assert, | ||
expect = chai.expect; | ||
chai.should(); | ||
require('../'); | ||
describe('Functions', function () { | ||
// Minor methods | ||
describe('Functions::MinorMethods', function () { | ||
describe('#clone', function () { | ||
@@ -19,3 +22,2 @@ var test = function () { | ||
expect(copy.call()).to.equal('hello'); | ||
copy.should.not.equal(test); | ||
}); | ||
@@ -25,6 +27,5 @@ | ||
expect(test.call()).to.equal('hello'); | ||
copy.should.not.equal(test); | ||
}); | ||
}); | ||
// Major methods | ||
}); | ||
}); |
@@ -1,11 +0,14 @@ | ||
var chai = require('chai'), | ||
assert = chai.assert, | ||
expect = chai.expect, | ||
should = chai.should(); | ||
/* globals describe, it */ | ||
/* jshint -W030 */ | ||
var | ||
chai = require('chai'), | ||
assert = chai.assert, | ||
expect = chai.expect; | ||
chai.should(); | ||
require('../'); | ||
describe('Numbers', function () { | ||
// Minor methods | ||
describe('Numbers::MinorMethods', function () { | ||
var zero = 0, | ||
@@ -105,5 +108,5 @@ one = 1, | ||
it('should throw TypeError if self is not integer value', function () { | ||
expect(function () {f.next}).to.throw(TypeError); | ||
expect(function () {NaN.next}).to.throw(TypeError); | ||
expect(function () {Infinity.next}).to.throw(TypeError); | ||
expect(function () { return f.next; }).to.throw(TypeError); | ||
expect(function () { return NaN.next; }).to.throw(TypeError); | ||
expect(function () { return Infinity.next; }).to.throw(TypeError); | ||
}); | ||
@@ -151,5 +154,5 @@ | ||
it('should throw TypeError if self is not integer value', function () { | ||
expect(function () {f.pred}).to.throw(TypeError); | ||
expect(function () {NaN.pred}).to.throw(TypeError); | ||
expect(function () {Infinity.pred}).to.throw(TypeError); | ||
expect(function () { return f.pred; }).to.throw(TypeError); | ||
expect(function () { return NaN.pred;}).to.throw(TypeError); | ||
expect(function () { return Infinity.pred; }).to.throw(TypeError); | ||
}); | ||
@@ -167,4 +170,4 @@ | ||
expect(negf.round).to.eql(-3) | ||
expect(posf.round).to.eql(12) | ||
expect(negf.round).to.eql(-3); | ||
expect(posf.round).to.eql(12); | ||
}); | ||
@@ -183,5 +186,5 @@ }); | ||
}); | ||
}); | ||
// Major methods | ||
describe('Numbers::MajorMethods', function () { | ||
describe('#downto()', function () { | ||
@@ -188,0 +191,0 @@ var i = 20, |
@@ -1,13 +0,17 @@ | ||
var chai = require('chai'), | ||
assert = chai.assert, | ||
expect = chai.expect, | ||
should = chai.should(); | ||
/* globals describe, it */ | ||
/* jshint -W030 */ | ||
var | ||
chai = require('chai'), | ||
// assert = chai.assert, | ||
expect = chai.expect; | ||
chai.should(); | ||
require('../'); | ||
describe('Objects', function () { | ||
// Minor methods | ||
describe('Objects::MinorMethods', function () { | ||
var a = [1, 'bar', 3, undefined, 5], | ||
b = true, | ||
f = function (one, two) {}, | ||
f = function (one, two) { one * two; }, | ||
n = 5, | ||
@@ -49,7 +53,7 @@ o = {a: 1, b: 2}, | ||
it('should return undefined for non-objects. Strings & Arrays excempt.', function () { | ||
expect(a.empty).to.false; | ||
if (expect(a.empty).to.false); | ||
expect(b.empty).to.equal(undefined); | ||
expect(f.empty).to.equal(undefined); | ||
expect(n.empty).to.equal(undefined); | ||
expect(s.empty).to.be.false; | ||
if (expect(s.empty).to.be.false); | ||
}); | ||
@@ -102,3 +106,3 @@ }); | ||
expect(false.size).to.equal(0); | ||
}) | ||
}); | ||
@@ -110,3 +114,3 @@ it('should return the number of arguments a function has defined', function () { | ||
it('should return the length of an objects properties', function () { | ||
expect(o.size).to.equal(2) | ||
expect(o.size).to.equal(2); | ||
}); | ||
@@ -118,6 +122,5 @@ | ||
expect(Infinity.size).to.equal(Infinity); | ||
}) | ||
}); | ||
}); | ||
describe('#string', function () { | ||
@@ -131,2 +134,3 @@ it('should return true if object is string, false otherwise', function () { | ||
expect(s.string).to.be.true; | ||
/* jshint -W053 */ | ||
expect(new String('hello').string).to.be.true; | ||
@@ -149,4 +153,12 @@ }); | ||
// Major methods | ||
}); | ||
describe('Objects::MajorMethods', function () { | ||
var a = [1, 'bar', 3, undefined, 5], | ||
b = true, | ||
f = function (one, two) { one * two; }, | ||
n = 5, | ||
o = {a: 1, b: 2}, | ||
s = 'foo'; | ||
describe('#each()', function () { | ||
@@ -216,2 +228,3 @@ var o2 = {a: 1, b: 2, c: 3}, | ||
expect(s.eql('foo')).to.be.true; | ||
/* jshint -W053 */ | ||
expect(s.eql(new String('foo'))).to.be.false; | ||
@@ -226,3 +239,3 @@ }); | ||
c: true | ||
}, | ||
}, | ||
o2 = {}; | ||
@@ -237,3 +250,3 @@ | ||
it('should throw error when no value given', function () { | ||
expect(function () {o.fetch()}).to.throw(Error); | ||
expect(function () { o.fetch(); }).to.throw(Error); | ||
}); | ||
@@ -259,3 +272,3 @@ | ||
}); | ||
}) | ||
}); | ||
}); | ||
}); |
@@ -1,11 +0,14 @@ | ||
var chai = require('chai'), | ||
assert = chai.assert, | ||
expect = chai.expect, | ||
should = chai.should(); | ||
/* globals describe, it */ | ||
/* jshint -W030 */ | ||
var | ||
chai = require('chai'), | ||
assert = chai.assert, | ||
expect = chai.expect; | ||
chai.should(); | ||
require('../'); | ||
describe('Strings', function () { | ||
// Minor methods | ||
describe('Strings::MinorMethods', function () { | ||
var oddity = '𝌆 bar mañana mañana'; | ||
@@ -153,4 +156,5 @@ | ||
// Major methods | ||
}); | ||
describe('Strings::MajorMethods', function () { | ||
describe('#each()', function () { | ||
@@ -157,0 +161,0 @@ var foo = 'hello', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
280498
28
1467