master 2.2.0
yutent 2023-06-20 18:50:57 +08:00
parent c89fff71d9
commit 1285c266c6
5 changed files with 13 additions and 23 deletions

View File

@ -6,20 +6,10 @@
const Es = require('esbuild') const Es = require('esbuild')
Es.build({
entryPoints: ['src/index.mjs'],
outfile: 'dist/index.mjs',
platform: 'node',
bundle: true,
minify: true,
format: 'esm'
})
Es.build({ Es.build({
entryPoints: ['src/index.mjs'], entryPoints: ['src/index.mjs'],
outfile: 'dist/index.js', outfile: 'dist/index.js',
platform: 'node',
minify: true, minify: true,
bundle: true, bundle: true,
target: 'node8' target: 'es6'
}) })

View File

@ -1,6 +1,6 @@
{ {
"name": "es.shim", "name": "es.shim",
"version": "2.1.1", "version": "2.2.0",
"description": "实现部分新API, 以及一些常用的扩展方法", "description": "实现部分新API, 以及一些常用的扩展方法",
"keyworks": [ "keyworks": [
"es5", "es5",

View File

@ -6,7 +6,7 @@
//获取当天是本月第几周 //获取当天是本月第几周
if (!Date.isDate) { if (!Date.isDate) {
Object.defineProperty(Date, 'isDate', { Object.defineProperty(Date, 'isDate', {
value: function(obj) { value: function (obj) {
return obj && typeof obj === 'object' && obj.getTime ? true : false return obj && typeof obj === 'object' && obj.getTime ? true : false
}, },
writable: true writable: true
@ -16,7 +16,7 @@ if (!Date.isDate) {
if (!Date.prototype.getFullWeek) { if (!Date.prototype.getFullWeek) {
//获取当天是本年度第几周 //获取当天是本年度第几周
Object.defineProperty(Date.prototype, 'getFullWeek', { Object.defineProperty(Date.prototype, 'getFullWeek', {
value: function() { value: function () {
let thisYear = this.getFullYear() let thisYear = this.getFullYear()
let that = new Date(thisYear, 0, 1) let that = new Date(thisYear, 0, 1)
let firstDay = that.getDay() let firstDay = that.getDay()
@ -27,7 +27,7 @@ if (!Date.prototype.getFullWeek) {
//获取当天是本月第几周 //获取当天是本月第几周
Object.defineProperty(Date.prototype, 'getWeek', { Object.defineProperty(Date.prototype, 'getWeek', {
value: function() { value: function () {
let today = this.getDate() let today = this.getDate()
let thisMonth = this.getMonth() let thisMonth = this.getMonth()
let thisYear = this.getFullYear() let thisYear = this.getFullYear()
@ -40,8 +40,8 @@ if (!Date.prototype.getFullWeek) {
//时间格式化 //时间格式化
if (!Date.prototype.format) { if (!Date.prototype.format) {
Object.defineProperty(Date.prototype, 'format', { Object.defineProperty(Date.prototype, 'format', {
value: function(str) { value: function (str) {
var dt = { let dt = {
fullyear: this.getFullYear(), fullyear: this.getFullYear(),
year: this.getYear(), year: this.getYear(),
fullweek: this.getFullWeek(), fullweek: this.getFullWeek(),
@ -53,7 +53,7 @@ if (!Date.prototype.format) {
minutes: this.getMinutes(), minutes: this.getMinutes(),
seconds: this.getSeconds() seconds: this.getSeconds()
} }
var reg = null let reg = null
str = str || 'Y-m-d H:i:s' str = str || 'Y-m-d H:i:s'
dt.g = dt.hours > 12 ? dt.hours - 12 : dt.hours dt.g = dt.hours > 12 ? dt.hours - 12 : dt.hours

View File

@ -28,7 +28,7 @@ if (!Object.empty) {
if (!Object.prototype.toParams) { if (!Object.prototype.toParams) {
Object.defineProperty(Object.prototype, 'toParams', { Object.defineProperty(Object.prototype, 'toParams', {
value: function () { value: function () {
var params = '' let params = ''
for (let k in this) { for (let k in this) {
if (this[k] === void 0) { if (this[k] === void 0) {
continue continue

View File

@ -127,7 +127,7 @@ if (!String.prototype.escape) {
if (!String.prototype.at) { if (!String.prototype.at) {
Object.defineProperty(String.prototype, 'at', { Object.defineProperty(String.prototype, 'at', {
value: function (num) { value: function (num) {
var n = +num let n = +num
if (n < 0) { if (n < 0) {
n += this.length n += this.length
} }
@ -144,12 +144,12 @@ if (!String.prototype.at) {
if (!String.prototype.toJson) { if (!String.prototype.toJson) {
Object.defineProperty(String.prototype, 'toJson', { Object.defineProperty(String.prototype, 'toJson', {
value: function () { value: function () {
var str = this.replace(/^\?/, '') let str = this.replace(/^\?/, '')
var params = decodeURIComponent(str) let params = decodeURIComponent(str)
.split('&') .split('&')
.filter(_ => _) .filter(_ => _)
.map(_ => _.split('=')) .map(_ => _.split('='))
var obj = {} let obj = {}
for (let it of params) { for (let it of params) {
obj[it[0]] = it[1] || '' obj[it[0]] = it[1] || ''
} }