Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jymin

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jymin - npm Package Compare versions

Comparing version 0.2.4 to 0.2.5

scripts/json.js

230

jymin.js
/**
* _ _ ___ ____ _ _
* | |_ _ _ __ ___ (_)_ __ __ __/ _ \ |___ \ | || |
* _ | | | | | '_ ` _ \| | '_ \ \ \ / / | | | __) || || |_
* | |_| | |_| | | | | | | | | | | \ V /| |_| | / __/ |__ _|
* \___/ \__, |_| |_| |_|_|_| |_| \_/ \___(_)_____(_) |_|
* _ _ ___ ____ ____
* | |_ _ _ __ ___ (_)_ __ __ __/ _ \ |___ \ | ___|
* _ | | | | | '_ ` _ \| | '_ \ \ \ / / | | | __) | |___ \
* | |_| | |_| | | | | | | | | | | \ V /| |_| | / __/ _ ___) |
* \___/ \__, |_| |_| |_|_|_| |_| \_/ \___(_)_____(_)____/
* |___/

@@ -23,2 +23,3 @@ *

* https://github.com/zerious/jymin/blob/master/scripts/history.js
* https://github.com/zerious/jymin/blob/master/scripts/json.js
* https://github.com/zerious/jymin/blob/master/scripts/logging.js

@@ -33,3 +34,3 @@ * https://github.com/zerious/jymin/blob/master/scripts/numbers.js

this.jymin = {version: '0.2.4'};
this.jymin = {version: '0.2.5'};

@@ -254,3 +255,3 @@ /**

*/
var pad = function (
var padArray = function (
array, // Array: The array to check for items.

@@ -346,24 +347,21 @@ padToLength, // number: The minimum number of items in the array.

*/
var getUtcTimestamp = function (
var getIsoDate = function (
date // Date: Date object. (Default: now)
) {
var utcMonths = {
Jan: '01',
Feb: '02',
Mar: '03',
Apr: '04',
May: '05',
Jun: '06',
Jul: '07',
Aug: '08',
Sep: '09',
Oct: '10',
Nov: '11',
Dec: '12'
};
date = date || new Date();
var utcPattern = /^.*?(\d+) (\w+) (\d+) ([\d:]+).*?$/;
return date.toUTCString().replace(utcPattern, function (a, d, m, y, t) {
return y + '-' + utcMonths[m] + '-' + d + ' ' + t;
});
if (!date) {
date = new Date();
}
if (date.toISOString) {
date = date.toISOString();
}
else {
// Build an ISO date string manually in really old browsers.
var utcPattern = /^.*?(\d+) (\w+) (\d+) ([\d:]+).*?$/;
date = date.toUTCString().replace(utcPattern, function (a, d, m, y, t) {
m = zeroFill(date.getMonth(), 2);
t += '.' + zeroFill(date.getMilliseconds(), 3);
return y + '-' + m + '-' + d + 'T' + t + 'Z';
});
}
return date;
};

@@ -1325,2 +1323,89 @@ /**

/**
* Create JSON that doesn't necessarily have to be strict.
*/
var stringify = function (data, stack, strict) {
var reserved = /^(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with)$/;
if (data === null) {
data = 'null';
}
else if (isFunction(data)) {
if (strict) {
data = '[Function]';
}
else {
data = ensureString(data).replace(/^function \(/, 'function(');
}
}
else if (isDate(data)) {
if (strict) {
data = '"' + getIsoDate() + '"';
}
else {
data = 'new Date(' + getTime(data) + ')';
}
}
else if (isObject(data)) {
stack = stack || [];
var isCircular = false;
forEach(stack, function (item, index) {
if (item == data) {
isCircular = true;
}
});
if (isCircular) {
return null;
}
push(stack, data);
var parts = [];
if (isArray(data)) {
forEach(data, function (value) {
push(parts, stringify(value, stack, strict));
});
}
else {
forIn(data, function (key, value) {
if (strict || reserved.test(key)) {
key = '"' + key + '"';
}
push(parts, key + ':' + stringify(value, stack, strict));
});
}
pop(stack);
data = '{' + parts.join(',') + '}';
}
else if (isString(data) && stack) {
data = '"' + data.replace(/"/g, '\\"') + '"';
}
else {
data = '' + data;
}
return data;
};
/**
* Parse JavaScript.
*/
var parse = function (text) {
if (text[0] == '{' || text[0] == '[') {
try {
var evil = window.eval; // jshint ignore:line
evil('eval.J=' + text);
text = evil.J;
}
catch (e) {
//+env:debug
error('[Jymin] Could not parse JS: "' + text + '"');
//-env:debug
}
}
return text;
};
/**
* Execute JavaScript.
*/
var execute = function (text) {
parse('0;' + text);
};
/**
* Log values to the console, if it's available.

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

};
/**
* Left-pad a number with zeros if it's shorter than the desired length.
*/
var zeroFill = function (
number,
length
) {
number = ensureString(number);
// Repurpose the lenth variable to count how much padding we need.
length = Math.max(length - number.length, 0);
return (new Array(length + 1)).join('0') + number;
};
/**
* Execute a callback when the page loads.

@@ -1659,81 +1757,3 @@ */

};
/**
* Create a not-strictly-JSON string.
*/
var stringify = function (data, stack) {
var reserved = /^(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with)$/;
if (data === null) {
data = 'null';
}
else if (isFunction(data)) {
data = ensureString(data).replace(/^function \(/, 'function(');
}
else if (isDate(data)) {
data = 'new Date(' + getTime(data) + ')';
}
else if (isObject(data)) {
stack = stack || [];
var isCircular = false;
forEach(stack, function (item, index) {
if (item == data) {
isCircular = true;
}
});
if (isCircular) {
return null;
}
push(stack, data);
var parts = [];
if (isArray(data)) {
forEach(data, function (value) {
push(parts, stringify(value, stack));
});
}
else {
forIn(data, function (key, value) {
if (reserved.test(key)) {
key = '"' + key + '"';
}
push(parts, key + ':' + stringify(value, stack));
});
}
pop(stack);
data = '{' + parts.join(',') + '}';
}
else if (isString(data) && stack) {
data = '"' + data.replace(/"/g, '\\"') + '"';
}
else {
data = '' + data;
}
return data;
};
/**
* Parse JavaScript.
*/
var parse = function (text) {
if (text[0] == '{') {
try {
var evil = window.eval; // jshint ignore:line
evil('eval.J=' + text);
text = evil.J;
}
catch (e) {
//+env:debug
error('[Jymin] Could not parse JS: "' + text + '"');
//-env:debug
}
}
return text;
};
/**
* Execute JavaScript.
*/
var execute = function (text) {
parse('0;' + text);
};
/**
* Get the current location host.

@@ -1740,0 +1760,0 @@ */

@@ -15,3 +15,3 @@ {

],
"version": "0.2.4",
"version": "0.2.5",
"main": "chug/chug.js",

@@ -18,0 +18,0 @@ "homepage": "http://lighter.io/jymin",

@@ -148,3 +148,3 @@ /**

*/
var pad = function (
var padArray = function (
array, // Array: The array to check for items.

@@ -151,0 +151,0 @@ padToLength, // number: The minimum number of items in the array.

@@ -16,24 +16,21 @@ /**

*/
var getUtcTimestamp = function (
var getIsoDate = function (
date // Date: Date object. (Default: now)
) {
var utcMonths = {
Jan: '01',
Feb: '02',
Mar: '03',
Apr: '04',
May: '05',
Jun: '06',
Jul: '07',
Aug: '08',
Sep: '09',
Oct: '10',
Nov: '11',
Dec: '12'
};
date = date || new Date();
var utcPattern = /^.*?(\d+) (\w+) (\d+) ([\d:]+).*?$/;
return date.toUTCString().replace(utcPattern, function (a, d, m, y, t) {
return y + '-' + utcMonths[m] + '-' + d + ' ' + t;
});
if (!date) {
date = new Date();
}
if (date.toISOString) {
date = date.toISOString();
}
else {
// Build an ISO date string manually in really old browsers.
var utcPattern = /^.*?(\d+) (\w+) (\d+) ([\d:]+).*?$/;
date = date.toUTCString().replace(utcPattern, function (a, d, m, y, t) {
m = zeroFill(date.getMonth(), 2);
t += '.' + zeroFill(date.getMilliseconds(), 3);
return y + '-' + m + '-' + d + 'T' + t + 'Z';
});
}
return date;
};

@@ -13,1 +13,14 @@ /**

};
/**
* Left-pad a number with zeros if it's shorter than the desired length.
*/
var zeroFill = function (
number,
length
) {
number = ensureString(number);
// Repurpose the lenth variable to count how much padding we need.
length = Math.max(length - number.length, 0);
return (new Array(length + 1)).join('0') + number;
};

@@ -92,79 +92,1 @@ /**

};
/**
* Create a not-strictly-JSON string.
*/
var stringify = function (data, stack) {
var reserved = /^(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with)$/;
if (data === null) {
data = 'null';
}
else if (isFunction(data)) {
data = ensureString(data).replace(/^function \(/, 'function(');
}
else if (isDate(data)) {
data = 'new Date(' + getTime(data) + ')';
}
else if (isObject(data)) {
stack = stack || [];
var isCircular = false;
forEach(stack, function (item, index) {
if (item == data) {
isCircular = true;
}
});
if (isCircular) {
return null;
}
push(stack, data);
var parts = [];
if (isArray(data)) {
forEach(data, function (value) {
push(parts, stringify(value, stack));
});
}
else {
forIn(data, function (key, value) {
if (reserved.test(key)) {
key = '"' + key + '"';
}
push(parts, key + ':' + stringify(value, stack));
});
}
pop(stack);
data = '{' + parts.join(',') + '}';
}
else if (isString(data) && stack) {
data = '"' + data.replace(/"/g, '\\"') + '"';
}
else {
data = '' + data;
}
return data;
};
/**
* Parse JavaScript.
*/
var parse = function (text) {
if (text[0] == '{') {
try {
var evil = window.eval; // jshint ignore:line
evil('eval.J=' + text);
text = evil.J;
}
catch (e) {
//+env:debug
error('[Jymin] Could not parse JS: "' + text + '"');
//-env:debug
}
}
return text;
};
/**
* Execute JavaScript.
*/
var execute = function (text) {
parse('0;' + text);
};
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