Skip to content

Commit

Permalink
feat: compitable for wx
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Jul 20, 2023
1 parent 20e6a19 commit 7aff63b
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 181 deletions.
11 changes: 0 additions & 11 deletions .editorconfig

This file was deleted.

10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ gulpfile.js
.prettierrc
Gemfile
jest.config.js
jest.setup.js
LICENSE.txt
Rakefile
express.js
.babelrc
.vscode
.release-it.json

Expand Down
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
package-lock=false
28 changes: 1 addition & 27 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 5 additions & 8 deletions .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
13 changes: 0 additions & 13 deletions build/clean.js

This file was deleted.

21 changes: 0 additions & 21 deletions build/scripts.js

This file was deleted.

34 changes: 0 additions & 34 deletions dist/index.js

This file was deleted.

9 changes: 0 additions & 9 deletions dist/index.min.js

This file was deleted.

16 changes: 6 additions & 10 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -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']));
11 changes: 11 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
interface Result {
hour: number;
minute: number;
second: number;
millisecond: number;
datetime: string;
}

interface NxStatic {
timeFormat: (ts: number) => Result;
}
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
verbose: true,
testRegex: [/\.spec.js/],
//preset: "jest-puppeteer",
automock: false,
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
}
Expand Down
43 changes: 20 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]"
Expand All @@ -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"
]
}
}
42 changes: 21 additions & 21 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 7aff63b

Please sign in to comment.