Permalink
Browse files

browserify objectid added

  • Loading branch information...
dreampulse committed Apr 21, 2014
1 parent fa9f0a8 commit 124d4f9bd83790efb14b7ff7a5537a9a7e499f55
Showing with 273 additions and 34 deletions.
  1. +2 −2 Gruntfile.js
  2. +116 −1 browser-dist/modelizer-angular.js
  3. +144 −30 browser-dist/modelizer.js
  4. +2 −0 lib/modelizer.js
  5. +6 −0 lib/objectid.js
  6. +3 −1 package.json
View
@@ -73,15 +73,15 @@ module.exports = function(grunt) {
dest : './browser-dist/modelizer.js',
options: {
require : ['q'],
alias: ['./lib/modelizer-client:modelizer']
alias: ['./lib/modelizer-client:modelizer', 'objectid-browser:./objectid']
}
},
angular : {
src : './lib/angular-client.js',
dest : './browser-dist/modelizer-angular.js',
options: {
require : ['q'],
alias: ['./lib/angular-client:modelizer']
alias: ['./lib/angular-client:modelizer', 'objectid-browser:./objectid']
}
}
}
@@ -1518,6 +1518,121 @@ process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
},{}],"H6+VjG":[function(require,module,exports){
/*
*
* Copyright (c) 2011 Justin Dearing (zippy1981@gmail.com)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) version 2 licenses.
* This software is not distributed under version 3 or later of the GPL.
*
* Version 1.0.1-dev
* Changes made by Jonathan Häberle (jonathan.haeberle@gmail.com)
* Published to BPM for browserify-usage
*
*/
/**
* Javascript class that mimics how WCF serializes a object of type MongoDB.Bson.ObjectId
* and converts between that format and the standard 24 character representation.
*/
var ObjectId = (function () {
var increment = 0;
var pid = Math.floor(Math.random() * (32767));
var machine = Math.floor(Math.random() * (16777216));
if (typeof (localStorage) != 'undefined') {
var mongoMachineId = parseInt(localStorage['mongoMachineId']);
if (mongoMachineId >= 0 && mongoMachineId <= 16777215) {
machine = Math.floor(localStorage['mongoMachineId']);
}
// Just always stick the value in.
localStorage['mongoMachineId'] = machine;
document.cookie = 'mongoMachineId=' + machine + ';expires=Tue, 19 Jan 2038 05:00:00 GMT'
}
else {
var cookieList = document.cookie.split('; ');
for (var i in cookieList) {
var cookie = cookieList[i].split('=');
if (cookie[0] == 'mongoMachineId' && cookie[1] >= 0 && cookie[1] <= 16777215) {
machine = cookie[1];
break;
}
}
document.cookie = 'mongoMachineId=' + machine + ';expires=Tue, 19 Jan 2038 05:00:00 GMT';
}
function ObjId() {
if (!(this instanceof ObjectId)) {
return new ObjectId(arguments[0], arguments[1], arguments[2], arguments[3]).toString();
}
if (typeof (arguments[0]) == 'object') {
this.timestamp = arguments[0].timestamp;
this.machine = arguments[0].machine;
this.pid = arguments[0].pid;
this.increment = arguments[0].increment;
}
else if (typeof (arguments[0]) == 'string' && arguments[0].length == 24) {
this.timestamp = Number('0x' + arguments[0].substr(0, 8)),
this.machine = Number('0x' + arguments[0].substr(8, 6)),
this.pid = Number('0x' + arguments[0].substr(14, 4)),
this.increment = Number('0x' + arguments[0].substr(18, 6))
}
else if (arguments.length == 4 && arguments[0] != null) {
this.timestamp = arguments[0];
this.machine = arguments[1];
this.pid = arguments[2];
this.increment = arguments[3];
}
else {
this.timestamp = Math.floor(new Date().valueOf() / 1000);
this.machine = machine;
this.pid = pid;
this.increment = increment++;
if (increment > 0xffffff) {
increment = 0;
}
}
};
return ObjId;
})();
ObjectId.prototype.getDate = function () {
return new Date(this.timestamp * 1000);
};
ObjectId.prototype.toArray = function () {
var strOid = this.toString();
var array = [];
var i;
for(i = 0; i < 12; i++) {
array[i] = parseInt(strOid.slice(i*2, i*2+2), 16);
}
return array;
};
/**
* Turns a WCF representation of a BSON ObjectId into a 24 character string representation.
*/
ObjectId.prototype.toString = function () {
var timestamp = this.timestamp.toString(16);
var machine = this.machine.toString(16);
var pid = this.pid.toString(16);
var increment = this.increment.toString(16);
return '00000000'.substr(0, 8 - timestamp.length) + timestamp +
'000000'.substr(0, 6 - machine.length) + machine +
'0000'.substr(0, 4 - pid.length) + pid +
'000000'.substr(0, 6 - increment.length) + increment;
};
module.exports = ObjectId;
},{}],"./objectid":[function(require,module,exports){
module.exports=require('H6+VjG');
},{}],"qLuPo1":[function(require,module,exports){
(function (process){
// vim:ts=4:sts=4:sw=4:
@@ -3461,4 +3576,4 @@ return Q;
}).call(this,require("/Users/jonathan/Projects/modelizer/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
},{"/Users/jonathan/Projects/modelizer/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":5}],"q":[function(require,module,exports){
module.exports=require('qLuPo1');
},{}]},{},["pZmObk"]);
},{}]},{},["pZmObk"])
Oops, something went wrong.

0 comments on commit 124d4f9

Please sign in to comment.