Socket
Socket
Sign inDemoInstall

oblo-util

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oblo-util - npm Package Compare versions

Comparing version 0.6.4 to 0.6.5

.history/oblo-util_20170217164949.js

2

oblo-util.d.ts

@@ -8,3 +8,3 @@ // This file is a copy of oblo-util/oblo-util.d.ts on https://github.com/borisyankov/DefinitelyTyped,

// Type definitions for oblo-util v0.6.4
// Type definitions for oblo-util v0.6.5
// Project: https://github.com/Oblosys/oblo-util

@@ -11,0 +11,0 @@ // Definitions by: Martijn Schrage <https://github.com/Oblosys/>

@@ -1,2 +0,2 @@

// oblo-util.js 0.6.4
// oblo-util.js 0.6.5

@@ -9,4 +9,4 @@ // (c) 2015-2011 Martijn M. Schrage, Oblomomov Systems

(function(util){ // Cannot have '-' in name, so use 'util' rather than the verbose 'oblo_util'
// Notes: basic modules, no active importing, mainly experiment for using npm also on client

@@ -19,18 +19,20 @@ // needs to be defined before we call it.

};
var _ = require('underscore', '_'); // underscore calls itself '_' on client
util.debug = true; // set this to false on deployment
// Call console.log with all parameters, but only when util.debug == true
util.log = function() {
if (util.debug && typeof console != 'undefined')
if (util.debug && typeof console != 'undefined') {
var log = Function.prototype.bind.call(console.log, console);
log.apply(null, Array.prototype.slice.call(arguments));
}
};
util.error = function() {
if (typeof console != 'undefined')
if (typeof console != 'undefined') {
var error = Function.prototype.bind.call(console.error, console);
error.apply(null, Array.prototype.slice.call(arguments));
}
};

@@ -42,3 +44,3 @@

};
util.square = function(x) {

@@ -51,3 +53,3 @@ return x*x;

var xs = [];
for (var i=0; i<n; i++)
for (var i=0; i<n; i++)
xs.push(_.clone(x));

@@ -63,4 +65,4 @@ return xs;

};
// pad integer with leading 0's when necessary
// pad integer with leading 0's when necessary
util.padZero = function(l, n) {

@@ -73,4 +75,4 @@ return util.pad('0', l, n);

}
// optional arg indentStr is to prefix every generated line with indentation
// optional arg indentStr is to prefix every generated line after the first with indentation
// optional arg maxDepth is to prevent hanging on circular objects

