Skip to content

Commit

Permalink
Fixed conflict issue with Mongoose.
Browse files Browse the repository at this point in the history
Fixes issue /issues/1
  • Loading branch information
Albert-IV committed Apr 11, 2014
1 parent aa2418f commit 6170afa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ This combines the two arrays together. This does alter the original array, as w
OBJECTS
-------------------------
###Object.prototype.get()
###Object.prototype.peel()
```javascript
var obj = { name : { first : "Al", last : "Bundy" } };
obj.get('name.last'); // returns "Bundy"
obj.get('path.not.in.object'); // Returns 0
obj.peel('name.last'); // returns "Bundy"
obj.peel('path.not.in.object'); // Returns 0
```
This allows you to reach into objects and get their values, if it exists. If it doesn't, will return 0. The advantage of this is you avoid a dreaded `obj.name && obj.name.first` situation, and not have to worry about a malformed object blowing up your application.
Expand Down
6 changes: 3 additions & 3 deletions extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
return function(deltaDate) {
if( typeof deltaDate == "string" ) deltaDate = new Date(deltaDate);
if( !this.isDate() || !deltaDate.isDate() ) return {};

// Get # of milliseconds between dates
var delta = this.getTime() > deltaDate.getTime() ?
this.getTime() - deltaDate.getTime() :
Expand All @@ -28,7 +28,7 @@
var toSecond = function(d) { return Math.floor( d / 1000 ); }
, secondToMilli = function(d) { return d * 1000; }

, toMinute = function(d) { return Math.floor( d / 1000 / 60 ); }
, toMinute = function(d) { return Math.floor( d / 1000 / 60 ); }
, minuteToMilli = function(d) { return d * 1000 * 60; }

, toHour = function(d) { return Math.floor( d / 1000 / 60 / 60 ); }
Expand Down Expand Up @@ -82,7 +82,7 @@
}
})();

OBJ_EXT.get = (function() {
OBJ_EXT.peel = (function() {
var _get = function(obj, path) {
var key = path.shift(),
lb, rb, idx, val;
Expand Down
33 changes: 17 additions & 16 deletions tests/tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require('../extensions.js')
"use strict";
require('../extensions.js');

var should = require('should');
// var mongoose = require('mongoose');
var mongoose = require('mongoose');

describe('Date.prototype', function() {
var date = new Date(2000, 0, 1),
Expand All @@ -24,7 +25,7 @@ describe('Date.prototype', function() {

( objectIsDateCode ).should.be.ok;
( typeof objectIsDateCode ).should.equal( "function" );

( arrayIsDateCode ).should.be.ok;
( typeof arrayIsDateCode ).should.equal( "function" );

Expand All @@ -34,7 +35,7 @@ describe('Date.prototype', function() {

it('.getLabel should return function', function() {
var getLabelCode = new Date().getLabel;

( getLabelCode ).should.be.ok;
( typeof getLabelCode ).should.equal( "function" );
});
Expand Down Expand Up @@ -109,34 +110,34 @@ describe('Array.prototype', function() {

describe('Object.prototype', function() {

it('.get should return function', function() {
var getFunction = {}.get;
it('.peel should return function', function() {
var getFunction = {}.peel;

( getFunction ).should.be.ok;
( typeof getFunction ).should.equal( "function" );
});

it('.get() on obj.key should work', function() {
it('.peel() on obj.key should work', function() {
var obj = { foo : "bar" };

( obj.get("foo") ).should.equal('bar');
( typeof obj.get("name") ).should.equal( "undefined" );
( obj.peel("foo") ).should.equal('bar');
( typeof obj.peel("name") ).should.equal( "undefined" );
});

it('.get() o obj.key[i] should work', function() {
it('.peel() o obj.key[i] should work', function() {
var obj = { arr : [ "string"] };

( obj.get("arr[0]") ).should.equal( "string" );
( typeof obj.get("arr[2]") ).should.equal( "undefined" );
( obj.peel("arr[0]") ).should.equal( "string" );
( typeof obj.peel("arr[2]") ).should.equal( "undefined" );
});

it('.get() should work on arrays too!', function() {
it('.peel() should work on arrays too!', function() {
var obj = { arr : [ ]}
var arrObj = [ "string", { name : 'Jim' } ];

( arrObj.get('[0]') ).should.equal( "string" );
( arrObj.get('[1]') ).should.eql( { name : "Jim" } );
( typeof arrObj.get('[3]') ).should.equal( "undefined" );
( arrObj.peel('[0]') ).should.equal( "string" );
( arrObj.peel('[1]') ).should.eql( { name : "Jim" } );
( typeof arrObj.peel('[3]') ).should.equal( "undefined" );
});

/*
Expand Down

0 comments on commit 6170afa

Please sign in to comment.