Skip to content

Commit

Permalink
feat: initial/docs/test
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Nov 29, 2020
0 parents commit 31b7f3b
Show file tree
Hide file tree
Showing 17 changed files with 391 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
23 changes: 23 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.idea
.DS_Store
**/npm-debug.log
**/node_modules
test
__tests__
src
build
gulpfile.js

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

# vscode localhistory
.history
.release-it.json
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
package-lock=false
40 changes: 40 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"trailingComma": "none",
"arrowParens": "always",
"printWidth": 100,
"bracketSpacing": true,
"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"
}
}
]
}
17 changes: 17 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"git": {
"requireCleanWorkingDir": false
},
"hooks": {
"after:init": [
"npm run test",
"t2k"
],
"after:bump": [
"npm run build"
]
},
"github": {
"release": true
}
}
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# next-weeks
> Weeks for next.
[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]

## installation
```bash
npm install -S @jswork/next-weeks
```

## apis
| api | params | description |
| --- | ------------- | ---------------------------------------------- |
| at | (index, type) | Get en/cn/emoji by index(0-6). |
| day | (day, type) | Get en/cn/emoji by js date day.(1,2,3,4,5,6,0) |

## usage
```js
import NxWeeks from '@jswork/next-weeks';

// at:
NxWeeks.at(0, 'en') // 'Monday'
NxWeeks.at(1, 'en') // 'Tuesday'
NxWeeks.at(2, 'en') // 'Wednesday'
NxWeeks.at(3, 'en') // 'Thursday'
NxWeeks.at(4, 'en') // 'Friday'
NxWeeks.at(5, 'en') // 'Saturday'
NxWeeks.at(6, 'en') // 'Sunday'


// day:
const d1 = new Date('2020-11-23');
const d2 = new Date('2020-11-24');
const d3 = new Date('2020-11-25');
const d4 = new Date('2020-11-26');
const d5 = new Date('2020-11-27');
const d6 = new Date('2020-11-28');
const d7 = new Date('2020-11-29');

NxWeeks.day(d1.getDay(), 'cn') // '一'
NxWeeks.day(d2.getDay(), 'cn') // '二'
NxWeeks.day(d3.getDay(), 'cn') // '三'
NxWeeks.day(d4.getDay(), 'cn') // '四'
NxWeeks.day(d5.getDay(), 'cn') // '五'
NxWeeks.day(d6.getDay(), 'cn') // '六'
NxWeeks.day(d7.getDay(), 'cn') // '日'
```

## license
Code released under [the MIT license](https://github.com/afeiship/next-weeks/blob/master/LICENSE.txt).

[version-image]: https://img.shields.io/npm/v/@jswork/next-weeks
[version-url]: https://npmjs.org/package/@jswork/next-weeks

[license-image]: https://img.shields.io/npm/l/@jswork/next-weeks
[license-url]: https://github.com/afeiship/next-weeks/blob/master/LICENSE.txt

[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/next-weeks
[size-url]: https://github.com/afeiship/next-weeks/blob/master/dist/next-weeks.min.js

[download-image]: https://img.shields.io/npm/dm/@jswork/next-weeks
[download-url]: https://www.npmjs.com/package/@jswork/next-weeks
32 changes: 32 additions & 0 deletions __tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(function () {
const NxWeeks = require('../src');

describe('NxWeeks.methods', function () {
test('api:at en should return en', () => {
expect(NxWeeks.at(0, 'en')).toBe('Monday');
expect(NxWeeks.at(1, 'en')).toBe('Tuesday');
expect(NxWeeks.at(2, 'en')).toBe('Wednesday');
expect(NxWeeks.at(3, 'en')).toBe('Thursday');
expect(NxWeeks.at(4, 'en')).toBe('Friday');
expect(NxWeeks.at(5, 'en')).toBe('Saturday');
expect(NxWeeks.at(6, 'en')).toBe('Sunday');
});

test('api:day en should get by date.getDay()', () => {
const d1 = new Date('2020-11-23');
const d2 = new Date('2020-11-24');
const d3 = new Date('2020-11-25');
const d4 = new Date('2020-11-26');
const d5 = new Date('2020-11-27');
const d6 = new Date('2020-11-28');
const d7 = new Date('2020-11-29');
expect(NxWeeks.day(d1.getDay(), 'cn')).toBe('一');
expect(NxWeeks.day(d2.getDay(), 'cn')).toBe('二');
expect(NxWeeks.day(d3.getDay(), 'cn')).toBe('三');
expect(NxWeeks.day(d4.getDay(), 'cn')).toBe('四');
expect(NxWeeks.day(d5.getDay(), 'cn')).toBe('五');
expect(NxWeeks.day(d6.getDay(), 'cn')).toBe('六');
expect(NxWeeks.day(d7.getDay(), 'cn')).toBe('日');
});
});
})();
13 changes: 13 additions & 0 deletions build/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function() {
'use strict';

const gulp = require('gulp');
const $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'del']
});

//clean
gulp.task('clean', function() {
return $.del('dist');
});
})();
21 changes: 21 additions & 0 deletions build/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(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 ]:' }));
});
})();
36 changes: 36 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*!
* name: @jswork/next-weeks
* description: Weeks for next.
* homepage: https://github.com/afeiship/next-weeks
* version: 1.0.0
* date: 2020-11-29 21:21:00
* license: MIT
*/

(function () {
var global = global || this || window || Function('return this')();
var nx = global.nx || require('@jswork/next');
var DATABASE = {
en: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
shorty: ['Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'],
emoji: ['😝', '😪', '😭', '🤪', '😎', '😂'],
cn: ['一', '二', '三', '四', '五', '六', '日']
};

var NxWeeks = nx.declare('nx.Weeks', {
statics: {
at: function (inIndex, inType) {
return DATABASE[inType][inIndex];
},
day: function (inDay, inType) {
var idx = inDay - 1;
idx = idx >= 0 ? idx : 6;
return this.at(idx, inType);
}
}
});

if (typeof module !== 'undefined' && module.exports) {
module.exports = NxWeeks;
}
})();
9 changes: 9 additions & 0 deletions dist/index.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*!
* name: @jswork/next-weeks
* description: Weeks for next.
* homepage: https://github.com/afeiship/next-weeks
* version: 1.0.0
* date: 2020-11-29 21:21:00
* license: MIT
*/
!function(){var e=(this||window||Function("return this")()).nx||require("@jswork/next"),t={en:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],shorty:["Mon","Tue","Wed","Thur","Fri","Sat","Sun"],emoji:["😝","😪","😭","🤪","😎","😂"],cn:["一","二","三","四","五","六","日"]},e=e.declare("nx.Weeks",{statics:{at:function(e,n){return t[n][e]},day:function(e,n){e=0<=(e=e-1)?e:6;return this.at(e,n)}}});"undefined"!=typeof module&&module.exports&&(module.exports=e)}();
13 changes: 13 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function() {
'use strict';

const gulp = require('gulp');
const fs = require('fs');

//import
fs.readdirSync('./build').map(function(file) {
require('./build/' + file);
});

gulp.task('default', gulp.series(['clean', 'scripts']));
})();
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// https://jestjs.io/docs/en/configuration
module.exports = {
verbose: true,
testRegex: [/\.spec.js/],
//preset: "jest-puppeteer",
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
}
};
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@jswork/next-weeks",
"version": "1.0.0",
"description": "Weeks for next.",
"homepage": "https://github.com/afeiship/next-weeks",
"author": {
"name": "afei",
"email": "1290657123@qq.com"
},
"scripts": {
"build": "gulp",
"test": "jest",
"release": "release-it"
},
"main": "dist/index.js",
"license": "MIT",
"devDependencies": {
"@jswork/gulp-pkg-header": "^1.0.2",
"@jswork/next": "^1.0.2",
"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-rename": "^2.0.0",
"gulp-size": "^3.0.0",
"gulp-uglify": "^3.0.2",
"jest": "^26.6.3",
"release-it": "^14.2.1",
"uglify-js": "3.11.6",
"uglify-save-license": "^0.4.1"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
}
}
Loading

0 comments on commit 31b7f3b

Please sign in to comment.