New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

langext

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

langext - npm Package Compare versions

Comparing version 1.2.1-pre-1 to 1.2.1-pre-2

dist-es6/langext.js

10

CHANGES.md
# Changes Logs of langext.js
## 2016-08-17
- v1.2.1-preview-2
- Use `Object.defineProperty` instead of assignment expression. (Angus.Fenying)
- Rename `Date.prototype.nextDay` into `Date.prototype.getNextDay`. (Angus.Fenying)
- Rename `Date.prototype.nextMonth` into `Date.prototype.getNextMonth`. (Angus.Fenying)
- Added new method `Date.prototype.getToday`. (Angus.Fenying)
- Added module styles of "es6", "amd", "systemjs", "umd". (Angus.Fenying)
## 2016-08-16

@@ -4,0 +14,0 @@

108

dist/libs/date.js

@@ -1,54 +0,56 @@

if (!Date.prototype.getSimpleDate) {
Date.prototype.getSimpleDate = function () {
return this.getFullYear()
+ "-" + (this.getMonth() + 1).toString().leftPad("0", 2)
+ "-" + this.getDate().toString().leftPad("0", 2)
+ " " + this.getHours().toString().leftPad("0", 2)
+ ":" + this.getMinutes().toString().leftPad("0", 2)
+ ":" + this.getSeconds().toString().leftPad("0", 2);
};
}
if (!Date.prototype.nextMonth) {
Object.defineProperty(Date.prototype, "nextMonth", {
"value": function () {
var result = new Date(this.getTime());
result.setMonth(result.getMonth() + 1);
return result;
},
"enumerable": false,
"writable": false,
"configurable": false
});
}
if (!Date.prototype.nextDay) {
Object.defineProperty(Date.prototype, "nextDay", {
"value": function () {
return new Date(this.getTime() + 86400000);
},
"enumerable": false,
"writable": false,
"configurable": false
});
}
if (!Date.prototype.isLeapYear) {
Date.prototype.isLeapYear = function () {
var year = this.getFullYear();
return year % 100 === 0 ? (year % 400 === 0) : (year % 4 === 0);
};
}
"use strict";
var extDefine_1 = require("./extDefine");
extDefine_1.extendMethod(Date.prototype, "getSimpleDate", function () {
return this.getFullYear()
+ "-" + (this.getMonth() + 1).toString().leftPad("0", 2)
+ "-" + this.getDate().toString().leftPad("0", 2)
+ " " + this.getHours().toString().leftPad("0", 2)
+ ":" + this.getMinutes().toString().leftPad("0", 2)
+ ":" + this.getSeconds().toString().leftPad("0", 2);
});
extDefine_1.extendMethod(Date.prototype, "getNextMonth", function (remains) {
if (remains === void 0) { remains = true; }
var result = new Date(this.getTime());
result.setMonth(result.getMonth() + 1);
if (!remains) {
result.setDate(1);
result.setHours(0);
result.setSeconds(0);
result.setMinutes(0);
result.setMilliseconds(0);
}
return result;
});
extDefine_1.extendMethod(Date.prototype, "getNextDay", function (remains) {
if (remains === void 0) { remains = true; }
var result = new Date(this.getTime() + 86400000);
if (!remains) {
result.setHours(0);
result.setSeconds(0);
result.setMinutes(0);
result.setMilliseconds(0);
}
return result;
});
extDefine_1.extendMethod(Date.prototype, "getToday", function () {
var result = new Date();
result.setHours(0);
result.setSeconds(0);
result.setMinutes(0);
result.setMilliseconds(0);
return result;
});
extDefine_1.extendMethod(Date.prototype, "isLeapYear", function () {
var year = this.getFullYear();
return year % 100 === 0 ? (year % 400 === 0) : (year % 4 === 0);
});
var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
if (!Date.prototype.getDaysInMonth) {
Date.prototype.getDaysInMonth = function (month) {
return month === 1 ? (this.isLeapYear() ? 1 : 0) + daysInMonth[1] : daysInMonth[month];
};
}
if (!Date.timeNow) {
Date.timeNow = function () {
return Math.floor((new Date()).getTime() / 1000);
};
}
if (!Date.dateNow) {
Date.dateNow = function () {
return (new Date()).getSimpleDate();
};
}
extDefine_1.extendMethod(Date.prototype, "getDaysInMonth", function (month) {
return month === 1 ? (this.isLeapYear() ? 1 : 0) + daysInMonth[1] : daysInMonth[month];
});
extDefine_1.extendMethod(Date, "timeNow", function () {
return Math.floor((new Date()).getTime() / 1000);
});
extDefine_1.extendMethod(Date, "dateNow", function () {
return (new Date()).getSimpleDate();
});

