Socket
Socket
Sign inDemoInstall

protoblast

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protoblast - npm Package Compare versions

Comparing version 0.1.11 to 0.1.12

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## 0.1.12 (2016-02-03)
* Begin adding NW.js support
* `Date#format('L')` now returns a boolean instead of a string
* Always modify prototypes of classes made by Protoblast itself (URL fixes)
## 0.1.11 (2016-01-08)

@@ -2,0 +8,0 @@

6

lib/date_format.js

@@ -51,3 +51,3 @@ /**

* @since 0.1.4
* @version 0.1.4
* @version 0.1.12
*

@@ -59,2 +59,6 @@ * @return {String}

if (pattern == 'L' || pattern == 'I') {
return methods[pattern].call(this);
}
return pattern.replace(/(\\?)(.)/g, function(_, esc, chr) {

@@ -61,0 +65,0 @@ return (esc === '' && methods[chr]) ? methods[chr].call(date) : chr;

@@ -13,4 +13,15 @@ module.exports = function BlastInit(modifyPrototype) {

// Is it a pure, regular browser?
Blast.isBrowser = false;
// Is it running in a node context?
Blast.isNode = false;
// Is it running in NW.js?
Blast.isNW = false;
// Is it running in a NW.js window?
Blast.isNWWindow = false;
// If it's a browser, is it IE?
Blast.isIE = false;

@@ -24,10 +35,13 @@ Blast.__init = BlastInit;

if (typeof window !== 'undefined') {
if (typeof process === 'object' && (process.__node_webkit || process.__nwjs)) {
Blast.isNW = true;
Blast.isNode = true;
Globals = global;
} else if (typeof window !== 'undefined') {
Globals = window;
Blast.isBrowser = true;
if (window.navigator && navigator.userAgent) {
Blast.isIE = (navigator.userAgent.indexOf('MSIE') > -1 || navigator.userAgent.indexOf('Trident/') > -1);
if (window.navigator && window.navigator.userAgent) {
Blast.isIE = (window.navigator.userAgent.indexOf('MSIE') > -1 || window.navigator.userAgent.indexOf('Trident/') > -1);
}
} else {

@@ -38,2 +52,8 @@ Globals = global;

// NW.js offers 2 contexts: node & chromium
if (false && Blast.isNW && typeof window !== 'undefined') {
Globals = window;
Blast.isNWWindow = true;
}
Blast.Globals = Globals;

@@ -51,2 +71,8 @@

// Store shims under unit_test object
// when unit testing
if (module.exports.unit_test) {
Blast.Shims = {};
}
Globals.__Protoblast = Blast;

@@ -224,3 +250,3 @@

* @since 0.1.2
* @version 0.1.4
* @version 0.1.12
*/

