Skip to content

Commit

Permalink
refactor: add typing
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Jan 30, 2024
1 parent f4ccc61 commit 58a9224
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 202 deletions.
11 changes: 0 additions & 11 deletions .editorconfig

This file was deleted.

12 changes: 7 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
node_modules
bower_components
coverage
npm-debug.log
yarn.lock
Gemfile.lock
yarn-error.log
package-lock.json
.DS_Store
.idea
.vscode

# vscode localhistory
.history
dist

# package manager
npm-debug.log
yarn.lock
package-lock.json
pnpm-lock.yaml
6 changes: 5 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ test
__tests__
src
build
docs
gulpfile.js

.editorconfig
.prettierrc
Gemfile
jest.config.js
jest.setup.js
LICENSE.txt
Rakefile
express.js
.babelrc
.vscode
.release-it.json
docs


# vscode localhistory
.history
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
32 changes: 1 addition & 31 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,5 @@
"jsxBracketSameLine": true,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"overrides": [
{
"files": ["*.json", ".eslintrc", ".tslintrc", ".prettierrc", ".tern-project"],
"options": {
"parser": "json",
"tabWidth": 2
}
},
{
"files": "*.{css,sass,scss,less}",
"options": {
"parser": "postcss",
"tabWidth": 2
}
},
{
"files": "*.ts",
"options": {
"parser": "typescript"
}
},
{
"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"
}
}
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2020 afei <1290657123@qq.com>
Copyright (c) 2016 afei <1290657123@qq.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
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.

38 changes: 0 additions & 38 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: true });

//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']));
10 changes: 10 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type WeekType = 'en' | 'cn' | 'shorty' | 'emoji';
type WeekDay = 1 | 2 | 3 | 4 | 5 | 6 | 7;
type WeekIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;

interface NxStatic {
Weeks: {
at: (index: WeekIndex, type: WeekType) => string;
day: (target: WeekDay | Date, type: WeekType) => string;
}
}
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
48 changes: 21 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,46 @@
"name": "@jswork/next-weeks",
"version": "1.0.4",
"description": "Weeks for next.",
"homepage": "https://github.com/afeiship/next-weeks",
"homepage": "https://js.work",
"author": {
"name": "afei",
"email": "1290657123@qq.com"
},
"scripts": {
"build": "gulp",
"test": "jest",
"start": "node ./express.js",
"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-concat": "^2.6.1",
"gulp-debug": "^4.0.0",
"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",
"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",
"nx",
"jswork",
"weekend",
"weekday",
"weeks",
"week",
"weekly",
"en",
"cn",
"emoji",
"date",
"day"
]
}
}
52 changes: 26 additions & 26 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
(function () {
var global = typeof window !== 'undefined' ? window : this || Function('return this')();
var nx = global.nx || require('@jswork/next');
var NUMBER = 'number';
var DATABASE = {
en: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
shorty: ['Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'],
emoji: ['😝', 'πŸ˜ͺ', '😭', 'πŸ€ͺ', '🀣', '😎', 'πŸ˜‚'],
cn: ['δΈ€', '二', 'δΈ‰', 'ε››', 'δΊ”', 'ε…­', 'ζ—₯']
};
import nx from '@jswork/next';

var NxWeeks = nx.declare('nx.Weeks', {
statics: {
at: function (inIndex, inType) {
return DATABASE[inType][inIndex];
},
day: function (inDay, inType) {
var day = typeof inDay === NUMBER ? inDay : inDay.getDay();
var idx = day - 1;
idx = idx >= 0 ? idx : 6;
return this.at(idx, inType);
}
}
});
const NUMBER = 'number';
const DATABASE = {
en: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
shorty: ['Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'],
emoji: ['😝', 'πŸ˜ͺ', '😭', 'πŸ€ͺ', '🀣', '😎', 'πŸ˜‚'],
cn: ['δΈ€', '二', 'δΈ‰', 'ε››', 'δΊ”', 'ε…­', 'ζ—₯']
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = NxWeeks;
const NxWeeks = nx.declare('nx.Weeks', {
statics: {
at: function(inIndex, inType) {
return DATABASE[inType][inIndex];
},
day: function(inDay, inType) {
var day = typeof inDay === NUMBER ? inDay : inDay.getDay();
var idx = day - 1;
idx = idx >= 0 ? idx : 6;
return this.at(idx, inType);
}
}
})();
});

if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') {
module.exports = NxWeeks;
}

export default NxWeeks;

0 comments on commit 58a9224

Please sign in to comment.