@pisell/utils 1.0.21 → 1.0.23

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/es/format.js CHANGED
@@ -35,6 +35,11 @@ export var formatAmount = function formatAmount() {
35
35
  // 添加小数点
36
36
  if (precision > 0) {
37
37
  formattedAmount += '.' + decimalPart;
38
+
39
+ // 如果小数位是 .00的话 抹去
40
+ if (formattedAmount.indexOf('.00') !== -1) {
41
+ formattedAmount = formattedAmount.substring(0, formattedAmount.length - 3);
42
+ }
38
43
  }
39
44
 
40
45
  // 添加负号
package/es/image.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export declare const image: {
2
+ ali: (url: string, w: number) => string;
3
+ getImageSize: (url: string) => {
4
+ width: number;
5
+ height: number;
6
+ ratio: number;
7
+ success: boolean;
8
+ widthRatio: number;
9
+ originRatio: number;
10
+ };
11
+ };
package/es/image.js ADDED
@@ -0,0 +1,63 @@
1
+ var ali = function ali(url, w) {
2
+ if (!url || /^\s+$/.test(url)) {
3
+ return '';
4
+ }
5
+ // 如果图片链接中已经包含了过滤参数,则直接跳过
6
+ if (/x-oss-process=/.test(url)) {
7
+ return url;
8
+ }
9
+ var dpr = 2;
10
+ w = w || 750;
11
+ if (url.indexOf('?') > -1) {
12
+ url += '&';
13
+ } else {
14
+ url += '?';
15
+ }
16
+ url += 'x-oss-process=image/resize,w_' + parseInt(w * dpr + '') + ',image/format,webp/interlace,1,image/quality,Q_60/sharpen,90';
17
+ return url;
18
+ };
19
+
20
+ /**
21
+ * @Title: 获取图片尺寸
22
+ * @Describe: 通过 __ 进行分割
23
+ * @Author: Wzw
24
+ * @param {string} url
25
+ */
26
+
27
+ var getImageSize = function getImageSize(url) {
28
+ var size = {
29
+ width: 375,
30
+ height: 375,
31
+ ratio: 1,
32
+ widthRatio: 1,
33
+ success: false,
34
+ originRatio: 1
35
+ };
36
+ if (typeof url !== 'string') return size;
37
+ // https://file.mypisel.dev/boxlocal/image/9c4e5a0afdbefadc78e3eab27c9ca3202021_07_23_16_05_00_916_02868331878656287__2160_976__.jpeg
38
+ // 根据 __ 分割url
39
+ try {
40
+ var arr = url.split('__');
41
+ // 根据规则, 第二个下标为图片的宽高
42
+ if (arr[1]) {
43
+ // 分割宽高, 第一个值是宽 第二个值是高
44
+ var sizeArr = arr[1].split('_');
45
+ // 如果没取到则默认为375
46
+ var _width = Number(sizeArr[0]) || 375;
47
+ var _height = Number(sizeArr[1]) || 375;
48
+ size.width = _width;
49
+ size.height = _height;
50
+ size.success = true;
51
+ size.ratio = Number(_height / _width);
52
+ size.widthRatio = Number((_width / _height).toFixed(2));
53
+ size.originRatio = Number(_height / _width);
54
+ }
55
+ return size;
56
+ } catch (err) {
57
+ return size;
58
+ }
59
+ };
60
+ export var image = {
61
+ ali: ali,
62
+ getImageSize: getImageSize
63
+ };
package/es/index.d.ts CHANGED
@@ -6,4 +6,7 @@ export * from "./platform";
6
6
  export * from "./log";
7
7
  export * from "./format";
8
8
  export * from "./escPosPrinter";
9
+ export * from './miniRedux';
9
10
  export * from "./jsBridge";
11
+ export * from "./image";
12
+ export * from "./locales";
package/es/index.js CHANGED
@@ -6,5 +6,8 @@ export * from "./platform";
6
6
  export * from "./log";
7
7
  export * from "./format";
8
8
  export * from "./escPosPrinter";
9
+ export * from "./miniRedux";
9
10
  export * from "./jsBridge";
11
+ export * from "./image";
12
+ export * from "./locales";
10
13
  // export { default as firebase } from './firebase';
@@ -0,0 +1,12 @@
1
+ export declare const locales: {
2
+ init: (_localeMaps: any, _locale: string) => void;
3
+ getText: (id: string) => any;
4
+ locale: string;
5
+ localeMap: any;
6
+ localeMaps: {
7
+ en: {};
8
+ 'zh-CN': {};
9
+ 'zh-HK': {};
10
+ };
11
+ formatLocale: (_locale: string) => string;
12
+ };
package/es/locales.js ADDED
@@ -0,0 +1,75 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ // 所有多语言储存
8
+ var localeMaps = {
9
+ en: {},
10
+ 'zh-CN': {},
11
+ 'zh-HK': {}
12
+ };
13
+
14
+ // 当前语言
15
+ var locale = 'en';
16
+
17
+ // 当前语言对应的多语言
18
+ var localeMap = {};
19
+
20
+ // 语言格式化
21
+ var formatLocale = function formatLocale(_locale) {
22
+ var obj = {
23
+ 'en': 'en',
24
+ 'zh-CN': 'zh-CN',
25
+ 'zh-HK': 'zh-HK',
26
+ 'zh-TW': 'zh-HK',
27
+ 'en-US': 'en'
28
+ };
29
+ return obj[_locale] || 'en';
30
+ };
31
+
32
+ /**
33
+ * @title: 初始化多语言
34
+ * @description:
35
+ * @param {any} _localeMaps
36
+ * @param {string} _locale
37
+ * @return {*}
38
+ * @Author: zhiwei.Wang
39
+ * @Date: 2024-01-17 21:38
40
+ */
41
+ var init = function init(_localeMaps, _locale) {
42
+ // 设置语言
43
+ locale = formatLocale(_locale);
44
+ var allLocales = {};
45
+ for (var key in localeMaps) {
46
+ allLocales[key] = _objectSpread(_objectSpread({}, localeMaps[key]), _localeMaps[key]);
47
+ }
48
+
49
+ // 更新语言
50
+ localeMaps = allLocales;
51
+
52
+ // 更新当前语言对应的多语言
53
+ localeMap = localeMaps[locale];
54
+ console.log('多语言注入成功, 当前语言为:' + locale);
55
+ };
56
+
57
+ /**
58
+ * @title: 获取语言
59
+ * @description:
60
+ * @param {string} id
61
+ * @return {*}
62
+ * @Author: zhiwei.Wang
63
+ * @Date: 2024-01-17 21:39
64
+ */
65
+ var getText = function getText(id) {
66
+ return localeMap[id] || id;
67
+ };
68
+ export var locales = {
69
+ init: init,
70
+ getText: getText,
71
+ locale: locale,
72
+ localeMap: localeMap,
73
+ localeMaps: localeMaps,
74
+ formatLocale: formatLocale
75
+ };
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ interface MiniReduxProps<State, Namespace> {
3
+ namespace?: Namespace;
4
+ state?: State;
5
+ reducers?: any;
6
+ effects?: any;
7
+ }
8
+ export declare const miniRedux: <State extends Record<string, any>, Namespace extends string>({ namespace, state, reducers, effects, }: MiniReduxProps<State, Namespace>) => {
9
+ Context: React.Context<{ [K in Namespace]: State; } & {
10
+ dispatch: (params: {
11
+ type: string;
12
+ payload: any;
13
+ }) => void;
14
+ }>;
15
+ Provider: (ComponentUi: any) => (props: any) => JSX.Element;
16
+ };
17
+ export {};
@@ -0,0 +1,70 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import React, { createContext, useCallback, useReducer } from "react";
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ export var miniRedux = function miniRedux(_ref2) {
16
+ var _ref2$namespace = _ref2.namespace,
17
+ namespace = _ref2$namespace === void 0 ? "state" : _ref2$namespace,
18
+ state = _ref2.state,
19
+ _ref2$reducers = _ref2.reducers,
20
+ reducers = _ref2$reducers === void 0 ? {} : _ref2$reducers,
21
+ _ref2$effects = _ref2.effects,
22
+ effects = _ref2$effects === void 0 ? {} : _ref2$effects;
23
+ var Context = /*#__PURE__*/createContext({});
24
+ var Provider = function Provider(ComponentUi) {
25
+ var Components = function Components(props) {
26
+ var _objectSpread2, _ref5;
27
+ var _useReducer = useReducer(function (state, _ref3) {
28
+ var type = _ref3.type,
29
+ payload = _ref3.payload;
30
+ if (reducers[type]) {
31
+ return reducers[type](state, payload) || state;
32
+ } else {
33
+ return state;
34
+ }
35
+ }, state),
36
+ _useReducer2 = _slicedToArray(_useReducer, 2),
37
+ providerState = _useReducer2[0],
38
+ dispatch = _useReducer2[1];
39
+ var _dispatch = useCallback(function (_ref4) {
40
+ var type = _ref4.type,
41
+ payload = _ref4.payload;
42
+ if (effects[type]) {
43
+ effects[type].call(null, payload, dispatch);
44
+ } else if (reducers[type]) {
45
+ dispatch({
46
+ type: type,
47
+ payload: payload
48
+ });
49
+ }
50
+ }, []);
51
+ var _props = _objectSpread(_objectSpread({}, props), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, namespace, providerState), _defineProperty(_objectSpread2, "dispatch", _dispatch), _objectSpread2));
52
+ var _ref = null;
53
+ if (_props.forwardedRef) {
54
+ _ref = _props.forwardedRef;
55
+ delete _props.forwardedRef;
56
+ }
57
+ return /*#__PURE__*/_jsx(Context.Provider, {
58
+ value: (_ref5 = {}, _defineProperty(_ref5, namespace, providerState), _defineProperty(_ref5, "dispatch", _dispatch), _ref5),
59
+ children: /*#__PURE__*/_jsx(ComponentUi, _objectSpread(_objectSpread({}, _props), {}, {
60
+ ref: _ref
61
+ }))
62
+ });
63
+ };
64
+ return Components;
65
+ };
66
+ return {
67
+ Context: Context,
68
+ Provider: Provider
69
+ };
70
+ };
@@ -6,3 +6,25 @@
6
6
  * @return {*}