@@ -234,4 +260,10 @@ Blast.defineClass = function defineClass(className, constructor, shim) {

} else {
// Indicate this defined class belongs to protoblast
Blast.defineValue(constructor, '_blast_class', true);
// Store the new constructor in the classes object
Blast.Classes[className] = constructor;
// If we're allowed to modify prototypes, turn it into a global
if (Blast.modifyPrototype) {

@@ -282,3 +314,3 @@ Globals[className] = constructor;

* @since 0.1.0
* @version 0.1.9
* @version 0.1.12
*

@@ -339,2 +371,11 @@ * @param {Object} target The object to add the property to

if (shim && Blast.Shims) {
Blast.Shims[(className || targetClass.name) + '#' + name] = value;
// Force overwrite while unit testing
if (module.exports.unit_test) {
shim = false;
}
}
if (Blast.modifyPrototype) {

@@ -350,3 +391,3 @@

}
} else if (shim && !targetClass.prototype[name]) {
} else if (targetClass._blast_class || (shim && !targetClass.prototype[name])) {
definer(targetClass.prototype, name, value);

@@ -414,2 +455,11 @@ }

if (shim && Blast.Shims) {
Blast.Shims[(className || targetClass.name) + '.' + name] = value;
// Force overwrite while unit testing
if (module.exports.unit_test) {
shim = false;
}
}
if (Blast.modifyPrototype) {

@@ -416,0 +466,0 @@ // Only set if it's not a shim, or if it's not there

94

lib/url.js

@@ -5,3 +5,3 @@ module.exports = function BlastURL(Blast, Collection) {

liburl,
URL;
NewURL;

@@ -16,3 +16,3 @@ /**

*/
URL = Blast.defineClass('URL', function URL(url) {
NewURL = Blast.defineClass('URL', function URL(url) {

@@ -36,3 +36,7 @@ var auth;

// Parse the url
this.parse(url);
if (this.parse) {
this.parse(url);
} else {
parse.call(this, url);
}

@@ -57,3 +61,2 @@ // Add the origin

this.slashes = undefined;
}, true);

@@ -63,33 +66,13 @@

if (Blast.isIE || typeof _cordovaNative != 'undefined') {
Blast.Classes.URL = URL;
Blast.Classes.URL = NewURL;
Blast.Bound.URL = {};
Blast.Collection.URL = URL;
Blast.Collection.URL = NewURL;
Blast.definePrototype(URL, 'parse', function parse(url) {
var anchor,
temp;
if (url && url.href) {
url = ''+url.href;
}
temp = document.createElement('a');
temp.href = url;
anchor = document.createElement('a');
anchor.href = ''+temp;
// Add the properties of the anchor to our instance
Object.assign(this, anchor);
// Remove the injected toString
this.toString = Blast.Classes.URL.prototype.toString;
});
Blast.definePrototype(NewURL, 'parse', protoParse);
} else if (!Blast.isNode) {
// Detect broken URL constructor objects
if (Object.prototype.toString.call(window.URL) == '[object URLConstructor]') {
Blast.Classes.URL = URL;
Blast.Classes.URL = NewURL;
Blast.Bound.URL = {};
Blast.Collection.URL = URL;
Blast.Collection.URL = NewURL;
}

@@ -99,3 +82,3 @@ }

// Add the URL-module prototype methods
if (Blast.isNode) {
if (Blast.isNode && !Blast.isNWWindow) {
liburl = require('url');

@@ -107,2 +90,36 @@ Blast.Classes.URL.prototype = Object.create(liburl.Url.prototype);

* Parse a url string.
* For use inside the prototype
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.1.3
* @version 0.1.12
*
* @param {String} url
*
* @return {URL}
*/
function parse(url) {
var anchor,
temp;
if (url && url.href) {
url = ''+url.href;
}
temp = document.createElement('a');
temp.href = url;
anchor = document.createElement('a');
anchor.href = ''+temp;
// Add the properties of the anchor to our instance
Object.assign(this, anchor);
// Remove the injected toString
this.toString = Blast.Classes.URL.prototype.toString;
}
/**
* Parse a url string.
* Same as 'new Url()'

@@ -112,3 +129,3 @@ *

* @since 0.1.3
* @version 0.1.4
* @version 0.1.12
*

@@ -130,3 +147,3 @@ * @param {String} url

result = new URL(url);
result = new NewURL(url);
} else {

@@ -149,7 +166,7 @@

* @since 0.1.3
* @version 0.1.4
* @version 0.1.12
*
* @return {String}
*/
Blast.definePrototype('URL', 'toString', function toString() {
function toString() {

@@ -189,4 +206,11 @@ var result = '';

return result;
}, true);
}
if (Blast.isNW || Blast.isNode) {
// Force our version of toString
Blast.definePrototype('URL', 'toString', toString);
} else {
Blast.definePrototype('URL', 'toString', toString, true);
}
/**

@@ -193,0 +217,0 @@ * Clone this URL object

{
"name": "protoblast",
"description": "Add useful methods to native objects",
"version": "0.1.11",
"version": "0.1.12",
"author": "Jelle De Loecker <jelle@develry.be>",
"keywords": ["prototype", "util", "functional", "server", "client", "browser"],
"keywords": [
"prototype",
"util",
"functional",
"server",
"client",
"browser"
],
"repository": "skerit/protoblast",

@@ -14,6 +21,7 @@ "homepage": "http://protoblast.develry.be/",

"devDependencies": {
"browserify": "5.11.0",
"coveralls": "^2.11.6",
"git-rev": "0.2.1",
"matcha": "skerit/matcha",
"mocha": "1.20.x",
"git-rev": "0.2.1",
"browserify": "5.11.0",
"wd": "0.3.x"

@@ -24,2 +32,2 @@ },

}
}
}
# ![protoblast](http://protoblast.develry.be/media/static/protoblast-small.svg?width=30) Protoblast
[![NPM version](http://img.shields.io/npm/v/protoblast.svg)](https://npmjs.org/package/protoblast)
[![Build Status](https://secure.travis-ci.org/skerit/protoblast.png?branch=master)](http://travis-ci.org/skerit/protoblast)
[![Build Status](https://secure.travis-ci.org/skerit/protoblast.png?branch=master)](http://travis-ci.org/skerit/protoblast)
[![Coverage Status](https://coveralls.io/repos/github/skerit/protoblast/badge.svg?branch=master)](https://coveralls.io/github/skerit/protoblast?branch=master)

@@ -6,0 +7,0 @@ Extend native objects with helpful methods to speed up development,

@@ -6,5 +6,9 @@ var assert = require('assert');

var Blast = require('../index.js'),
blastObj = Blast(false),
blastObj,
modifiedProto;
Blast.unit_test = true;
blastObj = Blast(false);
modifiedProto = !!(String.prototype.startsWith && Object.divide);

@@ -11,0 +15,0 @@

@@ -611,2 +611,14 @@ var assert = require('assert'),

});
it('cast the variables before subtracting', function() {
var a = [0,1,2,47,99,100.5],
subtract;
// This should cast the 100.5 to 100 before matching
subtract = a.subtract(100, parseInt);
// The order of the subtraction is important
assert.equal(subtract.length, 5);
});
});

@@ -613,0 +625,0 @@

@@ -59,3 +59,82 @@ var assert = require('assert'),

});
});
describe('#format()', function() {
var date = new Date('2015-08-26T14:39:05.745Z');
it('should format the date using the specified methos', function() {
var a = new Date(date),
b = new Date('2016-08-26T14:39:05.745Z'),
c = new Date('2016-01-01T18:39:05.745Z'),
d = new Date('2016-08-26T06:39:05.745Z'),
e = new Date('2016-01-26T06:39:05.745Z'),
f = new Date('2016-01-03T06:39:05.745Z'),
g = new Date('2016-10-26T06:39:05.745Z')
// Days
assert.equal(a.format('d'), '26');
assert.equal(c.format('d'), '01');
assert.equal(a.format('j'), '26');
assert.equal(c.format('j'), '1');
assert.equal(c.format('D'), 'Fri');
assert.equal(c.format('l'), 'Friday');
assert.equal(c.format('N'), '5');
assert.equal(f.format('N'), '7', 'Sunday should return 7');
assert.equal(f.format('w'), '0', 'Sunday should return 0');
assert.equal(c.format('S'), 'st');
assert.equal(b.format('S'), 'th');
assert.equal(c.format('z'), '1');
assert.equal(e.format('z'), '26');
assert.equal(e.format('W'), '4');
assert.equal(c.format('W'), '53');
// Months
assert.equal(a.format('F'), 'August', 'Should return the full month name');
assert.equal(a.format('m'), '08', 'Should return zero-padded month number');
assert.equal(g.format('m'), '10', 'Should return zero-padded month number');
assert.equal(a.format('M'), 'Aug', 'Should return short month name');
assert.equal(a.format('n'), '8', 'Should return month number');
assert.equal(a.format('t'), '31', 'Should return days in the month');
// Years
assert.equal(a.format('L'), false, 'Should return false: 2015 is not a leap year');
assert.equal(b.format('L'), true, 'Should return true: 2016 is a leap year');
assert.equal(c.format('o'), '2015', 'The week is part of the previous year, so that year should be returned');
assert.equal(a.format('Y'), '2015', 'Should return the full year');
assert.equal(a.format('y'), '15', 'Should return the year in 2-digits');
// Time
assert.equal(a.format('a'), 'pm', 'Should return pm');
assert.equal(a.format('A'), 'PM', 'Should return PM');
assert.equal(d.format('a'), 'am', 'Should return am');
assert.equal(d.format('A'), 'AM', 'Should return AM');
assert.equal(a.format('B'), '652', 'Should return the swatch time');
// Skip hour tests, because of timezone stuff
// assert.equal(a.format('g'), '2');
// assert.equal(a.format('G'), '14');
// assert.equal(a.format('h'), '02');
// assert.equal(a.format('H'), '14');
assert.equal(a.format('i'), '39');
assert.equal(a.format('s'), '05');
assert.equal(a.format('u'), '745');
// Timezone
assert.equal(a.format('e'), 'Not Yet Supported');
//assert.equal(a.format('I'), true, 'DST should be true');
//assert.equal(e.format('I'), false, 'DST should be false');
assert.equal(e.format('O'), '+0100', 'Difference to GMT');
assert.equal(e.format('P'), '+01:00', 'Difference to GMT with colon');
// Date/Time
assert.equal(a.format('c'), '2015-08-26T16:39:05+02:00');
assert.equal(a.format('r'), 'Wed Aug 26 2015 16:39:05 GMT+0200 (CEST)');
assert.equal(e.format('U'), '1453790345.745');
});
});

@@ -62,0 +141,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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