🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

win-utils

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

win-utils - npm Package Compare versions

Comparing version
0.0.3
to
0.1.0
+98
test/simple.js
//here we test the insert functions
//making sure the database is filled with objects of the schema type
var assert = require('assert');
var should = require('should');
var utils = require('../');
var uuid = utils.cuid;
describe('Testing win-utils uuid -',function(){
//if we need to do something beforehand
before(function(done){
done();
});
it('Should return less than for IDs generated after each other',function(done){
var ids = [];
var superCount = 1000;//Math.pow(36, 4) + 35;
for(var i=0; i < superCount; i++)
ids.push(uuid());
for(var i=0; i < ids.length-1; i++)
{
// console.log("Id: ", ids[i], " above: ", ids[i+1]);
var lt = uuid.isLessThan(ids[i], ids[i+1]);
if(!lt)
{
console.log("Less than fail: ", i, " first: ", ids[i], " second: ", ids[i+1]);
}
lt.should.equal(true);
}
done();
});
it('Should return less than for number IDs generated before string IDs -- backwards compat',function(done){
var superCount = 1000;
for(var i=0; i < superCount; i++)
{
// console.log("Id: ", ids[i], " above: ", ids[i+1]);
var lt = "" + Math.random()*10000000;
var ltPlus = "" + parseInt(lt) + 10;
var gt = uuid();
var compare = uuid.isLessThan(lt, gt);
compare.should.equal(true);
compare = uuid.isLessThan(gt, lt);
compare.should.equal(false);
compare = uuid.isLessThan(gt, gt);
compare.should.equal(false);
}
done();
});
it('Should compare numbers to numbers -- backwards compat',function(done){
var superCount = 1000;
for(var i=0; i < superCount; i++)
{
// console.log("Id: ", ids[i], " above: ", ids[i+1]);
var lt = "" + Math.random()*10000000;
var ltPlus = "" + parseInt(lt) + 10;
compare = uuid.isLessThan(lt, ltPlus);
compare.should.equal(true);
compare = uuid.isLessThan(ltPlus, lt);
compare.should.equal(false);
compare = uuid.isLessThan(lt, lt);
compare.should.equal(false);
compare = uuid.isLessThan(ltPlus, ltPlus);
compare.should.equal(false);
}
done();
});
});
+1
-1
{
"name": "win-base",
"version": "0.0.3",
"version": "0.1.0",
"description": "Helper libraries for the winjs evolutionary library",
"main": "winutils.js"
}
{
"name": "win-utils",
"version": "0.0.3",
"version": "0.1.0",
"description": "Helper libraries for the winjs evolutionary library",

@@ -5,0 +5,0 @@ "scripts": [

{
"name": "win-utils",
"version": "0.0.3",
"version": "0.1.0",
"description": "Helper libraries for the win evolutionary library. Built for NPM/Component.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -118,3 +118,44 @@ /**

api.isLessThan = function(first, second)
{
var fParse= parseInt(first);
var sParse = parseInt(second);
if(isNaN(fParse) && isNaN(sParse))
{
//tease apart first, second to determine which ID came first
//counter + fingerprint + random = 6 blocks of 4 = 24
var dateEnd = 6*blockSize;
var counterEnd = 5*blockSize;
var charStart = 1;
//convert the base-36 time string to base 10 number -- parseint handles this by sending in the original radix
var firstTime = parseInt(first.slice(charStart, first.length - dateEnd), base);
//ditto for counter
var firstCounter = parseInt(first.slice(first.length - dateEnd, first.length - counterEnd),base);
//convert the base-36 time string to base 10 number -- parseint handles this by sending in the original radix
var secondTime = parseInt(second.slice(charStart, second.length - dateEnd), base);
//ditto for counter
var secondCounter = parseInt(second.slice(second.length - dateEnd, second.length - counterEnd), base);
//either the first time is less than the second time, and we answer this question immediately
//or the times are equal -- then we pull the lower counter
//techincially counters can wrap, but this won't happen very often AND this is all for measuring disjoint/excess behavior
//the time should be enough of an ordering principal for this not to matter
return firstTime < secondTime || (firstTime == secondTime && firstCounter < secondCounter);
}
else if(isNaN(sParse))
{
//if sParse is a string, then the first is a number and the second is a string UUID
//to maintain backwards compat -- number come before strings in neatjs ordering
return true;
}//both are not NaN -- we have two numbers to compare
else
{
return fParse < sParse;
}
}
//we send out API

@@ -121,0 +162,0 @@ module.exports = api;