@solar-taro/core 1.0.0 → 1.0.1

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.
Files changed (91) hide show
  1. package/hooks/filter-list.d.ts +16 -0
  2. package/hooks/filter-list.js +20 -0
  3. package/hooks/filter-list.js.map +1 -0
  4. package/hooks/index.js +4 -0
  5. package/hooks/index.js.map +1 -0
  6. package/hooks/list.d.ts +49 -0
  7. package/hooks/list.js +86 -0
  8. package/hooks/list.js.map +1 -0
  9. package/hooks/request.d.ts +22 -0
  10. package/hooks/request.js +27 -0
  11. package/hooks/request.js.map +1 -0
  12. package/index.js +6 -0
  13. package/index.js.map +1 -0
  14. package/operators.d.ts +8 -0
  15. package/operators.js +22 -0
  16. package/operators.js.map +1 -0
  17. package/package.json +6 -2
  18. package/services/bluetooth.d.ts +4 -0
  19. package/services/bluetooth.js +18 -0
  20. package/services/bluetooth.js.map +1 -0
  21. package/services/index.d.ts +4 -0
  22. package/services/index.js +5 -0
  23. package/services/index.js.map +1 -0
  24. package/services/overlay.d.ts +17 -0
  25. package/services/overlay.js +51 -0
  26. package/services/overlay.js.map +1 -0
  27. package/services/router.d.ts +77 -0
  28. package/services/router.js +62 -0
  29. package/services/router.js.map +1 -0
  30. package/services/vibrator.d.ts +13 -0
  31. package/services/vibrator.js +19 -0
  32. package/services/vibrator.js.map +1 -0
  33. package/setup.d.ts +1 -0
  34. package/setup.js +6 -0
  35. package/setup.js.map +1 -0
  36. package/utils/amount.d.ts +7 -0
  37. package/utils/amount.js +21 -0
  38. package/utils/amount.js.map +1 -0
  39. package/utils/array.d.ts +7 -0
  40. package/utils/array.js +8 -0
  41. package/utils/array.js.map +1 -0
  42. package/utils/date.d.ts +15 -0
  43. package/utils/date.js +89 -0
  44. package/utils/date.js.map +1 -0
  45. package/{src/utils/helper.ts → utils/helper.d.ts} +1 -4
  46. package/utils/helper.js +9 -0
  47. package/utils/helper.js.map +1 -0
  48. package/utils/index.d.ts +8 -0
  49. package/utils/index.js +9 -0
  50. package/utils/index.js.map +1 -0
  51. package/utils/math.d.ts +6 -0
  52. package/utils/math.js +9 -0
  53. package/utils/math.js.map +1 -0
  54. package/utils/service.d.ts +7 -0
  55. package/utils/service.js +17 -0
  56. package/utils/service.js.map +1 -0
  57. package/utils/style.d.ts +2 -0
  58. package/utils/style.js +8 -0
  59. package/utils/style.js.map +1 -0
  60. package/utils/window.d.ts +8 -0
  61. package/utils/window.js +16 -0
  62. package/utils/window.js.map +1 -0
  63. package/eslint.config.cjs +0 -22
  64. package/project.json +0 -42
  65. package/src/hooks/filter-list.ts +0 -23
  66. package/src/hooks/list.ts +0 -122
  67. package/src/hooks/request.ts +0 -51
  68. package/src/operators.ts +0 -26
  69. package/src/services/bluetooth.ts +0 -23
  70. package/src/services/index.ts +0 -4
  71. package/src/services/overlay.ts +0 -60
  72. package/src/services/router.ts +0 -125
  73. package/src/services/vibrator.ts +0 -22
  74. package/src/setup.ts +0 -6
  75. package/src/utils/amount.spec.ts +0 -10
  76. package/src/utils/amount.ts +0 -24
  77. package/src/utils/array.spec.ts +0 -22
  78. package/src/utils/array.ts +0 -8
  79. package/src/utils/date.ts +0 -90
  80. package/src/utils/index.ts +0 -8
  81. package/src/utils/math.ts +0 -9
  82. package/src/utils/service.ts +0 -19
  83. package/src/utils/style.ts +0 -9
  84. package/src/utils/window.ts +0 -17
  85. package/tsconfig.json +0 -21
  86. package/tsconfig.lib.json +0 -24
  87. package/tsconfig.spec.json +0 -28
  88. package/typedoc.json +0 -6
  89. package/vite.config.ts +0 -24
  90. /package/{src/hooks/index.ts → hooks/index.d.ts} +0 -0
  91. /package/{src/index.ts → index.d.ts} +0 -0