7
7
  */
8
8
  export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
9
+ /**
10
+ * @title: 对数组进行增|删
11
+ * @description: 用于多选选中和取消选中的处理
12
+ * @param {any} list
13
+ * @param {any} item
14
+ * @param {string} key
15
+ * @return {*}
16
+ * @Author: zhiwei.Wang
17
+ * @Date: 2023-12-19 16:44
18
+ */
19
+ export declare const changeArray: <T>(list: T[] | undefined, item: T, key?: string) => T[];
20
+ /**
21
+ * @title: 判断某个字段是否在列表内
22
+ * @description:
23
+ * @param {*} T
24
+ * @param {boolean} param2
25
+ * @return {*}
26
+ * @Author: zhiwei.Wang
27
+ * @Date: 2023-12-19 16:54
28
+ */
29
+ export declare const getItemByArray: <T>(list: T[] | undefined, item: T, key?: string) => boolean;
30
+ export declare const createArray: (length: number, returnItem: any) => any;
package/es/otherUtils.js CHANGED
@@ -9,4 +9,69 @@ export var getUniqueId = function getUniqueId() {
9
9
  var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
10
10
  var maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 11;
11
11
  return prefix + (Math.random() + '').replace(/\D/g, '').substring(0, maxLength);
12
+ };
13
+
14
+ /**
15
+ * @title: 对数组进行增|删
16
+ * @description: 用于多选选中和取消选中的处理
17
+ * @param {any} list
18
+ * @param {any} item
19
+ * @param {string} key
20
+ * @return {*}
21
+ * @Author: zhiwei.Wang
22
+ * @Date: 2023-12-19 16:44
23
+ */
24
+ export var changeArray = function changeArray() {
25
+ var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
26
+ var item = arguments.length > 1 ? arguments[1] : undefined;
27
+ var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'this';
28
+ var _list = JSON.parse(JSON.stringify(list));
29
+ var isSome = false;
30
+ if (key === 'this') {
31
+ isSome = _list.includes(item);
32
+ } else {
33
+ //@ts-ignore
34
+ isSome = _list.some(function (d) {
35
+ return d[key] === item[key];
36
+ });
37
+ }
38
+ if (isSome) {
39
+ _list = _list.filter(function (d) {
40
+ if (key === 'this') {
41
+ return d !== item;
42
+ }
43
+
44
+ //@ts-ignore
45
+ return d[key] !== item[key];
46
+ });
47
+ } else {
48
+ _list.push(item);
49
+ }
50
+ return _list;
51
+ };
52
+
53
+ /**
54
+ * @title: 判断某个字段是否在列表内
55
+ * @description:
56
+ * @param {*} T
57
+ * @param {boolean} param2
58
+ * @return {*}
59
+ * @Author: zhiwei.Wang
60
+ * @Date: 2023-12-19 16:54
61
+ */
62
+ export var getItemByArray = function getItemByArray() {
63
+ var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
64
+ var item = arguments.length > 1 ? arguments[1] : undefined;
65
+ var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'this';
66
+ if (key === 'this') {
67
+ return list.includes(item);
68
+ }
69
+
70
+ //@ts-ignore
71
+ return list.some(function (d) {
72
+ return d[key] === item[key];
73
+ });
74
+ };
75
+ export var createArray = function createArray(length, returnItem) {
76
+ return Array.from(new Array(length)).map(returnItem);
12
77
  };
