diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index beffa30..0000000 --- a/.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore index 1235b20..6a3e3b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,16 @@ node_modules bower_components coverage -npm-debug.log -yarn.lock -package-lock.json .DS_Store .idea .vscode # vscode localhistory .history +dist + +# package manager +npm-debug.log +yarn.lock +package-lock.json +pnpm-lock.yaml diff --git a/.npmignore b/.npmignore index 9d02b12..407d4d9 100644 --- a/.npmignore +++ b/.npmignore @@ -13,9 +13,11 @@ gulpfile.js .prettierrc Gemfile jest.config.js +jest.setup.js LICENSE.txt Rakefile express.js +.babelrc .vscode .release-it.json diff --git a/.npmrc b/.npmrc index 62d7190..43c97e7 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1 @@ -sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ package-lock=false diff --git a/.prettierrc b/.prettierrc index bfc51ad..cf847e6 100644 --- a/.prettierrc +++ b/.prettierrc @@ -6,31 +6,5 @@ "jsxBracketSameLine": true, "tabWidth": 2, "semi": true, - "singleQuote": true, - "overrides": [ - { - "files": "*.scss", - "options": { - "trailingComma": "none", - "tabWidth": 2, - "parser": "scss" - } - }, - { - "files": "*.json", - "options": { - "trailingComma": "none", - "tabWidth": 2, - "parser": "json" - } - }, - { - "files": "*.md", - "options": { - "trailingComma": "none", - "tabWidth": 2, - "parser": "json" - } - } - ] + "singleQuote": true } diff --git a/.release-it.json b/.release-it.json index d7341a3..f7f3e83 100644 --- a/.release-it.json +++ b/.release-it.json @@ -3,15 +3,12 @@ "requireCleanWorkingDir": false }, "hooks": { - "after:init": [ - "npm run test", - "t2k" - ], - "after:bump": [ - "npm run build" - ] + "after:init": ["npm run test", "t2k"], + "after:bump": ["npm run build"], + "after:release": ["npm pkg get name | cnpm sync"] }, "github": { - "release": true + "release": true, + "proxy": "http://127.0.0.1:9090" } } diff --git a/build/clean.js b/build/clean.js deleted file mode 100644 index 2b0766a..0000000 --- a/build/clean.js +++ /dev/null @@ -1,13 +0,0 @@ -(function() { - 'use strict'; - - const gulp = require('gulp'); - const $ = require('gulp-load-plugins')({ - pattern: ['gulp-*', 'gulp.*', 'del'] - }); - - //clean - gulp.task('clean', function() { - return $.del('dist'); - }); -})(); diff --git a/build/scripts.js b/build/scripts.js deleted file mode 100644 index 61801d0..0000000 --- a/build/scripts.js +++ /dev/null @@ -1,21 +0,0 @@ -(function() { - 'use strict'; - - const gulp = require('gulp'); - const saveLicense = require('uglify-save-license'); - const $ = require('gulp-load-plugins')({ - pattern: ['gulp-*', 'gulp.*', 'del', '@jswork/gulp-*'] - }); - - gulp.task('scripts', function() { - return gulp - .src('src/*.js') - .pipe($.jswork.pkgHeader()) - .pipe(gulp.dest('dist')) - .pipe($.size({ title: '[ default size ]:' })) - .pipe($.uglify({ output: { comments: saveLicense } })) - .pipe($.rename({ extname: '.min.js' })) - .pipe(gulp.dest('dist')) - .pipe($.size({ title: '[ minimize size ]:' })); - }); -})(); diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5fe2df9..0000000 --- a/dist/index.js +++ /dev/null @@ -1,34 +0,0 @@ -/*! - * name: @jswork/next-time-format - * description: Time format for next. - * homepage: https://github.com/afeiship/next-time-format - * version: 1.0.3 - * date: 2021-01-09 16:30:48 - * license: MIT - */ - -(function () { - var global = typeof window !== 'undefined' ? window : this || Function('return this')(); - var nx = global.nx || require('@jswork/next'); - /* prettier-ignore */ - var pad = function (value) { return ('' + value).padStart(2, '0'); }; - - nx.timeFormat = function (inTimestamp) { - var millisecond = parseInt(inTimestamp % 1000), - second = Math.floor((inTimestamp / 1000) % 60), - minute = Math.floor((inTimestamp / (1000 * 60)) % 60), - hour = Math.floor(inTimestamp / (1000 * 60 * 60)); - - return { - hour: hour, - minute: minute, - second: second, - millisecond: millisecond, - datetime: [pad(hour), pad(minute), pad(second)].join(':') - }; - }; - - if (typeof module !== 'undefined' && module.exports) { - module.exports = nx.timeFormat; - } -})(); diff --git a/dist/index.min.js b/dist/index.min.js deleted file mode 100644 index 988331f..0000000 --- a/dist/index.min.js +++ /dev/null @@ -1,9 +0,0 @@ -/*! - * name: @jswork/next-time-format - * description: Time format for next. - * homepage: https://github.com/afeiship/next-time-format - * version: 1.0.3 - * date: 2021-01-09 16:30:48 - * license: MIT - */ -!function(){function r(e){return(""+e).padStart(2,"0")}var e=("undefined"!=typeof window?window:this||Function("return this")()).nx||require("@jswork/next");e.timeFormat=function(e){var t=parseInt(e%1e3),o=Math.floor(e/1e3%60),n=Math.floor(e/6e4%60),e=Math.floor(e/36e5);return{hour:e,minute:n,second:o,millisecond:t,datetime:[r(e),r(n),r(o)].join(":")}},"undefined"!=typeof module&&module.exports&&(module.exports=e.timeFormat)}(); \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 0513561..c318497 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,13 +1,9 @@ -(function() { - 'use strict'; +const gulp = require('gulp'); +const { NxScripts, CleanRegistry } = require('@jswork/gulp-registry'); - const gulp = require('gulp'); - const fs = require('fs'); +const task1 = new CleanRegistry(); +const task2 = new NxScripts({ name: 'qs', classify: false }); - //import - fs.readdirSync('./build').map(function(file) { - require('./build/' + file); - }); +[task1, task2].forEach(gulp.registry); - gulp.task('default', gulp.series(['clean', 'scripts'])); -})(); +gulp.task('default', gulp.series(['clean', 'nx:scripts'])); diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..a828bd4 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,11 @@ +interface Result { + hour: number; + minute: number; + second: number; + millisecond: number; + datetime: string; +} + +interface NxStatic { + timeFormat: (ts: number) => Result; +} diff --git a/jest.config.js b/jest.config.js index 399cb7b..29d96fb 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,6 +3,7 @@ module.exports = { verbose: true, testRegex: [/\.spec.js/], //preset: "jest-puppeteer", + automock: false, moduleNameMapper: { '^@/(.*)$': '/src/$1' } diff --git a/package.json b/package.json index 102294b..b8b7baf 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@jswork/next-time-format", "version": "1.0.3", "description": "Time format for next.", - "homepage": "https://github.com/afeiship/next-time-format", + "homepage": "https://js.work", "author": { "name": "afei", "email": "1290657123@qq.com" @@ -14,37 +14,34 @@ "release": "release-it" }, "main": "dist/index.js", + "module": "dist/index.esm.js", "license": "MIT", "devDependencies": { - "@jswork/gulp-pkg-header": "^1.0.2", - "@jswork/next": "^1.0.2", + "@babel/core": "^7.21.3", + "@babel/preset-env": "^7.20.2", + "@jswork/gulp-pkg-header": "^1.0.8", + "@jswork/gulp-registry": "^1.0.22", + "@jswork/next": "^1.1.8", "del": "^6.0.0", "gulp": "^4.0.2", - "gulp-debug": "^4.0.0", - "gulp-header": "^2.0.9", - "gulp-ignore": "^3.0.0", - "gulp-load-plugins": "^2.0.5", + "gulp-babel": "^8.0.0", + "gulp-prettier": "^4.0.0", "gulp-rename": "^2.0.0", - "gulp-size": "^3.0.0", + "gulp-replace": "^1.1.4", "gulp-uglify": "^3.0.2", - "jest": "^26.6.3", - "prettier": "^2.1.2", - "release-it": "^14.2.1", - "uglify-js": "3.11.6", + "jest": "^29.5.0", + "jest-location-mock": "^1.0.9", "uglify-save-license": "^0.4.1" }, + "babel": { + "presets": [ + [ + "@babel/preset-env" + ] + ] + }, "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" - }, - "keywords": [ - "next", - "time", - "format", - "date", - "left", - "hour", - "minute", - "second" - ] + } } diff --git a/src/index.js b/src/index.js index 95dc27c..3f2f2e8 100644 --- a/src/index.js +++ b/src/index.js @@ -1,25 +1,25 @@ -(function () { - var global = typeof window !== 'undefined' ? window : this || Function('return this')(); - var nx = global.nx || require('@jswork/next'); - /* prettier-ignore */ - var pad = function (value) { return ('' + value).padStart(2, '0'); }; +import nx from '@jswork/next'; - nx.timeFormat = function (inTimestamp) { - var millisecond = parseInt(inTimestamp % 1000), - second = Math.floor((inTimestamp / 1000) % 60), - minute = Math.floor((inTimestamp / (1000 * 60)) % 60), - hour = Math.floor(inTimestamp / (1000 * 60 * 60)); +/* prettier-ignore */ +const pad = function (value) { return ('' + value).padStart(2, '0'); }; - return { - hour: hour, - minute: minute, - second: second, - millisecond: millisecond, - datetime: [pad(hour), pad(minute), pad(second)].join(':') - }; +nx.timeFormat = function (inTimestamp) { + const millisecond = parseInt(inTimestamp % 1000), + second = Math.floor((inTimestamp / 1000) % 60), + minute = Math.floor((inTimestamp / (1000 * 60)) % 60), + hour = Math.floor(inTimestamp / (1000 * 60 * 60)); + + return { + hour: hour, + minute: minute, + second: second, + millisecond: millisecond, + datetime: [pad(hour), pad(minute), pad(second)].join(':') }; +}; + +if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { + module.exports = nx.timeFormat; +} - if (typeof module !== 'undefined' && module.exports) { - module.exports = nx.timeFormat; - } -})(); +export default nx.timeFormat;