@@ -81,3 +83,3 @@ util.showJSON = function(json,indentStr,maxDepth) {

var str = '';
if (typeof json == 'undefined') {

@@ -113,7 +115,7 @@ str += 'undefined';

} else {
console.error('util.showJSON: internal error, unhandled type: \'' + typeof json + '\'');
console.error('util.showJSON: internal error, unhandled type: \'' + typeof json + '\'');
}
return str;
};
util.showTime = function(date) {

@@ -132,14 +134,14 @@ return util.padZero(2, date.getHours()) + ':' + util.padZero(2, date.getMinutes()) + ':' + util.padZero(2, date.getSeconds());

else
throw 'Exception: Incorrect date: "'+dateStr+'"';
throw new Error("Incorrect date: '"+dateStr+"'");
};
/* Set boolean DOM attribute for jQuery object $elt according to HTML standard.
* (absence denotes false, attrName=AttrName denotes true) */
* (absence denotes false, attrName=attrName denotes true) */
util.setAttr = function($elt, attrName, isSet) {
if (isSet)
if (isSet)
$elt.attr(attrName, attrName);
else
$elt.removeAttr(attrName);
$elt.removeAttr(attrName);
};
})(typeof exports == 'undefined' ? this.util={} : exports); // pass exports if we're on the server, otherwise, create object util
var util = require('./oblo-util');
describe("debug", function() {
it("defaults to true", function() {
describe('debug', function() {
it('defaults to true', function() {
expect( util.debug ).toEqual(true);

@@ -9,7 +9,37 @@ });

describe("square", function() {
it("squares positive values", function() {
describe('log', function() {
it('calls console.log when util.debug == true', function() {
console.log = jasmine.createSpy('log');
util.debug = true;
util.log('log test');
expect(console.log).toHaveBeenCalledWith('log test');
});
it('does not call console.log when util.debug == false', function() {
console.log = jasmine.createSpy('log');
util.debug = false;
util.log('log test');
expect(console.log).not.toHaveBeenCalled();
});
});
describe('error', function() {
it('calls console.error', function() {
console.log = jasmine.createSpy('log');
util.debug = true;
util.log('log test');
expect(console.log).toHaveBeenCalledWith('log test');
});
it('does not call console.log when util.debug == false', function() {
console.log = jasmine.createSpy('log');
util.debug = false;
util.log('log test');
expect(console.log).not.toHaveBeenCalled();
});
});
describe('square', function() {
it('squares positive values', function() {
expect( util.square(4.2) ).toEqual(4.2*4.2);
});
it("squares negative values", function() {
it('squares negative values', function() {
expect( util.square(-3.4) ).toEqual(3.4*3.4);

@@ -19,31 +49,31 @@ });

describe("clip", function() {
it("handles float values lower than minimum", function() {
describe('clip', function() {
it('handles float values lower than minimum', function() {
expect( util.clip(50.5, 99.5, 20) ).toEqual(50.5);
});
it("handles float value equal to minimum", function() {
it('handles float value equal to minimum', function() {
expect( util.clip(50.5, 99.5, 50.5) ).toEqual(50.5);
});
it("handles float values inside interval", function() {
it('handles float values inside interval', function() {
expect( util.clip(50.5, 99.5, 80.1) ).toEqual(80.1);
});
it("handles float value equal to maximum", function() {
it('handles float value equal to maximum', function() {
expect( util.clip(50.5, 99.5, 99.5) ).toEqual(99.5);
});
it("handles float values higher than maximum", function() {
it('handles float values higher than maximum', function() {
expect( util.clip(50.5, 99.5, 102.5) ).toEqual(99.5);
});
it("handles int values lower than minimum", function() {
it('handles int values lower than minimum', function() {
expect( util.clip(50, 100, 20) ).toEqual(50);
});
it("handles int value equal to minimum", function() {
it('handles int value equal to minimum', function() {
expect( util.clip(50, 100, 50) ).toEqual(50);
});
it("handles int values inside interval", function() {
it('handles int values inside interval', function() {
expect( util.clip(50, 100, 80) ).toEqual(80);
});
it("handles int value equal to maximum", function() {
it('handles int value equal to maximum', function() {
expect( util.clip(50, 100, 100) ).toEqual(100);
});
it("handles int values higher than maximum", function() {
it('handles int values higher than maximum', function() {
expect( util.clip(50, 100, 130) ).toEqual(100);

@@ -53,10 +83,10 @@ });

describe("replicate", function() {
it("handles positive values", function() {
describe('replicate', function() {
it('handles positive values', function() {
expect( util.replicate(3,'x') ).toEqual(['x','x','x']);
});
it("handles zero", function() {
it('handles zero', function() {
expect( util.replicate(0,'x') ).toEqual([]);
});
it("handles positive values", function() {
it('handles positive values', function() {
expect( util.replicate(-1,'x') ).toEqual([]);

@@ -66,45 +96,79 @@ });

describe("pad", function() {
it("handles extreme padding", function() {
describe('pad', function() {
it('handles extreme padding', function() {
expect( util.pad('x',35,1) ).toEqual('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1');
});
it("doesn't clip string wider than padding", function() {
it('doesn\'t clip string wider than padding', function() {
expect( util.pad('x',2,'a larger string') ).toEqual('a larger string');
});
it("ignores negative padding", function() {
it('ignores negative padding', function() {
expect( util.pad(-2,'x','some string') ).toEqual('some string');
});
});
});
describe("padZero", function() {
it("handles extreme padding", function() {
describe('padZero', function() {
it('handles extreme padding', function() {
expect( util.padZero(35,1) ).toEqual('00000000000000000000000000000000001');
});
it("doesn't clip number when wider than padding", function() {
it('doesn\'t clip number when wider than padding', function() {
expect( util.padZero(2,1234) ).toEqual('1234');
});
it("ignores negative padding", function() {
it('ignores negative padding', function() {
expect( util.padZero(-2,23) ).toEqual('23');
});
});
});
describe('addslashes', function() {
it('adds a slash to \\, " and \'', function() {
expect( util.addslashes('\\ " \'') ).toEqual('\\\\ \\" \\\'');
});
});
describe("showTime", function() {
it("shows a time", function() {
expect( util.showTime(new Date(10,1,2013,1,2,3)) ).toEqual('01:02:03');
describe('showJSON', function() {
it('shows an empty object as {}', function() {
expect( util.showJSON({}) ).toEqual('{}');
});
it("handles afternoon", function() {
expect( util.showTime(new Date(10,1,2013,13,2,3)) ).toEqual('13:02:03');
it('shows an empty array as []', function() {
expect( util.showJSON([]) ).toEqual('[]');
});
it('handles object with undefined, null, string, and array properties', function() {
obj = { p1: undefined, p2: null, p3: 'string\n', p4: [1,2] }
str = '{ p1: undefined\n'
+ ', p2: null\n'
+ ', p3: \'string\n\'\n'
+ ', p4:\n'
+ ' [ 1\n'
+ ' , 2\n'
+ ' ]\n'
+ '}'
expect( util.showJSON(obj) ).toEqual(str);
});
it('prefixes each line with indentStr', function() {
expect( util.showJSON({p1: 1, p2: 2},'XX',2) )
.toEqual('{ p1: 1\nXX, p2: 2\nXX}');
});
it('respects maxDepth for arrays and objects', function() {
expect( util.showJSON({a: [2,[3]], o: {p2:{p3:{}}}},'',2) )
.toEqual('{ a:\n [ 2\n , [...]\n ]\n, o:\n { p2:\n {...}\n }\n}');
});
});
describe("showDate", function() {
it("shows a date", function() {
expect( util.showDate(new Date(2012,0,2)) ).toEqual('02-01-2012');
describe('showTime', function() {
it('shows a time', function() {
expect( util.showTime(new Date(10,1,2013,1,2,3)) ).toEqual('01:02:03');
});
it('handles afternoon', function() {
expect( util.showTime(new Date(10,1,2013,13,2,3)) ).toEqual('13:02:03');
});
});
describe("readDate", function() {
it("reads a date", function() {
var date = util.readDate('01-03-2013');
describe('showDate', function() {
it('shows a date', function() {
expect( util.showDate(new Date(2012,0,2)) ).toEqual('02-01-2012');
});
});
describe('readDate', function() {
it('reads a date', function() {
var date = util.readDate('01-03-2013');
expect( date.getDate() ).toEqual(1);

@@ -114,3 +178,6 @@ expect( date.getMonth() ).toEqual(2);

});
it('throws an error on an invalid date string', function() {
expect( function() {util.readDate('no date');} )
.toThrow(new Error("Incorrect date: 'no date'"));
});
});
{
"name": "oblo-util",
"version": "0.6.4",
"version": "0.6.5",
"description": "Utilities module suitable for both Node.js and client-side use",

@@ -24,12 +24,14 @@ "main": "oblo-util.js",

},
"dependencies": {
"dependencies": {
"underscore": ">=1.4.3"
},
"devDependencies": {
"jasmine-node": ">=1.11"
"istanbul": "^0.4.0",
"jasmine-node": "^2.0.0",
"jquery": "^2.1.4",
"jsdom": "^7.0.1"
},
"scripts": {
"test": "jasmine-node oblo-util.spec.js"
"test": "istanbul cover --include-all-sources jasmine-node *.spec.js && istanbul report text-summary lcov"
}
}
oblo-util [![Build Status](https://travis-ci.org/Oblosys/oblo-util.svg?branch=master)](https://travis-ci.org/Oblosys/oblo-util)
=========
JavaScript utilities module, suitable for both Node.js and client-side use
JavaScript utilities module, suitable for both Node.js and client-side use. Available on npm: [www.npmjs.com/package/oblo-util](https://www.npmjs.com/package/oblo-util), install with
npm install oblo-util
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc