Skip to content

Commit

Permalink
🌟feat(pkg): add types
Browse files Browse the repository at this point in the history
  • Loading branch information
Ten-K committed Aug 31, 2022
1 parent c7ddbb3 commit 8459de0
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
42 changes: 42 additions & 0 deletions __unconfig_vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
let __unconfig_data
const __unconfig_stub = function (data) {
__unconfig_data = data
}
__unconfig_stub.default = (data) => {
__unconfig_data = data
}
import * as path from 'path'
import dts from 'vite-plugin-dts'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import libCss from 'vite-plugin-libcss'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { terser } from 'rollup-plugin-terser'

// https://vitejs.dev/config/
const __unconfig_default = defineConfig({
base: './',
plugins: [vue(), vueJsx(), dts(), libCss()],
build: {
lib: {
entry: path.resolve(__dirname, 'src/index.ts'),
name: 'SimpleWorkerTimer',
fileName: (format) => `index.${format}.js`
},
// https://rollupjs.org/guide/en/#big-list-of-options
rollupOptions: {
treeshake: true,
external: ['vue'],
output: {
globals: {
vue: 'vue'
},
exports: 'named'
},
plugins: [terser({ compress: { drop_console: true } })]
}
}
})

if (typeof __unconfig_default === 'function') __unconfig_default(...[{ command: 'serve', mode: 'development' }])
export default __unconfig_data
2 changes: 2 additions & 0 deletions example/Vue3/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ dist-ssr
*.njsproj
*.sln
*.sw?

.vercel
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"main": "dist/index.umd.js",
"module": "dist/index.es.js",
"types": "dist/index.d.ts",
"unpkg": "dist/index.umd.js",
"jsdelivr": "dist/index.umd.js",
"exports": {
Expand Down
16 changes: 8 additions & 8 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { IDate } from '../types/index'

// 正则格式化日期
/** 正则格式化日期 */
export const formatDate = (date: Date, dateFormat: string) => {
/* 单独格式化年份,根据y的字符数量输出年份
* 例如:yyyy => 2019
yy => 19
y => 9
*/
* 例如:yyyy => 2019
yy => 19
y => 9
*/
if (/(y+)/.test(dateFormat)) {
dateFormat = dateFormat.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
}
// 格式化月、日、时、分、秒
/** 格式化月、日、时、分、秒 */
const o: IDate = {
'm+': date.getMonth() + 1,
'd+': date.getDate(),
Expand All @@ -20,7 +20,7 @@ export const formatDate = (date: Date, dateFormat: string) => {
}
for (const k in o) {
if (new RegExp(`(${k})`).test(dateFormat)) {
// 取出对应的值
/** 取出对应的值 */
const str = o[k] + ''
/* 根据设置的格式,输出对应的字符
* 例如: 早上8时,hh => 08,h => 8
Expand All @@ -33,7 +33,7 @@ export const formatDate = (date: Date, dateFormat: string) => {
return dateFormat
}

// 日期时间补零
/** 日期时间补零 */
export const padLeftZero = (str: string | any[]) => {
return ('00' + str).substr(str.length)
}
6 changes: 4 additions & 2 deletions src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// 正则格式化日期
/** 为什么不用utils导入的原因: https://github.com/vitejs/vite/issues/9882 */

/** 正则格式化日期 */
const formatDate = (date: Date, dateFormat: string) => {
/* 单独格式化年份,根据y的字符数量输出年份
* 例如:yyyy => 2019
Expand Down Expand Up @@ -33,7 +35,7 @@ const formatDate = (date: Date, dateFormat: string) => {
return dateFormat
}

// 日期时间补零
/** 日期时间补零 */
const padLeftZero = (str: string | any[]) => {
return ('00' + str).substr(str.length)
}
Expand Down

0 comments on commit 8459de0

Please sign in to comment.