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

date-utils-2020

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

date-utils-2020 - npm Package Compare versions

Comparing version 0.0.2 to 1.0.0

src/helper.ts

17

.eslintrc.js

@@ -11,5 +11,3 @@ /**

},
globals: {
THREE: true
},
globals: {},
parserOptions: {

@@ -23,10 +21,17 @@ parser: 'babel-eslint',

extends: [
'standard'
'standard',
'plugin:@typescript-eslint/recommended'
],
plugins: [],
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint'
],
rules: {
'space-before-function-paren': 0,
// 'brace-style': [2, 'stroustrup', { allowSingleLine: true }],
'brace-style': 0
'brace-style': 0,
// '@typescript-eslint/explicit-function-return-type': 'off',
// '@typescript-eslint/no-explicit-any': 'off',
// '@typescript-eslint/no-use-before-define': 'off',
}
}
/*! For license information please see date-utils-2020.js.LICENSE.txt */
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}("undefined"!=typeof self?self:this,(function(){return(()=>{"use strict";var e={638:(e,t,r)=>{function n(e){return/^-?\d+\.?\d+$/.test(e)}function o(e){return"string"==typeof e}function s(e){return(e+="")[1]?e:"0"+e}r.r(t),r.d(t,{formatDate:()=>a,isNumberLike:()=>n,isString:()=>o,toDate:()=>u,toTwoDigits:()=>s});var i={weeks:["日","一","二","三","四","五","六"]};function a(e,t,r){var n,a=u(e);if(!a||!t)return o(e)?e:e+"";if("timestamp"===t)return+a;/(y+)/i.test(t)&&(n=RegExp.$1,t=t.replace(n,(a.getFullYear()+"").substr(4-n.length))),r&&Array.isArray(r.weeks)||(r=i);var f={"M+":a.getMonth()+1,"d+":a.getDate(),"h+":a.getHours(),"m+":a.getMinutes(),"s+":a.getSeconds(),"w+":a.getDay(),"W+":r.weeks[a.getDay()],"a+":a.getHours()<12?"am":"pm","A+":a.getHours()<12?"AM":"PM"};for(var p in f)if(new RegExp("("+p+")").test(t)){n=RegExp.$1;var l=f[p]+"";t=t.replace(n,1===n.length?l:s(l))}return t}function u(e){if(!e)return null;if(e instanceof Date)return e;var t=null;if(n(e)){var r=e+"",s=r.length;t=8===s?new Date([r.substr(0,4),r.substr(4,2),r.substr(6,2)].join("/")):6===s?new Date([r.substr(0,4),r.substr(4,2),"01"].join("/")):4===s?new Date(r+"/01/01"):new Date(e)}else o(e)&&(e=(e=e.replace(/[年月日]/g,(function(e){return"日"===e?"":"/"}))).replace(/[(((].*?[)))]/g," ").replace(/\bam|pm\b/gi," ").replace(/\s+/g," "),/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.test(e)?t=new Date([RegExp.$1,RegExp.$2,RegExp.$3].join("/")):/^(\d{4})[-/](\d{1,2})$/.test(e)?t=new Date([RegExp.$1,RegExp.$2,"01"].join("/")):(t=new Date(e),isNaN(t.getFullYear())&&(t=null)));return t}}},t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}return r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(638)})()}));
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}("undefined"!=typeof self?self:this,(function(){return(()=>{"use strict";var e={949:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.toTwoDigits=t.isString=t.isNumberLike=void 0,t.isNumberLike=function(e){return"number"==typeof e||"string"==typeof e&&/^-?(\d+|\d+\.\d+)$/.test(e)},t.isString=function(e){return"string"==typeof e},t.toTwoDigits=function(e){var t=e+"";return t[1]?t:"0"+t}},607:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.toTwoDigits=t.toDate=t.isNumberLike=t.formatDate=void 0;var n=r(949);Object.defineProperty(t,"isNumberLike",{enumerable:!0,get:function(){return n.isNumberLike}}),Object.defineProperty(t,"toTwoDigits",{enumerable:!0,get:function(){return n.toTwoDigits}});var i={weeks:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]};function o(e){if(!e)return null;if(e instanceof Date)return e;var t=e+"";if(n.isNumberLike(t)){var r=t.length;return 8===r?new Date([t.substr(0,4),t.substr(4,2),t.substr(6,2)].join("/")):6===r?new Date([t.substr(0,4),t.substr(4,2),"01"].join("/")):4===r?new Date(t+"/01/01"):new Date(t)}if(t=(t=t.replace(/[年月日]/g,(function(e){return"日"===e?"":"/"}))).replace(/[(((].*?[)))]/g," ").replace(/\bam|pm\b/gi," ").replace(/\s+/g," "),/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.test(t))return new Date([RegExp.$1,RegExp.$2,RegExp.$3].join("/"));if(/^(\d{4})[-/](\d{1,2})$/.test(t))return new Date([RegExp.$1,RegExp.$2,"01"].join("/"));var i=new Date(t);return isNaN(i.getFullYear())?null:i}t.formatDate=function(e,t,r){var u,s=o(e);if(!s||!t)return e+"";if("timestamp"===t)return s.getTime().toString();/(y+)/i.test(t)&&(u=RegExp.$1,t=t.replace(u,(s.getFullYear()+"").substr(4-u.length))),r&&Array.isArray(r.weeks)||(r=i);var a={"M+":s.getMonth()+1,"d+":s.getDate(),"h+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"w+":s.getDay(),"W+":r.weeks[s.getDay()],"a+":s.getHours()<12?"am":"pm","A+":s.getHours()<12?"AM":"PM"};for(var f in a)if(new RegExp("("+f+")").test(t)){u=RegExp.$1;var g=a[f]+"";t=t.replace(u,1===u.length?g:n.toTwoDigits(g))}return t},t.toDate=o}},t={};return function r(n){if(t[n])return t[n].exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}(607)})()}));
/*!
* date-utils-2020 0.0.2
* date-utils-2020 v1.0.0
* Author: Capricorncd
* Repository: https://github.com/capricorncd/date-utils-2020#readme
* Author: Capricorncd
* Released on: 2021-01-01 21:39:26
*/
{
"name": "date-utils-2020",
"version": "0.0.2",
"version": "1.0.0",
"description": "date utils 2020, format(date: Date, formatter: string)/toDate(a?: any)...",

@@ -31,3 +31,7 @@ "main": "dist/date-utils-2020.js",

"@babel/core": "^7.12.9",
"@babel/plugin-transform-typescript": "^7.12.1",
"@babel/preset-env": "^7.12.7",
"@babel/preset-typescript": "^7.12.7",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"babel-loader": "^8.2.2",

@@ -43,2 +47,4 @@ "clean-webpack-plugin": "^3.0.0",

"html-webpack-plugin": "^4.5.0",
"ts-loader": "^8.0.13",
"typescript": "^4.1.3",
"webpack": "^5.9.0",

@@ -45,0 +51,0 @@ "webpack-cli": "^4.2.0",

@@ -31,2 +31,16 @@ # date-utils-2020

```javascript
// node.js
const { formatDate } = require('date-utils-2020')
const result = formatDate(new Date(), 'yyyy/MM/dd hh:mm:ss')
console.log(result)
// 2020/12/05 16:07:43
```
```javascript
import { formatDate } from 'date-utils-2020'
constole.log(formatDate(new Date(), 'yyyy/MM/dd hh:mm:ss'))
```
## Methods

@@ -36,8 +50,24 @@

|:--|:--|:--|
|formatDate|(date: any, fmt: string, langPackage?: langPackage)|return `string`|
|formatDate|(date: any, format: string, langPackage?: ILangPackage)|return `string`|
|toDate|(s: any)|return `Date` or `null`|
|isNumberLike|(n: any)| return Boolean `true` or `false`|
|isString|(n: any)| return Boolean `true` or `false`|
|isNumberLike|(n: any)| return boolean `true` or `false`|
|toTwoDigits|(n: number)| return `string`|
#### format
Date Formats
|format|meaning|Example|
|:--|:--|:--|:--|
|yyyy/yy|year|`2021`/`21`|
|MM/M|month|`01`/`1`|
|dd/d|day|`01`/`1`|
|hh/h|hour|`01`/`1`|
|mm/m|minute|`01`/`1`|
|ss/s|second|`01`/`1`|
|w|week|`[0, 1, 2, 3, 4, 5, 6]`|
|W|week|`['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']`|
|a|am/pm|`am`|
|A|AM/PM|`AM`|
#### langPackage

@@ -47,6 +77,7 @@

|:--|:--|:--|
|weeks|`string[]`|Example: `['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']`, Default: `['日', '一', '二', '三', '四', '五', '六']`|
|weeks|`string[]`|Example: `['日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日']`, Default: `['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']`|
```javascript
const langPackage = {
// ['日', '一', '二', '三', '四', '五', '六']
weeks: ['日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日']

@@ -53,0 +84,0 @@ }

@@ -8,3 +8,3 @@ /**

const test = formatDate(new Date, 'yyyy-MM-dd hh:mm:ss')
const test = formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss')

@@ -14,1 +14,3 @@ console.log(test)

console.log(toDate(test))
console.log(formatDate(new Date(), 'yy-M-d h:m:s'))

@@ -6,7 +6,8 @@ /**

*/
export type langPackage = {
weeks: string[]
export interface ILangPackage {
weeks: string[],
[key: string]: any
}
export function formatDate(srcDate: any, fmt: string, langPackage?: langPackage): string;
export function formatDate(srcDate: any, fmt: string, langPackage?: ILangPackage): string;

@@ -17,4 +18,2 @@ export function toDate(date: any): Date | null;

export function isString(s: any): boolean;
export function toTwoDigits(n: any): string;

@@ -12,2 +12,3 @@ /**

const pkg = require('./package.json')
const { formatDate } = require('./dist/date-utils-2020')

@@ -23,3 +24,3 @@ const argsArr = process.argv.slice(2)

entry: {
'date-utils-2020': resolve(__dirname, './src/index.js')
'date-utils-2020': resolve(__dirname, './src/index.ts')
},

@@ -42,2 +43,7 @@ output: {

{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.js?$/,

@@ -59,6 +65,6 @@ loader: 'babel-loader'

new BannerPlugin([
`${pkg.name} ${pkg.version}`,
`${pkg.name} v${pkg.version}`,
`Author: ${pkg.author}`,
`Repository: ${pkg.homepage}`,
// `Released on: ${formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss')}`
`Released on: ${formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss')}`
].join('\n'))

@@ -74,3 +80,3 @@ ]

new EslintWebpackPlugin({
extensions: ['js'],
extensions: ['ts'],
fix: true

@@ -77,0 +83,0 @@ })

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