package/lib/format.js CHANGED
@@ -36,6 +36,9 @@ var formatAmount = (amount = 0, precision = 2, symbol = "") => {
36
36
  let formattedAmount = symbol + integerPart.toString();
37
37
  if (precision > 0) {
38
38
  formattedAmount += "." + decimalPart;
39
+ if (formattedAmount.indexOf(".00") !== -1) {
40
+ formattedAmount = formattedAmount.substring(0, formattedAmount.length - 3);
41
+ }
39
42
  }
40
43
  if (roundedAmount < 0) {
41
44
  formattedAmount = "-" + formattedAmount;
package/lib/image.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export declare const image: {
2
+ ali: (url: string, w: number) => string;
3
+ getImageSize: (url: string) => {
4
+ width: number;
5
+ height: number;
6
+ ratio: number;
7
+ success: boolean;
8
+ widthRatio: number;
9
+ originRatio: number;
10
+ };
11
+ };
package/lib/image.js ADDED
@@ -0,0 +1,78 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/image.ts
20
+ var image_exports = {};
21
+ __export(image_exports, {
22
+ image: () => image
23
+ });
24
+ module.exports = __toCommonJS(image_exports);
25
+ var ali = (url, w) => {
26
+ if (!url || /^\s+$/.test(url)) {
27
+ return "";
28
+ }
29
+ if (/x-oss-process=/.test(url)) {
30
+ return url;
31
+ }
32
+ let dpr = 2;
33
+ w = w || 750;
34
+ if (url.indexOf("?") > -1) {
35
+ url += "&";
36
+ } else {
37
+ url += "?";
38
+ }
39
+ url += "x-oss-process=image/resize,w_" + parseInt(w * dpr + "") + ",image/format,webp/interlace,1,image/quality,Q_60/sharpen,90";
40
+ return url;
41
+ };
42
+ var getImageSize = (url) => {
43
+ let size = {
44
+ width: 375,
45
+ height: 375,
46
+ ratio: 1,
47
+ widthRatio: 1,
48
+ success: false,
49
+ originRatio: 1
50
+ };
51
+ if (typeof url !== "string")
52
+ return size;
53
+ try {
54
+ let arr = url.split("__");
55
+ if (arr[1]) {
56
+ let sizeArr = arr[1].split("_");
57
+ let _width = Number(sizeArr[0]) || 375;
58
+ let _height = Number(sizeArr[1]) || 375;
59
+ size.width = _width;
60
+ size.height = _height;
61
+ size.success = true;
62
+ size.ratio = Number(_height / _width);
63
+ size.widthRatio = Number((_width / _height).toFixed(2));
64
+ size.originRatio = Number(_height / _width);
65
+ }
66
+ return size;
67
+ } catch (err) {
68
+ return size;
69
+ }
70
+ };
71
+ var image = {
72
+ ali,
73
+ getImageSize
74
+ };
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ image
78
+ });
package/lib/index.d.ts CHANGED
@@ -6,4 +6,7 @@ export * from "./platform";
6
6
  export * from "./log";