@@ -1,60 +0,0 @@
1
- import type * as Taro from '@tarojs/taro';
2
- import { hideLoading, showLoading, showModal, showToast } from '@tarojs/taro';
3
-
4
- export class Overlay {
5
- success(msg = '操作成功', duration = 1000) {
6
- return showToast({
7
- title: msg,
8
- icon: 'success',
9
- duration
10
- });
11
- }
12
-
13
- error(msg = '操作失败', duration = 2000) {
14
- return showToast({
15
- title: msg,
16
- icon: 'error' as any,
17
- duration
18
- });
19
- }
20
-
21
- tips(msg: string, duration = 2000) {
22
- return showToast({
23
- title: msg,
24
- icon: 'none',
25
- duration
26
- });
27
- }
28
-
29
- loading(msg = '正在加载') {
30
- showLoading({
31
- title: msg,
32
- mask: true
33
- });
34
-
35
- return {
36
- dismiss: () => hideLoading()
37
- };
38
- }
39
-
40
- /**
41
- * 模态框,确认走 `then`,取消走 `catch`
42
- * @param title
43
- * @param content
44
- * @param options
45
- */
46
- async modal(title: string, content: string, options?: Taro.showModal.Option) {
47
- const { confirm } = await showModal({
48
- title,
49
- content,
50
- ...options
51
- });
52
- if (!confirm) {
53
- return Promise.reject();
54
- }
55
- }
56
-
57
- }
58
-
59
-
60
- export const overlay = new Overlay();
@@ -1,125 +0,0 @@
1
- import { HttpParams } from '@ngify/http';
2
- import { EventChannel, getCurrentInstance, getCurrentPages, navigateBack, navigateTo, redirectTo, reLaunch } from '@tarojs/taro';
3
-
4
- export class Router {
5
- /**
6
- * 当前页面的的事件通道
7
- */
8
- get eventChannel() {
9
- return getCurrentInstance().page?.getOpenerEventChannel?.() as EventChannel;
10
- }
11
-
12
- get params() {
13
- return getCurrentInstance().router?.params ?? {}
14
- }
15
-
16
- /**
17
- * 重启某个页面
18
- * @param page 页面名
19
- * @param params 页面参数
20
- */
21
- relaunch(page: string, params?: Record<string | number, any>): Promise<TaroGeneral.CallbackResult>;
22
- /**
23
- * 重启某个页面
24
- * @param pkg 包名
25
- * @param page 页面名
26
- * @param params 页面参数
27
- */
28
- relaunch(pkg: string, page: string, params?: Record<string | number, any>): Promise<TaroGeneral.CallbackResult>;
29
- relaunch(pkgOrPage: string, pageOrParams?: string | Record<string | number, any>, params?: Record<string | number, any>) {
30
- return reLaunch({ url: this.buildUrl(pkgOrPage, pageOrParams, params) });
31
- }
32
-
33
- /**
34
- * 重定向到某个页面
35
- * @param page 页面名
36
- * @param params 页面参数
37
- */
38
- redirect(page: string, params?: Record<string | number, any>): Promise<TaroGeneral.CallbackResult>;
39
- /**
40
- * 重定向到某个页面
41
- * @param pkg 包名
42
- * @param page 页面名
43
- * @param params 页面参数
44
- */
45
- redirect(pkg: string, page: string, params?: Record<string | number, any>): Promise<TaroGeneral.CallbackResult>;
46
- redirect(pkgOrPage: string, pageOrParams?: string | Record<string | number, any>, params?: Record<string | number, any>) {
47
- return redirectTo({ url: this.buildUrl(pkgOrPage, pageOrParams, params) });
48
- }
49
-
50
- /**
51
- * 导航到某个页面
52
- * @param page
53
- * @param params
54
- * @param events
55
- */
56
- navigate(page: string, params?: Record<string | number, any>, events?: { [event: string]: (...args: any) => void }): Promise<TaroGeneral.CallbackResult & { eventChannel: EventChannel }>;
57
- /**
58
- * 导航到某个页面
59
- * @param pkg 包名
60
- * @param page 页面名
61
- * @param params 页面参数
62
- * @param events
63
- */
64
- navigate(pkg: string, page: string, params?: Record<string | number, any>, events?: { [event: string]: (...args: any) => void }): Promise<TaroGeneral.CallbackResult & { eventChannel: EventChannel }>;
65
- navigate(pkgOrPage: string, pageOrParams?: string | Record<string | number, any>, paramsOrEvents?: Record<string | number, any>, events?: { [event: string]: (...args: any) => void }) {
66
- // 分包页面
67
- if (typeof pageOrParams === 'string') {
68
- return navigateTo({ url: this.buildUrl(pkgOrPage, pageOrParams, paramsOrEvents), events }) as Promise<TaroGeneral.CallbackResult & { eventChannel: EventChannel }>;
69
- } else {
70
- return navigateTo({ url: this.buildUrl(pkgOrPage, pageOrParams), events: paramsOrEvents }) as Promise<TaroGeneral.CallbackResult & { eventChannel: EventChannel }>;
71
- }
72
- }
73
-
74
- /**
75
- * 返回到某一页面
76
- * @param delta 返回几页
77
- */
78
- back(delta = 1) {
79
- if (getCurrentPages().length > 1) {
80
- return navigateBack({ delta });
81
- }
82
-
83
- return this.redirect('index');
84
- }
85
-
86
- /**
87
- * 构造完整的页面 URL
88
- * @param page 页面名
89
- * @param params 页面参数
90
- */
91
- buildUrl(page: string, params?: Record<string | number, any>): string;
92
- /**
93
- * 构造完整的页面 URL
94
- * @param pkg 包名,默认为主包
95
- * @param page 页面名
96
- * @param params 页面参数
97
- */
98
- buildUrl(pkg: string, page: string, params?: Record<string | number, any>): string;
99
- buildUrl(pkgOrPage: string, pageOrParams?: string | Record<string | number, any>, params?: Record<string | number, any>): string;
100
- buildUrl(pkgOrPage: string, pageOrParams?: string | Record<string | number, any>, params?: Record<string | number, any>) {
101
- let url: string, pkg: string | undefined, page: string;
102
- // 分包页面
103
- if (typeof pageOrParams === 'string') {
104
- pkg = pkgOrPage;
105
- page = pageOrParams;
106
- } else {
107
- page = pkgOrPage;
108
- params = pageOrParams;
109
- }
110
-
111
- url = `/pages/${page}/index`;
112
-
113
- if (params) {
114
- url += '?' + new HttpParams(params).toString();
115
- }
116
-
117
- if (pkg) {
118
- url = `/packages/${pkg}${url}`;
119
- }
120
-
121
- return url;
122
- }
123
- }
124
-
125
- export const router = new Router();
@@ -1,22 +0,0 @@
1
- import type * as Taro from '@tarojs/taro';
2
- import { vibrateLong, vibrateShort } from '@tarojs/taro';
3
-
4
- export class Vibrator {
5
- /**
6
- * 短震
7
- * @param type
8
- */
9
- short(type: Taro.vibrateShort.Option['type'] = 'light') {
10
- // @ts-expect-error: https://developers.weixin.qq.com/community/develop/doc/00046cbacd4df8f5ad2cf631651800
11
- return vibrateShort({ type, style: type });
12
- }
13
-
14
- /**
15
- * 长震
16
- */
17
- long() {
18
- return vibrateLong();
19
- }
20
- }
21
-
22
- export const vibrator = new Vibrator();
package/src/setup.ts DELETED
@@ -1,6 +0,0 @@
1
- import { getUpdateManager } from '@tarojs/taro';
2
-
3
- export function setupSolar() {
4
- const updateManager = getUpdateManager();
5
- updateManager.onUpdateReady(() => updateManager.applyUpdate());
6
- }
@@ -1,10 +0,0 @@
1
- import { amount } from './amount';
2
-
3
- describe('amount.function', () => {
4
- it('should be formatting number', () => {
5
- expect(amount(12345)).toBe('12,345');
6
- expect(amount(12345, true)).toBe('12,345.00');
7
- expect(amount(12345.67)).toBe('12,345');
8
- expect(amount(12345.67, true)).toBe('12,345.67');
9
- });
10
- });
@@ -1,24 +0,0 @@
1
- /**
2
- * 将数字格式化成 1,234 这种带逗号的
3
- *
4
- * @param value
5
- * @param accurate 精准模式,启用后会附加小数点
6
- */
7
- export const amount = (value: number | string, accurate?: boolean) => {
8
- const [integer, decimal] = (+value || 0).toFixed(2).split('.');
9
-
10
- let str = integer
11
- .split('')
12
- .reverse()
13
- .map((char, index) =>
14
- char + (index > 0 && index % 3 === 0 ? ',' : '') // 每三个数字就加一逗号
15
- )
16
- .reverse()
17
- .join('');
18
-
19
- if (accurate) {
20
- str += `.${decimal}`;
21
- }
22
-
23
- return str;
24
- };
@@ -1,22 +0,0 @@
1
- import { find } from './array';
2
-
3
- describe('array.function', () => {
4
- describe('find', () => {
5
- it('应该可以从数组中找到目标元素', () => {
6
- const element = { id: 1, fullName: 'one' };
7
- const source = [element];
8
- const result = find(source, 'id', 1);
9
-
10
- expect(result).toEqual(element);
11
- expect(result).toBe(element);
12
- });
13
-
14
- it('在数组中找不到目标元素时应该返回 undefined', () => {
15
- const element = { id: 1, fullName: 'one' };
16
- const source = [element];
17
- const result = find(source, 'id', 2);
18
-
19
- expect(result).toBe(undefined);
20
- });
21
- });
22
- });
@@ -1,8 +0,0 @@
1
- /**
2
- * 根据条件从数组里找到元素
3
- * @param source
4
- * @param field
5
- * @param value
6
- */
7
- export const find = <A extends Record<string, any>[], E extends A[number], F extends keyof E>(source: A, field: F, value: E[F]) =>
8
- source.find(o => o[field as string] === value);
package/src/utils/date.ts DELETED
@@ -1,90 +0,0 @@
1
- const MONTH_NAMES = [
2
- '一月', '二月', '三月', '四月', '五月', '六月',
3
- '七月', '八月', '九月', '十月', '十一月', '十二月'
4
- ];
5
-
6
- const DAY_OF_WEEK_NAMES = [
7
- '星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'
8
- ];
9
-
10
- const twoDigitPad = (num: number) => num < 10 ? '0' + num : num.toString();
11
-
12
- /**
13
- * 日期格式化
14
- * - aaa: 上午/下午
15
- * - EEEE: 星期几
16
- * - MMMM: 月份全称
17
- * @param timestamp
18
- * @param fmt
19
- */
20
- export const date = (timestamp: number, fmt = 'yyyy-MM-dd') => {
21
- const date = new Date(timestamp);
22
- const day = date.getDate();
23
- const month = date.getMonth();
24
- const year = date.getFullYear();
25
- const hour = date.getHours();
26
- const minute = date.getMinutes();
27
- const second = date.getSeconds();
28
- const miliseconds = date.getMilliseconds();
29
- const h = hour % 12;
30
- const hh = twoDigitPad(h);
31
- const HH = twoDigitPad(hour);
32
- const mm = twoDigitPad(minute);
33
- const ss = twoDigitPad(second);
34
- const aaa = hour < 12 ? '上午' : '下午';
35
- const EEEE = DAY_OF_WEEK_NAMES[date.getDay()];
36
- const EEE = EEEE;
37
- const dd = twoDigitPad(day);
38
- const M = month + 1;
39
- const MM = twoDigitPad(M);
40
- const MMMM = MONTH_NAMES[month];
41
- const MMM = MMMM;
42
- const yyyy = year + '';
43
- const yy = yyyy.substring(2, 4);
44
-
45
- fmt = fmt
46
- .replace('hh', hh).replace('h', h.toString())
47
- .replace('HH', HH).replace('H', hour.toString())
48
- .replace('mm', mm).replace('m', minute.toString())
49
- .replace('ss', ss).replace('s', second.toString())
50
- .replace('S', miliseconds.toString())
51
- .replace('dd', dd).replace('d', day.toString())
52
- .replace('EEEE', EEEE).replace('EEE', EEE)
53
- .replace('yyyy', yyyy)
54
- .replace('yy', yy)
55
- .replace('aaa', aaa);
56
-
57
- if (fmt.includes('MMM')) {
58
- fmt = fmt.replace('MMMM', MMMM).replace('MMM', MMM);
59
- } else {
60
- fmt = fmt.replace('MM', MM).replace('M', M.toString());
61
- }
62
-
63
- return fmt;
64
- };
65
-
66
- /**
67
- * 时间尺度
68
- * @param timestamp
69
- * @returns 将返回 x秒/分钟/小时/天/月 前/后
70
- */
71
- export const relativeTime = (timestamp: number) => {
72
- const now = Date.now();
73
- const duration = Math.abs(now - timestamp);
74
- const beforeOrAfter = now > timestamp ? '前' : '后';
75
-
76
- if (duration <= 60000) {
77
- const tmp = duration / 1000 | 0;
78
- return tmp <= 900 ? '刚刚' : tmp + `秒${beforeOrAfter}`;
79
- } else if (duration < 3600000) {
80
- return (duration / 60000 | 0) + `分钟${beforeOrAfter}`;
81
- } else if (duration < 86400000) {
82
- return (duration / 3600000 | 0) + `小时${beforeOrAfter}`;
83
- } else if (duration < 86400000 * 30) {
84
- return (duration / 86400000 | 0) + `天${beforeOrAfter}`;
85
- } else if (duration < 86400000 * 365) {
86
- return (duration / (86400000 * 30) | 0) + `个月${beforeOrAfter}`;
87
- } else {
88
- return date(timestamp);
89
- }
90
- }
@@ -1,8 +0,0 @@
1
- export * from './amount'
2
- export * from './array'
3
- export * from './date'
4
- export * from './helper'
5
- export * from './math'
6
- export * from './service'
7
- export * from './style'
8
- export * from './window'
package/src/utils/math.ts DELETED
@@ -1,9 +0,0 @@
1
-
2
- /**
3
- * 固定数字小数位
4
- * @param value
5
- * @param fixed
6
- */
7
- export const fixed = (value: number, fixed = 2) => {
8
- return typeof value === 'number' ? value.toFixed(fixed) : '0.' + ('0'.repeat(fixed));
9
- };
@@ -1,19 +0,0 @@
1
- /**
2
- * 定义一个服务,并提供 setter, getter 函数。
3
- * 这对于需要先配置,后使用的 service 特别有用。
4
- *
5
- * @param factory 一个工厂函数,函数参数从返回的 setter 提供
6
- */
7
- export function defineService<T extends (...args: any) => any>(factory: T) {
8
- let service: ReturnType<T>;
9
-
10
- function setter(...args: Parameters<T>) {
11
- service = factory(...args as any);
12
- }
13
-
14
- function getter() {
15
- return service;
16
- }
17
-
18
- return [setter, getter] as const;
19
- }
@@ -1,9 +0,0 @@
1
- import { getSystemInfoSync } from '@tarojs/taro';
2
-
3
- export function rpxToPx(rpx: number) {
4
- return rpx / 750 * getSystemInfoSync().windowWidth;
5
- }
6
-
7
- export function pxToRpx(px: number) {
8
- return px * 750 / getSystemInfoSync().windowWidth;
9
- }
@@ -1,17 +0,0 @@
1
- import { getMenuButtonBoundingClientRect, getSystemInfoSync } from '@tarojs/taro';
2
- import { once } from './helper';
3
-
4
- export const getNavbarRect = once(() => {
5
- const { statusBarHeight, windowWidth } = getSystemInfoSync();
6
- const { height, width, left, top } = getMenuButtonBoundingClientRect();
7
- const bottom = top - statusBarHeight!;
8
-
9
- return {
10
- height: statusBarHeight! + height + bottom * 2,
11
- paddingTop: statusBarHeight! + bottom,
12
- paddingBottom: bottom,
13
- paddingLeft: windowWidth - width - left,
14
- paddingRight: windowWidth - width - left,
15
- buttonHeight: height,
16
- };
17
- });
package/tsconfig.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "forceConsistentCasingInFileNames": true,
5
- "strict": true,
6
- "noImplicitOverride": true,
7
- "noImplicitReturns": true,
8
- "noFallthroughCasesInSwitch": true,
9
- "noPropertyAccessFromIndexSignature": true
10
- },
11
- "files": [],
12
- "include": [],
13
- "references": [
14
- {
15
- "path": "./tsconfig.lib.json"
16
- },
17
- {
18
- "path": "./tsconfig.spec.json"
19
- }
20
- ]
21
- }
package/tsconfig.lib.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "declaration": true
6
- },
7
- "include": [
8
- "src/**/*.ts"
9
- ],
10
- "exclude": [
11
- "vite.config.ts",
12
- "vite.config.mts",
13
- "vitest.config.ts",
14
- "vitest.config.mts",
15
- "src/**/*.test.ts",
16
- "src/**/*.spec.ts",
17
- "src/**/*.test.tsx",
18
- "src/**/*.spec.tsx",
19
- "src/**/*.test.js",
20
- "src/**/*.spec.js",
21
- "src/**/*.test.jsx",
22
- "src/**/*.spec.jsx"
23
- ]
24
- }
@@ -1,28 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "types": [
6
- "vitest/globals",
7
- "vitest/importMeta",
8
- "vite/client",
9
- "node",
10
- "vitest"
11
- ]
12
- },
13
- "include": [
14
- "vite.config.ts",
15
- "vite.config.mts",
16
- "vitest.config.ts",
17
- "vitest.config.mts",
18
- "src/**/*.test.ts",
19
- "src/**/*.spec.ts",
20
- "src/**/*.test.tsx",
21
- "src/**/*.spec.tsx",
22
- "src/**/*.test.js",
23
- "src/**/*.spec.js",
24
- "src/**/*.test.jsx",
25
- "src/**/*.spec.jsx",
26
- "src/**/*.d.ts"
27
- ]
28
- }
package/typedoc.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "$schema": "https://typedoc.org/schema.json",
3
- "entryPoints": [
4
- "src/index.ts"
5
- ]
6
- }
package/vite.config.ts DELETED
@@ -1,24 +0,0 @@
1
- import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
2
- import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
3
- import { defineConfig } from 'vite';
4
-
5
- export default defineConfig({
6
- root: __dirname,
7
- cacheDir: '../../node_modules/.vite/core',
8
- plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],
9
- // Uncomment this if you are using workers.
10
- // worker: {
11
- // plugins: [ nxViteTsPaths() ],
12
- // },
13
- test: {
14
- watch: false,
15
- globals: true,
16
- environment: 'node',
17
- include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
18
- reporters: ['default'],
19
- coverage: {
20
- reportsDirectory: '../../coverage/core',
21
- provider: 'v8',
22
- },
23
- },
24
- });
File without changes
File without changes