From e836bea7ba9f3ae0c04ec865102fa487206c47f2 Mon Sep 17 00:00:00 2001 From: wangyong1997 <1044656020@qq.com> Date: Mon, 5 Aug 2024 14:22:03 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0browser=20=3D>=20openWind?= =?UTF-8?q?ow.js=20=E5=A2=9E=E5=8A=A0=E6=96=B9=E6=B3=95=EF=BC=9A=E5=9C=A8?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E9=A1=B5=E9=9D=A2=E6=89=93=E5=BC=80=E6=96=B0?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/browser/openWindow.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/browser/openWindow.js diff --git a/lib/browser/openWindow.js b/lib/browser/openWindow.js new file mode 100644 index 0000000..6a15bd3 --- /dev/null +++ b/lib/browser/openWindow.js @@ -0,0 +1,34 @@ +/** + * 在当前页面打开新窗口页 + * @param {string} url 打开的网页地址 + * @param {string} title 打开的网页标题 + * @param {number} width 打开网页的宽度 + * @param {number} height 打开网页的高度 + * @returns {Window | null} 新打开的窗口对象,或在失败时返回 null + */ +export default function openWindow(url, title, width, height) { + // 获取屏幕位置和尺寸 + const dualScreenLeft = window.screenLeft ?? window.screenX ?? screen.left; + const dualScreenTop = window.screenTop ?? window.screenY ?? screen.top; + + const screenWidth = window.innerWidth ?? document.documentElement.clientWidth ?? screen.width; + const screenHeight = window.innerHeight ?? document.documentElement.clientHeight ?? screen.height; + + // 计算窗口位置以居中显示 + const left = (screenWidth - width) / 2 + dualScreenLeft; + const top = (screenHeight - height) / 2 + dualScreenTop; + + // 打开新窗口 + const newWindow = window.open( + url, + title, + `toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=${width}, height=${height}, top=${top}, left=${left}` + ); + + // 如果可能,将焦点放在新窗口上 + if (newWindow && typeof newWindow.focus === 'function') { + newWindow.focus(); + } + + return newWindow; +} From 6650f08e598ac8c38e4ad2737964971e44666f20 Mon Sep 17 00:00:00 2001 From: wangyong1997 <1044656020@qq.com> Date: Mon, 5 Aug 2024 14:28:20 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0browser=20=3D>=20openWind?= =?UTF-8?q?ow.js=20=E5=A2=9E=E5=8A=A0=E6=96=B9=E6=B3=95=EF=BC=9A=E5=9C=A8?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E9=A1=B5=E9=9D=A2=E6=89=93=E5=BC=80=E6=96=B0?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/browser/openWindow.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/browser/openWindow.js b/lib/browser/openWindow.js index 6a15bd3..b337b09 100644 --- a/lib/browser/openWindow.js +++ b/lib/browser/openWindow.js @@ -1,12 +1,16 @@ /** * 在当前页面打开新窗口页 + * @author 王勇 + * @category browser + * @alias yd_browser_openWindow * @param {string} url 打开的网页地址 * @param {string} title 打开的网页标题 * @param {number} width 打开网页的宽度 * @param {number} height 打开网页的高度 * @returns {Window | null} 新打开的窗口对象,或在失败时返回 null */ -export default function openWindow(url, title, width, height) { + +export default (url, title, width, height) => { // 获取屏幕位置和尺寸 const dualScreenLeft = window.screenLeft ?? window.screenX ?? screen.left; const dualScreenTop = window.screenTop ?? window.screenY ?? screen.top; From e40b97188715623e7208633664721a13b9201278 Mon Sep 17 00:00:00 2001 From: wangyong1997 <1044656020@qq.com> Date: Mon, 5 Aug 2024 14:42:46 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E4=BC=98=E5=8C=96openWindow=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/browser/openWindow.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/browser/openWindow.js b/lib/browser/openWindow.js index b337b09..bd1cb1d 100644 --- a/lib/browser/openWindow.js +++ b/lib/browser/openWindow.js @@ -12,15 +12,15 @@ export default (url, title, width, height) => { // 获取屏幕位置和尺寸 - const dualScreenLeft = window.screenLeft ?? window.screenX ?? screen.left; - const dualScreenTop = window.screenTop ?? window.screenY ?? screen.top; + const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left + const dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top - const screenWidth = window.innerWidth ?? document.documentElement.clientWidth ?? screen.width; - const screenHeight = window.innerHeight ?? document.documentElement.clientHeight ?? screen.height; + const screenWidth = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width + const screenHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height // 计算窗口位置以居中显示 - const left = (screenWidth - width) / 2 + dualScreenLeft; - const top = (screenHeight - height) / 2 + dualScreenTop; + const left = ((screenWidth / 2) - (width / 2)) + dualScreenLeft + const top = ((screenHeight / 2) - (height / 2)) + dualScreenTop // 打开新窗口 const newWindow = window.open( From 2c1d8b20580220c404f37a9a40864283682abd6d Mon Sep 17 00:00:00 2001 From: bianxuerui <407955981@qq.com> Date: Mon, 5 Aug 2024 14:53:21 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E6=96=B0=E5=A2=9EcomputeAge=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/datetime/computeAge.js | 28 +++++++++++++++++++++++++ lib/datetime/computeAge.test.js | 36 +++++++++++++++++++++++++++++++++ package.json | 3 ++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 lib/datetime/computeAge.js create mode 100644 lib/datetime/computeAge.test.js diff --git a/lib/datetime/computeAge.js b/lib/datetime/computeAge.js new file mode 100644 index 0000000..784cc1b --- /dev/null +++ b/lib/datetime/computeAge.js @@ -0,0 +1,28 @@ +import dayjs from 'dayjs'; + +/** + * 计算年龄 + * + * @author 卞雪瑞 + * @category 时间操作 + * @alias yd_compute_age + * @param {String} birthday - 生日日期字符串 + * @summary 根据给的生日计算出用户的年龄 + * @returns {Number} - 返回计算出的年龄,如果未提供生日则返回0 + */ +const computeAge = (birthday) => { + if (birthday) { + const _birthday = dayjs(birthday); + + if (!_birthday.isValid()) { + return 0; + } + + const cur = dayjs(); + const age = cur.get('year') - _birthday.get('year') - (cur.get('month') < _birthday.get('month') || (cur.get('month') == _birthday.get('month') && cur.get('date') < _birthday.get('date')) ? 1 : 0); + return age; + } + return 0; +}; + +export default computeAge; diff --git a/lib/datetime/computeAge.test.js b/lib/datetime/computeAge.test.js new file mode 100644 index 0000000..124ea90 --- /dev/null +++ b/lib/datetime/computeAge.test.js @@ -0,0 +1,36 @@ +import { describe, test, expect } from 'vitest'; +import dayjs from 'dayjs'; +import dy_compute_age from './computeAge'; // 确保路径正确 + +describe('dy_compute_age', () => { + test('正确计算年龄', () => { + const birthday = '1990-01-01'; // 例如,出生日期为 1990 年 1 月 1 日 + const expectedAge = dayjs().year() - 1990; // 计算预期的年龄 + const age = dy_compute_age(birthday); + expect(age).toBe(expectedAge); + }); + + test('计算同一天出生的年龄应为 0', () => { + const today = dayjs().format('YYYY-MM-DD'); + const age = dy_compute_age(today); + expect(age).toBe(0); + }); + + test('边界情况:出生日期在今年的某一天', () => { + const birthday = dayjs().subtract(5, 'month').format('YYYY-MM-DD'); // 例如,5 个月前 + const expectedAge = dayjs().year() - dayjs(birthday).year(); + const age = dy_compute_age(birthday); + expect(age).toBe(expectedAge); + }); + + test('无效日期应返回 0', () => { + const invalidDate = 'not-a-date'; + const age = dy_compute_age(invalidDate); + expect(age).toBe(0); + }); + + test('未提供出生日期应返回 0', () => { + const age = dy_compute_age(); + expect(age).toBe(0); + }); +}); diff --git a/package.json b/package.json index c9b4d32..c6ada4b 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,8 @@ "inspect": "eslint --inspect-config" }, "dependencies": { - "date-fns": "^3.6.0" + "date-fns": "^3.6.0", + "dayjs": "^1.11.12" }, "devDependencies": { "@eslint/config-inspector": "^0.5.2", From 0492e9ccdfea11830816325da4840a0950cd815d Mon Sep 17 00:00:00 2001 From: bianxuerui <407955981@qq.com> Date: Mon, 5 Aug 2024 14:53:48 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E6=96=B0=E5=A2=9EdateRange=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/datetime/dateRange.js | 30 ++++++++++++++++++++++ lib/datetime/dateRange.test.js | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 lib/datetime/dateRange.js create mode 100644 lib/datetime/dateRange.test.js diff --git a/lib/datetime/dateRange.js b/lib/datetime/dateRange.js new file mode 100644 index 0000000..21208bc --- /dev/null +++ b/lib/datetime/dateRange.js @@ -0,0 +1,30 @@ +import dayjs from 'dayjs'; + +/** + * 返回一个时间范围 + * @author 卞雪瑞 + * @category 时间操作 + * @alias yd_date_range + * @param {number} year - 需要增加的年数,默认为0 + * @param {number} month - 需要增加的月数,默认为0 + * @param {number} day - 需要增加的天数,默认为0 + * @param {number} hour - 需要增加的小时数,默认为0 + * @param {number} minute - 需要增加的分钟数,默认为0 + * @param {number} second - 需要增加的秒数,默认为0 + * @summary 生成一个时间范围数组,该数组包含当前时间和目标时间 + * 如果目标时间在当前时间之后,则返回 [当前时间, 目标时间] 的数组 + * 如果目标时间在当前时间之前或相同,则返回 [目标时间, 当前时间] 的数组 + * @returns {Array} 返回一个包含两个dayjs对象的数组,分别代表开始时间和结束时间 + */ + +const dateRange = (year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0) => { + const now = dayjs(); + const targetDate = now.add(year, 'year').add(month, 'month').add(day, 'day').add(hour, 'hour').add(minute, 'minute').add(second, 'second'); + + if (now.isBefore(targetDate)) { + return [now, targetDate]; + } + return [targetDate, now]; +}; + +export default dateRange; diff --git a/lib/datetime/dateRange.test.js b/lib/datetime/dateRange.test.js new file mode 100644 index 0000000..87a43af --- /dev/null +++ b/lib/datetime/dateRange.test.js @@ -0,0 +1,46 @@ +import { describe, test, expect } from 'vitest'; +import dayjs from 'dayjs'; +import yd_date_range from './dateRange'; + +describe('yd_date_range', () => { + test('默认情况下返回当前时间范围', () => { + const [start, end] = yd_date_range(); + expect(start.isSame(dayjs(), 'second')).toBe(true); + expect(end.isSame(dayjs(), 'second')).toBe(true); + }); + + test('增加一年', () => { + const [start, end] = yd_date_range(1); + expect(end.year()).toBe(start.year() + 1); + }); + + test('增加一个月', () => { + const [start, end] = yd_date_range(0, 1); + expect(end.month()).toBe((start.month() + 1) % 12); + }); + + test('增加一天', () => { + const [start, end] = yd_date_range(0, 0, 1); + expect(end.date()).toBe(start.date() + 1); + }); + + test('增加一小时', () => { + const [start, end] = yd_date_range(0, 0, 0, 1); + expect(end.hour()).toBe((start.hour() + 1) % 24); + }); + + test('增加一分钟', () => { + const [start, end] = yd_date_range(0, 0, 0, 0, 1); + expect(end.minute()).toBe((start.minute() + 1) % 60); + }); + + test('增加一秒钟', () => { + const [start, end] = yd_date_range(0, 0, 0, 0, 0, 1); + expect(end.second()).toBe((start.second() + 1) % 60); + }); + + test('如果目标日期在当前日期之前,返回的顺序应调整', () => { + const [start, end] = yd_date_range(-1); // 减少一年 + expect(start.isBefore(end)).toBe(true); + }); +}); From 4e86954c29b5bbbf373e66f1ee77a023359b9f72 Mon Sep 17 00:00:00 2001 From: wangyong1997 <1044656020@qq.com> Date: Mon, 5 Aug 2024 15:02:58 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E6=96=B0=E5=A2=9Eyd=5Fbrowser=5FscrollTo?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/browser/scrollTo.js | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/browser/scrollTo.js diff --git a/lib/browser/scrollTo.js b/lib/browser/scrollTo.js new file mode 100644 index 0000000..477f68b --- /dev/null +++ b/lib/browser/scrollTo.js @@ -0,0 +1,65 @@ +// Quadratic ease-in-out function for smooth scrolling +Math.easeInOutQuad = function(t, b, c, d) { + t /= d / 2; + if (t < 1) { + return c / 2 * t * t + b; + } + t--; + return -c / 2 * (t * (t - 2) - 1) + b; +}; + +// RequestAnimationFrame polyfill for smooth animations +const requestAnimFrame = (() => { + return window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + function(callback) { window.setTimeout(callback, 1000 / 60); }; +})(); + +/** + * Move the scroll position to a specific amount + * @param {number} amount - The amount to scroll + */ +function move(amount) { + document.documentElement.scrollTop = amount; + document.body.parentNode.scrollTop = amount; + document.body.scrollTop = amount; +} + +/** + * Get the current scroll position + * @returns {number} - The current scroll position + */ +function position() { + return document.documentElement.scrollTop || + document.body.parentNode.scrollTop || + document.body.scrollTop; +} + +/** + * 平滑滚动到特定位置 + * @author 王勇 + * @category browser + * @alias yd_browser_scrollTo + * @param {number} to - 目标滚动位置 + * @param {number} [duration=500] - 滚动动画的持续时间,以毫秒为单位 + * @param {Function} [callback] - 在滚动动画完成后执行的回调函数 + */ +export default (to, duration = 500, callback) => { + const start = position(); + const change = to - start; + const increment = 20; + let currentTime = 0; + function animateScroll() { + currentTime += increment; + const val = Math.easeInOutQuad(currentTime, start, change, duration); + move(val); + if (currentTime < duration) { + requestAnimFrame(animateScroll); + } else if (typeof callback === 'function') { + callback(); + } + } + + animateScroll(); +} \ No newline at end of file From 234afc2aa6da14d953652097bb61d0216ceebfed Mon Sep 17 00:00:00 2001 From: bianxuerui <407955981@qq.com> Date: Mon, 5 Aug 2024 16:01:01 +0800 Subject: [PATCH 7/9] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4dayjs=E6=94=B9?= =?UTF-8?q?=E7=94=A8date-fns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/datetime/computeAge.js | 15 ++++++++++----- lib/datetime/computeAge.test.js | 10 +++++----- lib/datetime/dateRange.js | 11 +++++------ lib/datetime/dateRange.test.js | 21 +++++++++++---------- package.json | 3 +-- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/lib/datetime/computeAge.js b/lib/datetime/computeAge.js index 784cc1b..887d22b 100644 --- a/lib/datetime/computeAge.js +++ b/lib/datetime/computeAge.js @@ -1,4 +1,4 @@ -import dayjs from 'dayjs'; +import { parseISO, isValid, differenceInYears, isBefore } from 'date-fns'; /** * 计算年龄 @@ -12,14 +12,19 @@ import dayjs from 'dayjs'; */ const computeAge = (birthday) => { if (birthday) { - const _birthday = dayjs(birthday); + const _birthday = parseISO(birthday); - if (!_birthday.isValid()) { + if (!isValid(_birthday)) { return 0; } - const cur = dayjs(); - const age = cur.get('year') - _birthday.get('year') - (cur.get('month') < _birthday.get('month') || (cur.get('month') == _birthday.get('month') && cur.get('date') < _birthday.get('date')) ? 1 : 0); + const cur = new Date(); + let age = differenceInYears(cur, _birthday); + + if (isBefore(cur, new Date(cur.getFullYear(), _birthday.getMonth(), _birthday.getDate()))) { + age--; + } + return age; } return 0; diff --git a/lib/datetime/computeAge.test.js b/lib/datetime/computeAge.test.js index 124ea90..623f7c3 100644 --- a/lib/datetime/computeAge.test.js +++ b/lib/datetime/computeAge.test.js @@ -1,24 +1,24 @@ import { describe, test, expect } from 'vitest'; -import dayjs from 'dayjs'; +import { format, parseISO, getYear, subMonths } from 'date-fns'; import dy_compute_age from './computeAge'; // 确保路径正确 describe('dy_compute_age', () => { test('正确计算年龄', () => { const birthday = '1990-01-01'; // 例如,出生日期为 1990 年 1 月 1 日 - const expectedAge = dayjs().year() - 1990; // 计算预期的年龄 + const expectedAge = new Date().getFullYear() - 1990; // 计算预期的年龄 const age = dy_compute_age(birthday); expect(age).toBe(expectedAge); }); test('计算同一天出生的年龄应为 0', () => { - const today = dayjs().format('YYYY-MM-DD'); + const today = format(new Date(), 'yyyy-MM-dd'); const age = dy_compute_age(today); expect(age).toBe(0); }); test('边界情况:出生日期在今年的某一天', () => { - const birthday = dayjs().subtract(5, 'month').format('YYYY-MM-DD'); // 例如,5 个月前 - const expectedAge = dayjs().year() - dayjs(birthday).year(); + const birthday = format(subMonths(new Date(), 5), 'yyyy-MM-dd'); // 例如,5 个月前 + const expectedAge = getYear(new Date()) - getYear(parseISO(birthday)); const age = dy_compute_age(birthday); expect(age).toBe(expectedAge); }); diff --git a/lib/datetime/dateRange.js b/lib/datetime/dateRange.js index 21208bc..bdeb9ab 100644 --- a/lib/datetime/dateRange.js +++ b/lib/datetime/dateRange.js @@ -1,8 +1,7 @@ -import dayjs from 'dayjs'; +import { add, isBefore } from 'date-fns'; /** * 返回一个时间范围 - * @author 卞雪瑞 * @category 时间操作 * @alias yd_date_range * @param {number} year - 需要增加的年数,默认为0 @@ -14,14 +13,14 @@ import dayjs from 'dayjs'; * @summary 生成一个时间范围数组,该数组包含当前时间和目标时间 * 如果目标时间在当前时间之后,则返回 [当前时间, 目标时间] 的数组 * 如果目标时间在当前时间之前或相同,则返回 [目标时间, 当前时间] 的数组 - * @returns {Array} 返回一个包含两个dayjs对象的数组,分别代表开始时间和结束时间 + * @returns {Array} 返回一个包含两个Date对象的数组,分别代表开始时间和结束时间 */ const dateRange = (year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0) => { - const now = dayjs(); - const targetDate = now.add(year, 'year').add(month, 'month').add(day, 'day').add(hour, 'hour').add(minute, 'minute').add(second, 'second'); + const now = new Date(); + const targetDate = add(now, { years: year, months: month, days: day, hours: hour, minutes: minute, seconds: second }); - if (now.isBefore(targetDate)) { + if (isBefore(now, targetDate)) { return [now, targetDate]; } return [targetDate, now]; diff --git a/lib/datetime/dateRange.test.js b/lib/datetime/dateRange.test.js index 87a43af..4f71744 100644 --- a/lib/datetime/dateRange.test.js +++ b/lib/datetime/dateRange.test.js @@ -1,46 +1,47 @@ import { describe, test, expect } from 'vitest'; -import dayjs from 'dayjs'; +import { add, isEqual, isBefore, startOfSecond } from 'date-fns'; import yd_date_range from './dateRange'; describe('yd_date_range', () => { test('默认情况下返回当前时间范围', () => { const [start, end] = yd_date_range(); - expect(start.isSame(dayjs(), 'second')).toBe(true); - expect(end.isSame(dayjs(), 'second')).toBe(true); + const now = new Date(); + expect(isEqual(startOfSecond(start), startOfSecond(now))).toBe(true); + expect(isEqual(startOfSecond(end), startOfSecond(now))).toBe(true); }); test('增加一年', () => { const [start, end] = yd_date_range(1); - expect(end.year()).toBe(start.year() + 1); + expect(end.getFullYear()).toBe(start.getFullYear() + 1); }); test('增加一个月', () => { const [start, end] = yd_date_range(0, 1); - expect(end.month()).toBe((start.month() + 1) % 12); + expect((end.getMonth() + 12) % 12).toBe((start.getMonth() + 1) % 12); }); test('增加一天', () => { const [start, end] = yd_date_range(0, 0, 1); - expect(end.date()).toBe(start.date() + 1); + expect(end.getDate()).toBe(start.getDate() + 1); }); test('增加一小时', () => { const [start, end] = yd_date_range(0, 0, 0, 1); - expect(end.hour()).toBe((start.hour() + 1) % 24); + expect((end.getHours() + 24) % 24).toBe((start.getHours() + 1) % 24); }); test('增加一分钟', () => { const [start, end] = yd_date_range(0, 0, 0, 0, 1); - expect(end.minute()).toBe((start.minute() + 1) % 60); + expect((end.getMinutes() + 60) % 60).toBe((start.getMinutes() + 1) % 60); }); test('增加一秒钟', () => { const [start, end] = yd_date_range(0, 0, 0, 0, 0, 1); - expect(end.second()).toBe((start.second() + 1) % 60); + expect((end.getSeconds() + 60) % 60).toBe((start.getSeconds() + 1) % 60); }); test('如果目标日期在当前日期之前,返回的顺序应调整', () => { const [start, end] = yd_date_range(-1); // 减少一年 - expect(start.isBefore(end)).toBe(true); + expect(isBefore(start, end)).toBe(true); }); }); diff --git a/package.json b/package.json index be5bb49..2c8b858 100644 --- a/package.json +++ b/package.json @@ -44,8 +44,7 @@ "inspect": "eslint --inspect-config" }, "dependencies": { - "date-fns": "^3.6.0", - "dayjs": "^1.11.12" + "date-fns": "^3.6.0" }, "devDependencies": { "@eslint/config-inspector": "^0.5.2", From ac3ee55819e5bf6dfb4f681a617d2f5bb133581a Mon Sep 17 00:00:00 2001 From: wangyong1997 <1044656020@qq.com> Date: Mon, 5 Aug 2024 18:27:26 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=BC=98=E5=8C=96yd=5Fbrowser=5FscrollTo?= =?UTF-8?q?=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/browser/scrollTo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/browser/scrollTo.js b/lib/browser/scrollTo.js index 477f68b..72f9ae8 100644 --- a/lib/browser/scrollTo.js +++ b/lib/browser/scrollTo.js @@ -1,5 +1,5 @@ // Quadratic ease-in-out function for smooth scrolling -Math.easeInOutQuad = function(t, b, c, d) { +const easeInOutQuad = (t, b, c, d) => { t /= d / 2; if (t < 1) { return c / 2 * t * t + b; @@ -52,7 +52,7 @@ export default (to, duration = 500, callback) => { let currentTime = 0; function animateScroll() { currentTime += increment; - const val = Math.easeInOutQuad(currentTime, start, change, duration); + const val = easeInOutQuad(currentTime, start, change, duration); move(val); if (currentTime < duration) { requestAnimFrame(animateScroll); From 7d870d9dc3fe029b9dd816eb84ed639f3f24d918 Mon Sep 17 00:00:00 2001 From: grantguo <810153274@qq.com> Date: Mon, 5 Aug 2024 21:18:32 +0800 Subject: [PATCH 9/9] =?UTF-8?q?add=20yd=5FidCard=5FgetSex=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/idCard/getSex.js | 15 +++++++++++++++ lib/idCard/getSex.test.js | 11 +++++++++++ 2 files changed, 26 insertions(+) create mode 100644 lib/idCard/getSex.js create mode 100644 lib/idCard/getSex.test.js diff --git a/lib/idCard/getSex.js b/lib/idCard/getSex.js new file mode 100644 index 0000000..bea8758 --- /dev/null +++ b/lib/idCard/getSex.js @@ -0,0 +1,15 @@ +/** + * @description 根据身份证获取性别 + * @author grantguo + * @category idCard + * @alias yd_idCard_getSex + * @param { string } card 身份证号 + * @return 返回性别 + * @summary 根据身份证号码获取性别 + * @example + * yd_idCard_getSex(card) + */ +export default (card) => { + const num = Number(card.slice(-2, -1)); + return num % 2 === 0 ? '女性' : '男性'; +}; diff --git a/lib/idCard/getSex.test.js b/lib/idCard/getSex.test.js new file mode 100644 index 0000000..a516cc8 --- /dev/null +++ b/lib/idCard/getSex.test.js @@ -0,0 +1,11 @@ +import { describe, it, expect } from 'vitest'; +import yd_idCard_getSex from './getSex.js'; + +describe('yd_idCard_getAge', () => { + it('获取性别', () => { + const sex_1 = yd_idCard_getSex('220181199608286312'); + expect(sex_1).toEqual('男性'); + const sex_2 = yd_idCard_getSex('42132120020509720X'); + expect(sex_2).toEqual('女性'); + }); +});