7
7
  export * from "./format";
8
8
  export * from "./escPosPrinter";
9
+ export * from './miniRedux';
9
10
  export * from "./jsBridge";
11
+ export * from "./image";
12
+ export * from "./locales";
package/lib/index.js CHANGED
@@ -24,7 +24,10 @@ __reExport(src_exports, require("./platform"), module.exports);
24
24
  __reExport(src_exports, require("./log"), module.exports);
25
25
  __reExport(src_exports, require("./format"), module.exports);
26
26
  __reExport(src_exports, require("./escPosPrinter"), module.exports);
27
+ __reExport(src_exports, require("./miniRedux"), module.exports);
27
28
  __reExport(src_exports, require("./jsBridge"), module.exports);
29
+ __reExport(src_exports, require("./image"), module.exports);
30
+ __reExport(src_exports, require("./locales"), module.exports);
28
31
  // Annotate the CommonJS export names for ESM import in node:
29
32
  0 && (module.exports = {
30
33
  ...require("./otherUtils"),
@@ -35,5 +38,8 @@ __reExport(src_exports, require("./jsBridge"), module.exports);
35
38
  ...require("./log"),
36
39
  ...require("./format"),
37
40
  ...require("./escPosPrinter"),
38
- ...require("./jsBridge")
41
+ ...require("./miniRedux"),
42
+ ...require("./jsBridge"),
43
+ ...require("./image"),
44
+ ...require("./locales")
39
45
  });