@@ -1,20 +0,20 @@

if (!Number.prototype.formatSize) {
Number.prototype.formatSize = function (ac) {
if (ac === void 0) { ac = 1; }
var k = this * 1.0;
var i = 0;
var units = ["B", "KB", "MB", "GB", "TB", "PB"];
while (k >= 1048576) {
i++;
k /= 1024.0;
}
if (k >= 1024) {
i++;
k /= 1024.0;
}
return {
"num": k > 0 ? k.toFixed(ac) : "0",
"unit": units[i]
};
"use strict";
var extDefine_1 = require("./extDefine");
extDefine_1.extendMethod(Number.prototype, "formatSize", function (ac) {
if (ac === void 0) { ac = 1; }
var k = this * 1.0;
var i = 0;
var units = ["B", "KB", "MB", "GB", "TB", "PB"];
while (k >= 1048576) {
i++;
k /= 1024.0;
}
if (k >= 1024) {
i++;
k /= 1024.0;
}
return {
"num": k > 0 ? k.toFixed(ac) : "0",
"unit": units[i]
};
}
});

@@ -1,39 +0,39 @@

if (!RegExp.prototype.matches) {
RegExp.prototype.matches = function (str) {
var mc = [];
var rea;
while (rea = this.exec(str)) {
var gc = [];
var i = 0;
var ot = rea[0];
var baseIndex = rea.index;
for (var _i = 0, rea_1 = rea; _i < rea_1.length; _i++) {
var val = rea_1[_i];
var g = void 0;
if (i === 0) {
g = {
"index": rea.index,
"value": val
};
}
else {
var index = ot.indexOf(val);
g = {
"index": index + baseIndex,
"value": val
};
ot = ot.substr(index + val.length);
baseIndex += index + val.length;
}
gc.push(g);
++i;
"use strict";
var extDefine_1 = require("./extDefine");
extDefine_1.extendMethod(RegExp.prototype, "matches", function (str) {
var mc = [];
var rea;
while (rea = this.exec(str)) {
var gc = [];
var i = 0;
var ot = rea[0];
var baseIndex = rea.index;
for (var _i = 0, rea_1 = rea; _i < rea_1.length; _i++) {
var val = rea_1[_i];
var g = void 0;
if (i === 0) {
g = {
"index": rea.index,
"value": val
};
}
mc.push({
"index": rea.index,
"value": rea[0],
"groups": gc
});
else {
var index = ot.indexOf(val);
g = {
"index": index + baseIndex,
"value": val
};
ot = ot.substr(index + val.length);
baseIndex += index + val.length;
}
gc.push(g);
++i;
}
return mc;
};
}
mc.push({
"index": rea.index,
"value": rea[0],
"groups": gc
});
}
return mc;
});

@@ -0,83 +1,65 @@

"use strict";
var extDefine_1 = require("./extDefine");
var DEFAULT_RANDOM_SEED = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
if (!String.random) {
String.random = function (length, seed) {
if (seed === void 0) { seed = DEFAULT_RANDOM_SEED; }
var l = seed.length;
var result = "";
if (length <= 0) {
return result;
}
while (length-- > 0) {
result += seed[Math.floor(Math.random() * l)];
}
extDefine_1.extendConstant(String, "DEFAULT_RANDOM_SEED", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
extDefine_1.extendMethod(String, "random", function (length, seed) {
if (seed === void 0) { seed = String["DEFAULT_RANDOM_SEED"]; }
var l = seed.length;
var result = "";
if (length <= 0) {
return result;
};
}
if (!String.format) {
String.format = function (fmt, target) {
return fmt.replace(/\$\{\w+\}/g, function (matchVal, index) {
return target[matchVal.substr(2, matchVal.length - 3)];
});
};
}
if (!String.prototype.leftPad) {
String.prototype.leftPad = function (el, length) {
var rtn = this, t = this;
while ((t = el + t).length <= length) {
rtn = t;
}
if (rtn.length < length) {
rtn = el.substr(0, length - rtn.length) + rtn;
}
return rtn;
};
}
if (!String.prototype.rightPad) {
String.prototype.rightPad = function (el, length) {
var rtn = this, t = this;
while ((t += el).length <= length) {
rtn = t;
}
if (rtn.length < length) {
rtn += el.substr(0, length - rtn.length);
}
return rtn;
};
}
if (!String.prototype.isEMail) {
String.prototype.isEMail = function () {
return this.match(/^[-_\w\.]+\@[-_\w]+(\.[-_\w]+)*$/i) ? true : false;
};
}
if (!String.prototype.isHex) {
String.prototype.isHex = function () {
return this.match(/^[0-9a-f]+$/i) ? true : false;
};
}
if (!String.prototype.isIPv4) {
String.prototype.isIPv4 = function () {
return this.match(/^[0-9]{1,3}(\.[0-9]{1,3}){3}$/) ? true : false;
};
}
if (!String.prototype.format) {
String.prototype.format = function (target) {
return this.replace(/\$\{\w+\}/g, function (matchVal, index) {
return target[matchVal.substr(2, matchVal.length - 3)];
});
};
}
if (!String.prototype.toEndLineOfCR) {
String.prototype.toEndLineOfCR = function () {
return this.replace(/\r\n|\n/g, "\r");
};
}
if (!String.prototype.toEndLineOfLF) {
String.prototype.toEndLineOfLF = function () {
return this.replace(/\r\n|\n/g, "\n");
};
}
if (!String.prototype.toEndLineOfCRLF) {
String.prototype.toEndLineOfCRLF = function () {
return this.replace(/\r\n|\r|\n/g, "\r\n");
};
}
}
while (length-- > 0) {
result += seed[Math.floor(Math.random() * l)];
}
return result;
});
extDefine_1.extendMethod(String, "format", function (fmt, target) {
return fmt.replace(/\$\{\w+\}/g, function (matchVal, index) {
return target[matchVal.substr(2, matchVal.length - 3)];
});
});
extDefine_1.extendMethod(String.prototype, "leftPad", function (el, length) {
var rtn = this, t = this;
while ((t = el + t).length <= length) {
rtn = t;
}
if (rtn.length < length) {
rtn = el.substr(0, length - rtn.length) + rtn;
}
return rtn;
});
extDefine_1.extendMethod(String.prototype, "rightPad", function (el, length) {
var rtn = this, t = this;
while ((t += el).length <= length) {
rtn = t;
}
if (rtn.length < length) {
rtn += el.substr(0, length - rtn.length);
}
return rtn;
});
extDefine_1.extendMethod(String.prototype, "isEMail", function () {
return this.match(/^[-_\w\.]+\@[-_\w]+(\.[-_\w]+)*$/i) ? true : false;
});
extDefine_1.extendMethod(String.prototype, "isHex", function () {
return this.match(/^[0-9a-f]+$/i) ? true : false;
});
extDefine_1.extendMethod(String.prototype, "isIPv4", function () {
return this.match(/^[0-9]{1,3}(\.[0-9]{1,3}){3}$/) ? true : false;
});
extDefine_1.extendMethod(String.prototype, "format", function (target) {
return this.replace(/\$\{\w+\}/g, function (matchVal, index) {
var k = matchVal.substr(2, matchVal.length - 3);
return target[k] ? target[k] : matchVal;
});
});
extDefine_1.extendMethod(String.prototype, "toEndLineOfCR", function () {
return this.replace(/\r\n|\n/g, "\r");
});
extDefine_1.extendMethod(String.prototype, "toEndLineOfLF", function () {
return this.replace(/\r\n|\n/g, "\n");
});
extDefine_1.extendMethod(String.prototype, "toEndLineOfCRLF", function () {
return this.replace(/\r\n|\r|\n/g, "\r\n");
});

@@ -19,1 +19,6 @@ "use strict";

}
console.log("A random string: ", String.random(16));
console.log("A random hex string: ", String.random(16, "0123456789abcdef"));
console.log("Today is", (new Date).getSimpleDate());
console.log("Next day is", (new Date).getNextDay().getSimpleDate());
console.log("Next month is", (new Date).getNextMonth().getSimpleDate());
{
"name": "langext",
"version": "1.2.1-pre-1",
"version": "1.2.1-pre-2",
"description": "A language extension package for javescript and typescript.",

@@ -8,3 +8,7 @@ "main": "./dist/langext.js",

"test": "node ./dist/sample.js",
"build": "tsc -p ./tsconfig.json"
"build": "tsc -p ./tsconfig.json",
"build-amd": "tsc -p ./tsconfig-amd.json",
"build-umd": "tsc -p ./tsconfig-umd.json",
"build-es6": "tsc -p ./tsconfig-es6.json",
"build-system": "tsc -p ./tsconfig-system.json"
},

@@ -11,0 +15,0 @@ "homepage": "https://github.com/fenying/langext.js#readme",

# langext.js
[![Build Status](https://travis-ci.org/fenying/langext.js.svg?branch=master)](https://travis-ci.org/fenying/langext.js)
[![Build Status](https://badge.fury.io/js/langext.svg)](https://www.npmjs.com/package/langext)

@@ -5,0 +6,0 @@ This project is for the utilities extensions for Javascript and typescript.

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