@jnrs/shared 1.0.6 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jnrs/shared",
3
- "version": "1.0.6",
3
+ "version": "1.0.11",
4
4
  "description": "As the name suggests.",
5
5
  "author": "Talia-Tan",
6
6
  "license": "ISC",
@@ -8,14 +8,28 @@
8
8
  "access": "public"
9
9
  },
10
10
  "type": "module",
11
+ "scripts": {
12
+ "test": "vitest",
13
+ "test:ui": "vitest --ui",
14
+ "dev": "tsc --watch --declaration --outDir dist",
15
+ "build": "rimraf dist && tsc",
16
+ "release": "node ./scripts/release.mjs"
17
+ },
11
18
  "keywords": [
19
+ "jnrs",
12
20
  "utils",
13
21
  "typescript",
14
22
  "helper"
15
23
  ],
24
+ "packageManager": "pnpm@10.18.1",
16
25
  "main": "dist/index.js",
17
26
  "module": "dist/index.js",
18
27
  "types": "dist/index.d.ts",
28
+ "files": [
29
+ "dist",
30
+ "README.md",
31
+ "LICENSE"
32
+ ],
19
33
  "exports": {
20
34
  ".": {
21
35
  "import": "./dist/index.js",
@@ -36,17 +50,11 @@
36
50
  "uuid": "^13.0.0"
37
51
  },
38
52
  "devDependencies": {
53
+ "@types/lodash-es": "^4.17.12",
39
54
  "@vitest/coverage-v8": "^3.2.4",
40
55
  "@vitest/ui": "3.2.4",
41
56
  "rimraf": "^6.0.1",
42
57
  "typescript": "^5.9.3",
43
- "@types/lodash-es": "^4.17.12",
44
58
  "vitest": "^3.2.4"
45
- },
46
- "scripts": {
47
- "test": "vitest",
48
- "test:ui": "vitest --ui",
49
- "build": "rimraf dist && tsc",
50
- "release": "pnpm build && pnpm publish"
51
59
  }
52
- }
60
+ }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './utils/date'
package/src/lodash.ts DELETED
@@ -1,11 +0,0 @@
1
- // 函数控制
2
- export { debounce, throttle, once } from 'lodash-es'
3
-
4
- // 安全属性访问
5
- export { get, set, has } from 'lodash-es'
6
-
7
- // 对象操作
8
- export { omit, pick, isEmpty } from 'lodash-es'
9
-
10
- // 工具判断
11
- export { isNil, noop } from 'lodash-es'
package/src/utils/date.ts DELETED
@@ -1,72 +0,0 @@
1
- /**
2
- * @Author : TanRui
3
- * @WeChat : Tan578853789
4
- * @File : date.ts
5
- * @Date : 2025/09/30
6
- * @Desc. : 日期格式化
7
- */
8
-
9
- import { format } from 'date-fns'
10
- import { zhCN, enUS, es, fr, ja, ko, ru, de } from 'date-fns/locale'
11
-
12
- const localeMap = {
13
- 'zh-CN': zhCN,
14
- 'en-US': enUS,
15
- 'es-ES': es,
16
- 'fr-FR': fr,
17
- 'ja-JP': ja,
18
- 'ko-KR': ko,
19
- 'ru-RU': ru,
20
- 'de-DE': de
21
- } as const
22
-
23
- type SupportedLocale = keyof typeof localeMap
24
-
25
- let defaultLocale = getLocale('zh-CN')
26
-
27
- /**
28
- * 设置全局默认语言
29
- * @param locale - 支持的语言字符串,如 'zh-CN', 'en-US', 'es-ES', 'fr-FR', 'ja-JP', 'ko-KR', 'ru-RU'
30
- */
31
- export function setDefaultLocale(locale: SupportedLocale) {
32
- if (!localeMap[locale]) {
33
- throw new Error(
34
- `talia-utils/date 不支持语言: ${locale}. 支持的语言包括: ${Object.keys(localeMap).join(', ')}`
35
- )
36
- }
37
- defaultLocale = getLocale(locale)
38
- }
39
-
40
- function getLocale(locale: SupportedLocale) {
41
- return localeMap[locale]
42
- }
43
-
44
- /**
45
- * 格式化日期为 "YYYY-MM-DD HH:mm:ss"
46
- * @param date - 可选,传入 Date 对象或时间戳;不传则使用当前时间
47
- * @param locale - 可选,传入 Locale 对象(如 `zhCN`, `enUS`),用于本地化
48
- * @returns 格式化后的字符串,例如 "1994-11-27 08:00:00"
49
- */
50
- export function formatDateTime(date?: Date | number, locale?: SupportedLocale): string {
51
- const targetDate = date ? new Date(date) : new Date()
52
- return format(targetDate, 'yyyy-MM-dd HH:mm:ss', {
53
- locale: locale ? getLocale(locale) : defaultLocale
54
- })
55
- }
56
-
57
- /**
58
- * 获取星期几的完整名称(如 "Monday" 或 "星期一")
59
- * @param date - 可选,传入 Date 对象或时间戳;不传则使用当前时间
60
- * @param locale - 可选,传入 Locale 对象(如 `zhCN`, `enUS`),用于本地化
61
- * @returns 星期几的字符串,例如 "Thursday"(英文)或 "星期四"(中文)
62
- *
63
- */
64
- export function formatWeekday(date: Date | number = new Date(), locale?: SupportedLocale): string {
65
- return format(date, 'EEEE', { locale: locale ? getLocale(locale) : defaultLocale })
66
- }
67
-
68
- export default {
69
- setDefaultLocale,
70
- formatDateTime,
71
- formatWeekday
72
- }
package/src/uuid.ts DELETED
@@ -1 +0,0 @@
1
- export { v5 as uuidv5 } from 'uuid'
package/test/date.test.ts DELETED
@@ -1,22 +0,0 @@
1
- import { test, expect } from 'vitest'
2
- import { setDefaultLocale, formatDateTime, formatWeekday } from '../src/utils/date'
3
-
4
- test('返回中文时间格式', () => {
5
- expect(formatDateTime(785894400000)).toBe('1994-11-27 08:00:00')
6
- })
7
-
8
- test('返回中文星期几', () => {
9
- const date = new Date('1994-11-27')
10
- expect(formatWeekday(date)).toBe('星期日')
11
- })
12
-
13
- test('返回英文星期几', () => {
14
- setDefaultLocale('en-US')
15
- const date = new Date('1994-11-27')
16
- expect(formatWeekday(date)).toBe('Sunday')
17
- })
18
-
19
- test('返回韩文星期几', () => {
20
- const date = new Date('1994-11-27')
21
- expect(formatWeekday(date, 'ko-KR')).toBe('일요일')
22
- })
@@ -1,16 +0,0 @@
1
- /**
2
- * vitest 单元测试用例
3
- * 使用方法:移除文件名中的 skip 关键字,即可启用该测试用例
4
- */
5
-
6
- import { test, expect } from 'vitest'
7
-
8
- test.todo('准备做的单元测试')
9
-
10
- test.skip('还没写完的单元测试用例,先跳过', () => {
11
- expect('运行结果').toBe('期望结果')
12
- })
13
-
14
- test('已经完成的单元测试用例', () => {
15
- expect('期望结果').toBe('期望结果')
16
- })
@@ -1,14 +0,0 @@
1
- import { test, expect } from 'vitest'
2
- import { has } from '../src/lodash'
3
-
4
- test('测试 has 方法', () => {
5
- expect(
6
- has(
7
- {
8
- a: 1,
9
- b: 2
10
- },
11
- 'a'
12
- )
13
- ).toBe(true)
14
- })
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json", // ← 继承根配置
3
- "compilerOptions": {
4
- "noEmit": false, // ← 允许 emit
5
- "declaration": true, // ← 生成 .d.ts(库必备)
6
- "outDir": "./dist", // ← 输出目录
7
- "rootDir": "./src" // ← 源码目录
8
- },
9
- "include": ["src/**/*"],
10
- "exclude": ["node_modules", "dist"]
11
- }
package/vitest.config.ts DELETED
@@ -1,3 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({})