@@ -0,0 +1,12 @@
1
+ export declare const locales: {
2
+ init: (_localeMaps: any, _locale: string) => void;
3
+ getText: (id: string) => any;
4
+ locale: string;
5
+ localeMap: any;
6
+ localeMaps: {
7
+ en: {};
8
+ 'zh-CN': {};
9
+ 'zh-HK': {};
10
+ };
11
+ formatLocale: (_locale: string) => string;
12
+ };
package/lib/locales.js ADDED
@@ -0,0 +1,69 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/locales.ts
20
+ var locales_exports = {};
21
+ __export(locales_exports, {
22
+ locales: () => locales
23
+ });
24
+ module.exports = __toCommonJS(locales_exports);
25
+ var localeMaps = {
26
+ en: {},
27
+ "zh-CN": {},
28
+ "zh-HK": {}
29
+ };
30
+ var locale = "en";
31
+ var localeMap = {};
32
+ var formatLocale = (_locale) => {
33
+ let obj = {
34
+ "en": "en",
35
+ "zh-CN": "zh-CN",
36
+ "zh-HK": "zh-HK",
37
+ "zh-TW": "zh-HK",
38
+ "en-US": "en"
39
+ };
40
+ return obj[_locale] || "en";
41
+ };
42
+ var init = (_localeMaps, _locale) => {
43
+ locale = formatLocale(_locale);
44
+ let allLocales = {};
45
+ for (let key in localeMaps) {
46
+ allLocales[key] = {
47
+ ...localeMaps[key],
48
+ ..._localeMaps[key]
49
+ };
50
+ }
51
+ localeMaps = allLocales;
52
+ localeMap = localeMaps[locale];
53
+ console.log("\u591A\u8BED\u8A00\u6CE8\u5165\u6210\u529F, \u5F53\u524D\u8BED\u8A00\u4E3A:" + locale);
54
+ };
55
+ var getText = (id) => {
56
+ return localeMap[id] || id;
57
+ };
58
+ var locales = {
59
+ init,
60
+ getText,
61
+ locale,
62
+ localeMap,
63
+ localeMaps,
64
+ formatLocale
65
+ };
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ locales
69
+ });
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ interface MiniReduxProps<State, Namespace> {
3
+ namespace?: Namespace;
4
+ state?: State;
5
+ reducers?: any;
6
+ effects?: any;
7
+ }
8
+ export declare const miniRedux: <State extends Record<string, any>, Namespace extends string>({ namespace, state, reducers, effects, }: MiniReduxProps<State, Namespace>) => {
9
+ Context: React.Context<{ [K in Namespace]: State; } & {
10
+ dispatch: (params: {
11
+ type: string;
12
+ payload: any;
13
+ }) => void;
14
+ }>;
15
+ Provider: (ComponentUi: any) => (props: any) => JSX.Element;
16
+ };
17
+ export {};
@@ -0,0 +1,90 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/miniRedux.tsx
30
+ var miniRedux_exports = {};
31
+ __export(miniRedux_exports, {
32
+ miniRedux: () => miniRedux
33
+ });
34
+ module.exports = __toCommonJS(miniRedux_exports);
35
+ var import_react = __toESM(require("react"));
36
+ var miniRedux = ({
37
+ namespace = "state",
38
+ state,
39
+ reducers = {},
40
+ effects = {}
41
+ }) => {
42
+ const Context = (0, import_react.createContext)({});
43
+ const Provider = (ComponentUi) => {
44
+ const Components = (props) => {
45
+ const [providerState, dispatch] = (0, import_react.useReducer)(
46
+ (state2, { type, payload }) => {
47
+ if (reducers[type]) {
48
+ return reducers[type](state2, payload) || state2;
49
+ } else {
50
+ return state2;
51
+ }
52
+ },
53
+ state
54
+ );
55
+ const _dispatch = (0, import_react.useCallback)(({ type, payload }) => {
56
+ if (effects[type]) {
57
+ effects[type].call(null, payload, dispatch);
58
+ } else if (reducers[type]) {
59
+ dispatch({ type, payload });
60
+ }
61
+ }, []);
62
+ let _props = {
63
+ ...props,
64
+ [namespace]: providerState,
65
+ dispatch: _dispatch
66
+ };
67
+ let _ref = null;
68
+ if (_props.forwardedRef) {
69
+ _ref = _props.forwardedRef;
70
+ delete _props.forwardedRef;
71
+ }
72
+ return /* @__PURE__ */ import_react.default.createElement(
73
+ Context.Provider,
74
+ {
75
+ value: { [namespace]: providerState, dispatch: _dispatch }
76
+ },
77
+ /* @__PURE__ */ import_react.default.createElement(ComponentUi, { ..._props, ref: _ref })
78
+ );
79
+ };
80
+ return Components;
81
+ };
82
+ return {
83
+ Context,
84
+ Provider
85
+ };
86
+ };
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ miniRedux
90
+ });
@@ -6,3 +6,25 @@
6
6
  * @return {*}
7
7
  */
8
8
  export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
9
+ /**
10
+ * @title: 对数组进行增|删
11
+ * @description: 用于多选选中和取消选中的处理
12
+ * @param {any} list
13
+ * @param {any} item
14
+ * @param {string} key
15
+ * @return {*}
16
+ * @Author: zhiwei.Wang
17
+ * @Date: 2023-12-19 16:44
18
+ */
19
+ export declare const changeArray: <T>(list: T[] | undefined, item: T, key?: string) => T[];
20
+ /**
21
+ * @title: 判断某个字段是否在列表内
22
+ * @description:
23
+ * @param {*} T
24
+ * @param {boolean} param2
25
+ * @return {*}
26
+ * @Author: zhiwei.Wang
27
+ * @Date: 2023-12-19 16:54
28
+ */
29
+ export declare const getItemByArray: <T>(list: T[] | undefined, item: T, key?: string) => boolean;
30
+ export declare const createArray: (length: number, returnItem: any) => any;
package/lib/otherUtils.js CHANGED
@@ -19,13 +19,48 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/otherUtils.ts
20
20
  var otherUtils_exports = {};
21
21
  __export(otherUtils_exports, {
22
+ changeArray: () => changeArray,
23
+ createArray: () => createArray,
24
+ getItemByArray: () => getItemByArray,
22
25
  getUniqueId: () => getUniqueId
23
26
  });
24
27
  module.exports = __toCommonJS(otherUtils_exports);
25
28
  var getUniqueId = (prefix = "", maxLength = 11) => {
26
29
  return prefix + (Math.random() + "").replace(/\D/g, "").substring(0, maxLength);
27
30
  };
31
+ var changeArray = (list = [], item, key = "this") => {
32
+ let _list = JSON.parse(JSON.stringify(list));
33
+ let isSome = false;
34
+ if (key === "this") {
35
+ isSome = _list.includes(item);
36
+ } else {
37
+ isSome = _list.some((d) => d[key] === item[key]);
38
+ }
39
+ if (isSome) {
40
+ _list = _list.filter((d) => {
41
+ if (key === "this") {
42
+ return d !== item;
43
+ }
44
+ return d[key] !== item[key];
45
+ });
46
+ } else {
47
+ _list.push(item);
48
+ }
49
+ return _list;
50
+ };
51
+ var getItemByArray = (list = [], item, key = "this") => {
52
+ if (key === "this") {
53
+ return list.includes(item);
54
+ }
55
+ return list.some((d) => d[key] === item[key]);
56
+ };
57
+ var createArray = (length, returnItem) => {
58
+ return Array.from(new Array(length)).map(returnItem);
59
+ };
28
60
  // Annotate the CommonJS export names for ESM import in node:
29
61
  0 && (module.exports = {
62
+ changeArray,
63
+ createArray,
64
+ getItemByArray,
30
65
  getUniqueId
31
66
  });
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@pisell/utils",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",
7
7
  "types": "./lib/index.d.ts",
8
8
  "typings": "./lib/index.d.ts",
9
9
  "devDependencies": {
10
+ "react": "^18.0.0",
10
11
  "father": "^4.1.0",
11
12
  "dayjs": "^1.11.9"
12
13
  },