@ray-js/api 1.3.1-beta.0 → 1.3.1-beta.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.
@@ -112,7 +112,7 @@ declare namespace ty {
112
112
  */
113
113
  export function startAccelerometer(params?: {
114
114
  /** 监听加速度数据回调函数的执行频率 */
115
- interval?: AccelerometerInterval | keyof typeof AccelerometerInterval
115
+ interval?: keyof typeof AccelerometerInterval
116
116
  complete?: () => void
117
117
  success?: (params: null) => void
118
118
  failure?: (params: {
@@ -269,7 +269,7 @@ declare namespace ty {
269
269
  */
270
270
  export function startDeviceMotionListening(params?: {
271
271
  /** 监听加速度数据回调函数的执行频率 */
272
- interval?: DeviceMotionInterval | keyof typeof DeviceMotionInterval
272
+ interval?: keyof typeof DeviceMotionInterval
273
273
  complete?: () => void
274
274
  success?: (params: null) => void
275
275
  failure?: (params: {
@@ -322,7 +322,7 @@ declare namespace ty {
322
322
  */
323
323
  export function startGyroscope(params?: {
324
324
  /** 监听陀螺仪数据回调函数的执行频率 */
325
- interval?: GyroscopeInterval | keyof typeof GyroscopeInterval
325
+ interval?: keyof typeof GyroscopeInterval
326
326
  complete?: () => void
327
327
  success?: (params: null) => void
328
328
  failure?: (params: {
@@ -999,8 +999,8 @@ declare namespace ty {
999
999
  bluetoothEnabled: boolean
1000
1000
  locationEnabled: boolean
1001
1001
  wifiEnabled: boolean
1002
- theme?: Themes | keyof typeof Themes
1003
- deviceOrientation?: Orientation | keyof typeof Orientation
1002
+ theme?: keyof typeof Themes
1003
+ deviceOrientation?: keyof typeof Orientation
1004
1004
  /** 设备等级(低:low-中:middle-高:high) */
1005
1005
  deviceLevel: string
1006
1006
  }) => void
@@ -1047,8 +1047,8 @@ declare namespace ty {
1047
1047
  bluetoothEnabled: boolean
1048
1048
  locationEnabled: boolean
1049
1049
  wifiEnabled: boolean
1050
- theme?: Themes | keyof typeof Themes
1051
- deviceOrientation?: Orientation | keyof typeof Orientation
1050
+ theme?: keyof typeof Themes
1051
+ deviceOrientation?: keyof typeof Orientation
1052
1052
  /** 设备等级(低:low-中:middle-高:high) */
1053
1053
  deviceLevel: string
1054
1054
  }
@@ -1891,11 +1891,11 @@ declare namespace ty {
1891
1891
  /** 小部件样式,默认middle */
1892
1892
  style?: string
1893
1893
  /** 版本类型,默认release */
1894
- versionType?: WidgetVersionType | keyof typeof WidgetVersionType
1894
+ versionType?: keyof typeof WidgetVersionType
1895
1895
  /** 版本号 */
1896
1896
  version?: string
1897
1897
  /** 展示位置,默认bottom */
1898
- position?: WidgetPosition | keyof typeof WidgetPosition
1898
+ position?: keyof typeof WidgetPosition
1899
1899
  /** 点击空白处是否关闭 */
1900
1900
  autoDismiss?: boolean
1901
1901
  /**
@@ -1914,7 +1914,7 @@ declare namespace ty {
1914
1914
 
1915
1915
  export type DeviceMotionBean = {
1916
1916
  /** 监听加速度数据回调函数的执行频率 */
1917
- interval?: DeviceMotionInterval | keyof typeof DeviceMotionInterval
1917
+ interval?: keyof typeof DeviceMotionInterval
1918
1918
  }
1919
1919
 
1920
1920
  export type DownLoadBean = {
@@ -1980,7 +1980,7 @@ declare namespace ty {
1980
1980
 
1981
1981
  export type GyroscopeBean = {
1982
1982
  /** 监听陀螺仪数据回调函数的执行频率 */
1983
- interval?: GyroscopeInterval | keyof typeof GyroscopeInterval
1983
+ interval?: keyof typeof GyroscopeInterval
1984
1984
  }
1985
1985
 
1986
1986
  export type ChooseImageBean = {
@@ -2194,7 +2194,7 @@ declare namespace ty {
2194
2194
  /** 超时时间,单位为毫秒 */
2195
2195
  timeout?: number
2196
2196
  /** HTTP 请求方法 */
2197
- method?: HTTPMethod | keyof typeof HTTPMethod
2197
+ method?: keyof typeof HTTPMethod
2198
2198
  /** 返回的数据格式 */
2199
2199
  dataType?: any
2200
2200
  /** 返回的数据类型 */
@@ -2348,8 +2348,8 @@ declare namespace ty {
2348
2348
  bluetoothEnabled: boolean
2349
2349
  locationEnabled: boolean
2350
2350
  wifiEnabled: boolean
2351
- theme?: Themes | keyof typeof Themes
2352
- deviceOrientation?: Orientation | keyof typeof Orientation
2351
+ theme?: keyof typeof Themes
2352
+ deviceOrientation?: keyof typeof Orientation
2353
2353
  /** 设备等级(低:low-中:middle-高:high) */
2354
2354
  deviceLevel: string
2355
2355
  }
@@ -2668,11 +2668,11 @@ declare namespace ty {
2668
2668
  /** 小部件样式,默认middle */
2669
2669
  style?: string
2670
2670
  /** 版本类型,默认release */
2671
- versionType?: WidgetVersionType | keyof typeof WidgetVersionType
2671
+ versionType?: keyof typeof WidgetVersionType
2672
2672
  /** 版本号 */
2673
2673
  version?: string
2674
2674
  /** 展示位置,默认bottom */
2675
- position?: WidgetPosition | keyof typeof WidgetPosition
2675
+ position?: keyof typeof WidgetPosition
2676
2676
  /** 点击空白处是否关闭 */
2677
2677
  autoDismiss?: boolean
2678
2678
  /**
@@ -3095,7 +3095,7 @@ declare namespace ty {
3095
3095
  /** 超时时间,单位为毫秒 */
3096
3096
  timeout?: number
3097
3097
  /** HTTP 请求方法 */
3098
- method?: HTTPMethod | keyof typeof HTTPMethod
3098
+ method?: keyof typeof HTTPMethod
3099
3099
  /** 返回的数据格式 */
3100
3100
  dataType?: any
3101
3101
  /** 返回的数据类型 */
@@ -325,7 +325,7 @@ declare namespace ty {
325
325
  /** data 请求入参 */
326
326
  data?: Record<string, any>
327
327
  /** method 请求方法 */
328
- method?: HighwayMethod | keyof typeof HighwayMethod
328
+ method?: keyof typeof HighwayMethod
329
329
  complete?: () => void
330
330
  success?: (params: {
331
331
  /**
@@ -1245,7 +1245,7 @@ declare namespace ty {
1245
1245
  /** data 请求入参 */
1246
1246
  data?: Record<string, any>
1247
1247
  /** method 请求方法 */
1248
- method?: HighwayMethod | keyof typeof HighwayMethod
1248
+ method?: keyof typeof HighwayMethod
1249
1249
  }
1250
1250
 
1251
1251
  export type HighwayRequestResponse = {
@@ -1,4 +1,4 @@
1
- /// <reference path="../@types/PlayNetKit.d.ts" />
1
+ /// <reference path="../@types/HomeKit.d.ts" />
2
2
  export declare const home: {
3
3
  getCurrentHomeInfo: typeof ty.home.getCurrentHomeInfo;
4
4
  getDeviceIdList: typeof ty.home.getDeviceIdList;
@@ -1,8 +1,16 @@
1
- /// <reference path="../@types/PlayNetKit.d.ts" />
1
+ /// <reference path="../@types/HomeKit.d.ts" />
2
2
  import { factory } from './utils';
3
3
  export var home = {
4
- getCurrentHomeInfo: factory('getCurrentHomeInfo'),
5
- getDeviceIdList: factory('getDeviceIdList'),
6
- getRoomList: factory('getRoomList'),
7
- getDeviceRoomInfo: factory('getDeviceRoomInfo')
4
+ getCurrentHomeInfo: factory('getCurrentHomeInfo', {
5
+ "namespace": "home"
6
+ }),
7
+ getDeviceIdList: factory('getDeviceIdList', {
8
+ "namespace": "home"
9
+ }),
10
+ getRoomList: factory('getRoomList', {
11
+ "namespace": "home"
12
+ }),
13
+ getDeviceRoomInfo: factory('getDeviceRoomInfo', {
14
+ "namespace": "home"
15
+ })
8
16
  };
@@ -1,4 +1,4 @@
1
- /// <reference path="../@types/PlayNetKit.d.ts" />
1
+ /// <reference path="../@types/MapKit.d.ts" />
2
2
  export declare const map: {
3
3
  chooseLocation: typeof ty.map.chooseLocation;
4
4
  getLocation: typeof ty.map.getLocation;
@@ -1,14 +1,32 @@
1
- /// <reference path="../@types/PlayNetKit.d.ts" />
1
+ /// <reference path="../@types/MapKit.d.ts" />
2
2
  import { factory } from './utils'; // ray 1.1.0 集成
3
3
 
4
4
  export var map = {
5
- chooseLocation: factory('chooseLocation'),
6
- getLocation: factory('getLocation'),
7
- getMapList: factory('getMapList'),
8
- isGeofenceReachLimit: factory('isGeofenceReachLimit'),
9
- openGeofenceMap: factory('openGeofenceMap'),
10
- openMapAppLocation: factory('openMapAppLocation'),
11
- registerGeofence: factory('registerGeofence'),
12
- unregisterGeofence: factory('unregisterGeofence'),
13
- updateGeofence: factory('updateGeofence')
5
+ chooseLocation: factory('chooseLocation', {
6
+ "namespace": "map"
7
+ }),
8
+ getLocation: factory('getLocation', {
9
+ "namespace": "map"
10
+ }),
11
+ getMapList: factory('getMapList', {
12
+ "namespace": "map"
13
+ }),
14
+ isGeofenceReachLimit: factory('isGeofenceReachLimit', {
15
+ "namespace": "map"
16
+ }),
17
+ openGeofenceMap: factory('openGeofenceMap', {
18
+ "namespace": "map"
19
+ }),
20
+ openMapAppLocation: factory('openMapAppLocation', {
21
+ "namespace": "map"
22
+ }),
23
+ registerGeofence: factory('registerGeofence', {
24
+ "namespace": "map"
25
+ }),
26
+ unregisterGeofence: factory('unregisterGeofence', {
27
+ "namespace": "map"
28
+ }),
29
+ updateGeofence: factory('updateGeofence', {
30
+ "namespace": "map"
31
+ })
14
32
  };
@@ -1,28 +1,76 @@
1
1
  /// <reference path="../@types/PlayNetKit.d.ts" />
2
2
  import { factory } from './utils';
3
3
  export var playnet = {
4
- autoConnectToAp: factory('autoConnectToAp'),
5
- getDeviceSecurityConfigs: factory('getDeviceSecurityConfigs'),
6
- getPairConfigToken: factory('getPairConfigToken'),
7
- hasBlePermission: factory('hasBlePermission'),
8
- hasLocalNetworkPermission: factory('hasLocalNetworkPermission'),
9
- hasPermission: factory('hasPermission'),
10
- isSystemPopupInAutoConnectAp: factory('isSystemPopupInAutoConnectAp'),
11
- offBLEScanDevice: factory('offBLEScanDevice'),
12
- offBLEStateChange: factory('offBLEStateChange'),
13
- offBlePermissionChange: factory('offBlePermissionChange'),
14
- offWifiStateChange: factory('offWifiStateChange'),
15
- offlocalNetWorkPermissionChange: factory('offlocalNetWorkPermissionChange'),
16
- onBLEScanDevice: factory('onBLEScanDevice'),
17
- onBLEStateChange: factory('onBLEStateChange'),
18
- onBlePermissionChange: factory('onBlePermissionChange'),
19
- onWifiStateChange: factory('onWifiStateChange'),
20
- onlocalNetWorkPermissionChange: factory('onlocalNetWorkPermissionChange'),
21
- queryDeviceConfigState: factory('queryDeviceConfigState'),
22
- requestPermission: factory('requestPermission'),
23
- resetDevice: factory('resetDevice'),
24
- startActivator: factory('startActivator'),
25
- startBLEScanDevice: factory('startBLEScanDevice'),
26
- stopActivator: factory('stopActivator'),
27
- stopBLEScan: factory('stopBLEScan')
4
+ autoConnectToAp: factory('autoConnectToAp', {
5
+ "namespace": "playnet"
6
+ }),
7
+ getDeviceSecurityConfigs: factory('getDeviceSecurityConfigs', {
8
+ "namespace": "playnet"
9
+ }),
10
+ getPairConfigToken: factory('getPairConfigToken', {
11
+ "namespace": "playnet"
12
+ }),
13
+ hasBlePermission: factory('hasBlePermission', {
14
+ "namespace": "playnet"
15
+ }),
16
+ hasLocalNetworkPermission: factory('hasLocalNetworkPermission', {
17
+ "namespace": "playnet"
18
+ }),
19
+ hasPermission: factory('hasPermission', {
20
+ "namespace": "playnet"
21
+ }),
22
+ isSystemPopupInAutoConnectAp: factory('isSystemPopupInAutoConnectAp', {
23
+ "namespace": "playnet"
24
+ }),
25
+ offBLEScanDevice: factory('offBLEScanDevice', {
26
+ "namespace": "playnet"
27
+ }),
28
+ offBLEStateChange: factory('offBLEStateChange', {
29
+ "namespace": "playnet"
30
+ }),
31
+ offBlePermissionChange: factory('offBlePermissionChange', {
32
+ "namespace": "playnet"
33
+ }),
34
+ offWifiStateChange: factory('offWifiStateChange', {
35
+ "namespace": "playnet"
36
+ }),
37
+ offlocalNetWorkPermissionChange: factory('offlocalNetWorkPermissionChange', {
38
+ "namespace": "playnet"
39
+ }),
40
+ onBLEScanDevice: factory('onBLEScanDevice', {
41
+ "namespace": "playnet"
42
+ }),
43
+ onBLEStateChange: factory('onBLEStateChange', {
44
+ "namespace": "playnet"
45
+ }),
46
+ onBlePermissionChange: factory('onBlePermissionChange', {
47
+ "namespace": "playnet"
48
+ }),
49
+ onWifiStateChange: factory('onWifiStateChange', {
50
+ "namespace": "playnet"
51
+ }),
52
+ onlocalNetWorkPermissionChange: factory('onlocalNetWorkPermissionChange', {
53
+ "namespace": "playnet"
54
+ }),
55
+ queryDeviceConfigState: factory('queryDeviceConfigState', {
56
+ "namespace": "playnet"
57
+ }),
58
+ requestPermission: factory('requestPermission', {
59
+ "namespace": "playnet"
60
+ }),
61
+ resetDevice: factory('resetDevice', {
62
+ "namespace": "playnet"
63
+ }),
64
+ startActivator: factory('startActivator', {
65
+ "namespace": "playnet"
66
+ }),
67
+ startBLEScanDevice: factory('startBLEScanDevice', {
68
+ "namespace": "playnet"
69
+ }),
70
+ stopActivator: factory('stopActivator', {
71
+ "namespace": "playnet"
72
+ }),
73
+ stopBLEScan: factory('stopBLEScan', {
74
+ "namespace": "playnet"
75
+ })
28
76
  };
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference path="../@types/api.d.ts" />
2
+ export * from './constants';
2
3
  export * from './all-kits';
3
4
  export * from './lifecycles';
4
5
  export { default as getApp } from './getApp';
@@ -25,11 +26,8 @@ export { default as getCdnUrl } from './getCdnUrl';
25
26
  */
26
27
  export { default as globalApi } from './global-api';
27
28
  export * from './cloud';
28
- /**
29
- * panel-sdk中一些面板小程序中必用API
30
- */
31
- export * from './panel';
32
29
  /**
33
30
  * 0.10.3将一部分未支持的api导入
34
31
  */
35
32
  export * from './viewAPI';
33
+ export * from './panel';
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference path="../@types/api.d.ts" />
2
+ export * from './constants';
2
3
  export * from './all-kits';
3
4
  export * from './lifecycles';
4
5
  export { default as getApp } from './getApp';
@@ -26,13 +27,9 @@ export { default as getCdnUrl } from './getCdnUrl';
26
27
 
27
28
  export { default as globalApi } from './global-api';
28
29
  export * from './cloud';
29
- /**
30
- * panel-sdk中一些面板小程序中必用API
31
- */
32
-
33
- export * from './panel';
34
30
  /**
35
31
  * 0.10.3将一部分未支持的api导入
36
32
  */
37
33
 
38
- export * from './viewAPI';
34
+ export * from './viewAPI';
35
+ export * from './panel';
@@ -4,7 +4,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import "core-js/modules/es.object.to-string.js";
5
5
  import "core-js/modules/web.dom-collections.for-each.js";
6
6
  import "core-js/modules/es.promise.js";
7
- import { getDeviceInfo, getLaunchOptionsSync, getGroupInfo, getApp, registerDeviceListListener, registerGroupChange, exitMiniProgram, subscribeDeviceRemoved, onDeviceRemoved } from '../../';
7
+ import { getDeviceInfo, getLaunchOptionsSync, getGroupInfo, getApp, registerDeviceListListener, registerGroupChange, exitMiniProgram, subscribeDeviceRemoved, onDeviceRemoved } from '@ray-js/api';
8
8
  // 本地化缓存 deviceInfo 方便随时调用
9
9
  var __deviceInfo = null;
10
10
  var defaultPanelEnvironmentOptions = {
@@ -121,6 +121,7 @@ function _initPanelEnvironment() {
121
121
 
122
122
  case 5:
123
123
  App = getApp(); // 基础库版本需要大于 2.6.0
124
+ // @ts-ignore
124
125
 
125
126
  App.onReady = function (event) {
126
127
  var _options$deviceId, _options$groupId;
@@ -0,0 +1,39 @@
1
+ declare type LanguageMap = {
2
+ [key: string]: Record<string, string>;
3
+ };
4
+ export default class I18N {
5
+ [x: string]: any;
6
+ strings: LanguageMap;
7
+ defaultLang: string;
8
+ __language: string;
9
+ constructor(props: LanguageMap);
10
+ forceUpdateNetworkLang(productId: string): void;
11
+ mergeLanguage(L1: LanguageMap, L2: LanguageMap): LanguageMap;
12
+ isZh(language: string): boolean;
13
+ setLanguage(language: string): void;
14
+ buildLanguage(language: string): void;
15
+ _getBestMatchingLanguage(language: string, props: LanguageMap): any;
16
+ formatString(str: string, ...values: any[]): string;
17
+ formatValue(key: string, ...values: any[]): any;
18
+ _replaceAll(find: string, replace: string, str: string): string;
19
+ getDpLang(code: string | number, value?: undefined | boolean | string): any;
20
+ getDpName(code: string, defaultName: string): any;
21
+ getDpsLang(key: {
22
+ [key: string]: string;
23
+ }): {};
24
+ getLang(key: string, defaultString?: string): any;
25
+ /**
26
+ * 获取picker标题
27
+ * @param {*} dpCode
28
+ */
29
+ getRangeStrings(dpCode: string, schema: Record<string, any>): {};
30
+ /**
31
+ * 开关倒计时转换为文案 time => 设备将在xxx后 关闭/开启
32
+ * 精确到分钟
33
+ * @param {*} t 倒计时剩余(秒)
34
+ * @param {*} power 设备当前的开关状态 (如果当前设备为开启状态, 则倒计时显示为关闭)
35
+ */
36
+ parseCountdown(t: number, power: boolean): string;
37
+ getFaultStrings(schema: Record<string, any>, faultCode: number | string, faultValue: number, onlyPrior?: boolean): string;
38
+ }
39
+ export {};
@@ -0,0 +1,293 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ import "core-js/modules/es.object.keys.js";
5
+ import "core-js/modules/es.object.assign.js";
6
+ import "core-js/modules/es.array.map.js";
7
+ import "core-js/modules/es.regexp.exec.js";
8
+ import "core-js/modules/es.regexp.test.js";
9
+ import "core-js/modules/es.array.last-index-of.js";
10
+ import "core-js/modules/es.string.replace.js";
11
+ import "core-js/modules/es.regexp.constructor.js";
12
+ import "core-js/modules/es.regexp.dot-all.js";
13
+ import "core-js/modules/es.regexp.sticky.js";
14
+ import "core-js/modules/es.regexp.to-string.js";
15
+ import "core-js/modules/es.array.concat.js";
16
+ import "core-js/modules/es.parse-float.js";
17
+ import { requestCloud, getSystemInfoSync, THING } from '../..';
18
+ import { getBitValue } from '../utils';
19
+ /**
20
+ * I18n 智能小程序中用来获取多语言的对象
21
+ * 文档: https://developer.tuya.com/cn/miniapp/framework/app/i18n
22
+ */
23
+
24
+ var I18N = /*#__PURE__*/function () {
25
+ function I18N(props) {
26
+ _classCallCheck(this, I18N);
27
+
28
+ this.strings = this.mergeLanguage(props, {});
29
+ this.defaultLang = this.strings.en ? 'en' : Object.keys(this.strings)[0];
30
+ this.setLanguage(this.defaultLang);
31
+ var langKey = getSystemInfoSync().language;
32
+ this.setLanguage(langKey);
33
+ }
34
+
35
+ _createClass(I18N, [{
36
+ key: "forceUpdateNetworkLang",
37
+ value: function forceUpdateNetworkLang(productId) {
38
+ var _this = this;
39
+
40
+ requestCloud({
41
+ api: "".concat(THING, ".m.i18n.get"),
42
+ version: '1.0',
43
+ data: {
44
+ productId: productId,
45
+ moduleName: 'h5',
46
+ endId: 2,
47
+ osId: 0
48
+ },
49
+ // @ts-ignore
50
+ success: function success(data) {
51
+ if (data) {
52
+ _this.strings = _this.mergeLanguage(_this.strings, data);
53
+
54
+ _this.buildLanguage(_this.__language);
55
+ }
56
+ }
57
+ });
58
+ }
59
+ }, {
60
+ key: "mergeLanguage",
61
+ value: function mergeLanguage(L1, L2) {
62
+ if (typeof L1 === 'undefined' && typeof L2 === 'undefined') return {};
63
+ if (typeof L1 === 'undefined') return L2;
64
+ if (typeof L2 === 'undefined') return L1;
65
+ var L0 = Object.assign({}, L1);
66
+ Object.keys(L2).map(function (k) {
67
+ if (typeof L0[k] !== 'undefined') {
68
+ Object.assign(L0[k], L2[k]);
69
+ } else {
70
+ L0[k] = Object.assign({}, L2[k]);
71
+ }
72
+
73
+ return null;
74
+ });
75
+ return L0;
76
+ }
77
+ }, {
78
+ key: "isZh",
79
+ value: function isZh(language) {
80
+ /**
81
+ * ios 的中文简体固定为 zh-Hans,
82
+ * 但安卓的中文简体可能有一大堆排列组件 = =,如 zh_CN、zh_cn、zh_Hans_CH、zh_hans_cn 等等;
83
+ */
84
+
85
+ /**
86
+ * 如果匹配到位中文简体地区,
87
+ * 则将中文 zh 相关的 values 都写入到 this.strings 下,保证兜底本地 zh 相关的能取到,
88
+ * 再将当前地区 key 相关的 values 都写入到 this.strings 下,优先级最高;
89
+ */
90
+ if (typeof language === 'string' && /^zh-hans$|^zh_hans$|^zh_cn$|^zh-cn$|^zh_hans_\w+|^zh-hans-\w+/.test(language.toLowerCase())) {
91
+ return true;
92
+ }
93
+
94
+ return false;
95
+ }
96
+ }, {
97
+ key: "setLanguage",
98
+ value: function setLanguage(language) {
99
+ this.__language = language;
100
+
101
+ if (this.isZh(language)) {
102
+ this.buildLanguage('zh');
103
+ this.buildLanguage(language);
104
+ } else {
105
+ this.buildLanguage(this.__language);
106
+ }
107
+ }
108
+ }, {
109
+ key: "buildLanguage",
110
+ value: function buildLanguage(language) {
111
+ var _this2 = this;
112
+
113
+ if (this.strings[language]) {
114
+ var localizedStrings = this.strings[language];
115
+ Object.keys(localizedStrings).map(function (key) {
116
+ // eslint-disable-next-line no-prototype-builtins
117
+ if (localizedStrings.hasOwnProperty(key)) {
118
+ _this2[key] = localizedStrings[key];
119
+ }
120
+
121
+ return null;
122
+ });
123
+ }
124
+ }
125
+ }, {
126
+ key: "_getBestMatchingLanguage",
127
+ value: function _getBestMatchingLanguage(language, props) {
128
+ if (props[language]) return language;
129
+ var idx = language.lastIndexOf('-');
130
+
131
+ if (idx >= 0) {
132
+ var lang = language.substring(0, idx);
133
+ return this._getBestMatchingLanguage(lang, props);
134
+ }
135
+
136
+ var underlineIdx = language.lastIndexOf('_');
137
+
138
+ if (underlineIdx >= 0) {
139
+ var _lang = language.substring(0, underlineIdx);
140
+
141
+ return this._getBestMatchingLanguage(_lang, props);
142
+ }
143
+
144
+ return this.defaultLang;
145
+ } // Format the passed string replacing the numbered placeholders
146
+ // i.e. I'd like some {0} and {1}, or just {0}
147
+ // Use example:
148
+ // strings.formatString(strings.question, strings.bread, strings.butter)
149
+
150
+ }, {
151
+ key: "formatString",
152
+ value: function formatString(str) {
153
+ var res = str;
154
+
155
+ for (var i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
156
+ res = this._replaceAll("{".concat(i, "}"), i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1], res);
157
+ }
158
+
159
+ return res;
160
+ }
161
+ }, {
162
+ key: "formatValue",
163
+ value: function formatValue(key) {
164
+ var res = typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
165
+
166
+ for (var i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
167
+ res = this._replaceAll("{".concat(i, "}"), i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1], res);
168
+ }
169
+
170
+ return res;
171
+ }
172
+ }, {
173
+ key: "_replaceAll",
174
+ value: function _replaceAll(find, replace, str) {
175
+ // eslint-disable-next-line no-useless-escape, no-param-reassign
176
+ find = find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
177
+ if (!str) return '';
178
+ return str.replace(new RegExp(find, 'g'), replace);
179
+ }
180
+ }, {
181
+ key: "getDpLang",
182
+ value: function getDpLang(code, value) {
183
+ var key;
184
+
185
+ if (typeof value === 'undefined') {
186
+ key = "dp_".concat(code).toLowerCase();
187
+ } else if (typeof value === 'boolean') {
188
+ var valStr = value ? 'on' : 'off';
189
+ key = "dp_".concat(code, "_").concat(valStr).toLowerCase();
190
+ } else {
191
+ key = "dp_".concat(code, "_").concat(value).toLowerCase();
192
+ }
193
+
194
+ return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
195
+ }
196
+ }, {
197
+ key: "getDpName",
198
+ value: function getDpName(code, defaultName) {
199
+ var key = "dp_".concat(code).toLowerCase();
200
+ return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : defaultName;
201
+ }
202
+ }, {
203
+ key: "getDpsLang",
204
+ value: function getDpsLang(key) {
205
+ var _this3 = this;
206
+
207
+ var strs = {};
208
+
209
+ if (_typeof(key) === 'object') {
210
+ if (typeof key.strKey === 'string') {
211
+ strs = I18n.t(key.strKey) !== key.strKey ? I18n.t(key.strKey) : typeof this[key.strKey] !== 'undefined' ? this[key.strKey] : I18n.t(key.strKey);
212
+ } else {
213
+ Object.keys(key).map(function (i) {
214
+ strs[key[i]] = I18n.t(key[i]) !== key[i] ? I18n.t(key[i]) : typeof _this3[key[i]] !== 'undefined' ? _this3[key[i]] : I18n.t(key[i]);
215
+ return null;
216
+ });
217
+ }
218
+ } else {
219
+ strs = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
220
+ }
221
+
222
+ return strs;
223
+ }
224
+ }, {
225
+ key: "getLang",
226
+ value: function getLang(key, defaultString) {
227
+ return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : typeof defaultString !== 'undefined' ? defaultString : I18n.t(key);
228
+ }
229
+ /**
230
+ * 获取picker标题
231
+ * @param {*} dpCode
232
+ */
233
+
234
+ }, {
235
+ key: "getRangeStrings",
236
+ value: function getRangeStrings(dpCode, schema) {
237
+ var _this4 = this;
238
+
239
+ var result = {};
240
+ if (typeof schema === 'undefined') return result;
241
+ var lists = schema.range;
242
+ lists.map(function (v) {
243
+ var key = "dp_".concat(dpCode, "_").concat(v).toLowerCase();
244
+ result[v] = I18n.t(key) !== key ? I18n.t(key) : typeof _this4[key] !== 'undefined' ? _this4[key] : I18n.t(key);
245
+ return null;
246
+ });
247
+ return result;
248
+ }
249
+ /**
250
+ * 开关倒计时转换为文案 time => 设备将在xxx后 关闭/开启
251
+ * 精确到分钟
252
+ * @param {*} t 倒计时剩余(秒)
253
+ * @param {*} power 设备当前的开关状态 (如果当前设备为开启状态, 则倒计时显示为关闭)
254
+ */
255
+
256
+ }, {
257
+ key: "parseCountdown",
258
+ value: function parseCountdown(t, power) {
259
+ var h = parseFloat("".concat(t / 3600));
260
+ var m = parseFloat("".concat(t / 60 - h * 60));
261
+ var tHour = I18n.t('t_hour') !== 't_hour' ? I18n.t('t_hour') : typeof this.t_hour !== 'undefined' ? this.t_hour : I18n.t('t_hour');
262
+ var tMinute = I18n.t('t_minute') !== 't_minute' ? I18n.t('t_minute') : typeof this.t_minute !== 'undefined' ? this.t_minute : I18n.t('t_minute');
263
+ var time = h >= 1.0 ? "".concat(Math.round(h)).concat(tHour) : "".concat(Math.round(m)).concat(tMinute);
264
+ var key = "countdown_".concat(power ? 'on' : 'off');
265
+ var str = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
266
+ return this.formatString(str, time);
267
+ }
268
+ }, {
269
+ key: "getFaultStrings",
270
+ value: function getFaultStrings(schema, faultCode, faultValue) {
271
+ var onlyPrior = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
272
+ if (!faultValue) return '';
273
+ var label = schema.label;
274
+ var labels = [];
275
+
276
+ for (var i = 0; i < label.length; i++) {
277
+ var value = label[i];
278
+ var isExist = getBitValue(faultValue, i);
279
+
280
+ if (isExist) {
281
+ labels.push(this.getDpLang(faultCode, value));
282
+ if (onlyPrior) break;
283
+ }
284
+ }
285
+
286
+ return onlyPrior ? labels[0] : labels.join(', ');
287
+ }
288
+ }]);
289
+
290
+ return I18N;
291
+ }();
292
+
293
+ export { I18N as default };
@@ -0,0 +1,39 @@
1
+ declare type LanguageMap = {
2
+ [key: string]: Record<string, string>;
3
+ };
4
+ export default class I18N {
5
+ [x: string]: any;
6
+ strings: LanguageMap;
7
+ defaultLang: string;
8
+ __language: string;
9
+ constructor(props: LanguageMap);
10
+ forceUpdateNetworkLang(productId: string): void;
11
+ mergeLanguage(L1: LanguageMap, L2: LanguageMap): LanguageMap;
12
+ isZh(language: string): boolean;
13
+ setLanguage(language: string): void;
14
+ buildLanguage(language: string): void;
15
+ _getBestMatchingLanguage(language: string, props: LanguageMap): any;
16
+ formatString(str: string, ...values: any[]): string;
17
+ formatValue(key: string, ...values: any[]): any;
18
+ _replaceAll(find: string, replace: string, str: string): string;
19
+ getDpLang(code: string | number, value?: undefined | boolean | string): any;
20
+ getDpName(code: string, defaultName: string): any;
21
+ getDpsLang(key: {
22
+ [key: string]: string;
23
+ }): {};
24
+ getLang(key: string, defaultString?: string): any;
25
+ /**
26
+ * 获取picker标题
27
+ * @param {*} dpCode
28
+ */
29
+ getRangeStrings(dpCode: string, schema: Record<string, any>): {};
30
+ /**
31
+ * 开关倒计时转换为文案 time => 设备将在xxx后 关闭/开启
32
+ * 精确到分钟
33
+ * @param {*} t 倒计时剩余(秒)
34
+ * @param {*} power 设备当前的开关状态 (如果当前设备为开启状态, 则倒计时显示为关闭)
35
+ */
36
+ parseCountdown(t: number, power: boolean): string;
37
+ getFaultStrings(schema: Record<string, any>, faultCode: number | string, faultValue: number, onlyPrior?: boolean): string;
38
+ }
39
+ export {};
@@ -0,0 +1,302 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ import "core-js/modules/es.object.keys.js";
5
+ import "core-js/modules/es.object.assign.js";
6
+ import "core-js/modules/es.array.map.js";
7
+ import "core-js/modules/es.regexp.exec.js";
8
+ import "core-js/modules/es.regexp.test.js";
9
+ import "core-js/modules/es.array.last-index-of.js";
10
+ import "core-js/modules/es.string.replace.js";
11
+ import "core-js/modules/es.regexp.constructor.js";
12
+ import "core-js/modules/es.regexp.dot-all.js";
13
+ import "core-js/modules/es.regexp.sticky.js";
14
+ import "core-js/modules/es.regexp.to-string.js";
15
+ import "core-js/modules/es.array.concat.js";
16
+ import "core-js/modules/es.parse-float.js";
17
+ import { requestCloud, getSystemInfoSync, THING } from '../..';
18
+ import { getBitValue } from '../utils'; // /**
19
+ // * I18n 智能小程序中用来获取多语言的对象
20
+ // * 文档: https://developer.tuya.com/cn/miniapp/framework/app/i18n
21
+ // */
22
+ // declare class I18n {
23
+ // static t: (key: string) => string;
24
+ // }
25
+ // 微信小程序暂时只支持本地多语言
26
+
27
+ var I18n = {
28
+ t: function t(key) {
29
+ return key;
30
+ }
31
+ };
32
+
33
+ var I18N = /*#__PURE__*/function () {
34
+ function I18N(props) {
35
+ _classCallCheck(this, I18N);
36
+
37
+ this.strings = this.mergeLanguage(props, {});
38
+ this.defaultLang = this.strings.en ? 'en' : Object.keys(this.strings)[0];
39
+ this.setLanguage(this.defaultLang);
40
+ var langKey = getSystemInfoSync().language;
41
+ this.setLanguage(langKey);
42
+ }
43
+
44
+ _createClass(I18N, [{
45
+ key: "forceUpdateNetworkLang",
46
+ value: function forceUpdateNetworkLang(productId) {
47
+ var _this = this;
48
+
49
+ requestCloud({
50
+ api: "".concat(THING, ".m.i18n.get"),
51
+ version: '1.0',
52
+ data: {
53
+ productId: productId,
54
+ moduleName: 'h5',
55
+ endId: 2,
56
+ osId: 0
57
+ },
58
+ // @ts-ignore
59
+ success: function success(data) {
60
+ if (data) {
61
+ _this.strings = _this.mergeLanguage(_this.strings, data);
62
+
63
+ _this.buildLanguage(_this.__language);
64
+ }
65
+ }
66
+ });
67
+ }
68
+ }, {
69
+ key: "mergeLanguage",
70
+ value: function mergeLanguage(L1, L2) {
71
+ if (typeof L1 === 'undefined' && typeof L2 === 'undefined') return {};
72
+ if (typeof L1 === 'undefined') return L2;
73
+ if (typeof L2 === 'undefined') return L1;
74
+ var L0 = Object.assign({}, L1);
75
+ Object.keys(L2).map(function (k) {
76
+ if (typeof L0[k] !== 'undefined') {
77
+ Object.assign(L0[k], L2[k]);
78
+ } else {
79
+ L0[k] = Object.assign({}, L2[k]);
80
+ }
81
+
82
+ return null;
83
+ });
84
+ return L0;
85
+ }
86
+ }, {
87
+ key: "isZh",
88
+ value: function isZh(language) {
89
+ /**
90
+ * ios 的中文简体固定为 zh-Hans,
91
+ * 但安卓的中文简体可能有一大堆排列组件 = =,如 zh_CN、zh_cn、zh_Hans_CH、zh_hans_cn 等等;
92
+ */
93
+
94
+ /**
95
+ * 如果匹配到位中文简体地区,
96
+ * 则将中文 zh 相关的 values 都写入到 this.strings 下,保证兜底本地 zh 相关的能取到,
97
+ * 再将当前地区 key 相关的 values 都写入到 this.strings 下,优先级最高;
98
+ */
99
+ if (typeof language === 'string' && /^zh-hans$|^zh_hans$|^zh_cn$|^zh-cn$|^zh_hans_\w+|^zh-hans-\w+/.test(language.toLowerCase())) {
100
+ return true;
101
+ }
102
+
103
+ return false;
104
+ }
105
+ }, {
106
+ key: "setLanguage",
107
+ value: function setLanguage(language) {
108
+ this.__language = language;
109
+
110
+ if (this.isZh(language)) {
111
+ this.buildLanguage('zh');
112
+ this.buildLanguage(language);
113
+ } else {
114
+ this.buildLanguage(this.__language);
115
+ }
116
+ }
117
+ }, {
118
+ key: "buildLanguage",
119
+ value: function buildLanguage(language) {
120
+ var _this2 = this;
121
+
122
+ if (this.strings[language]) {
123
+ var localizedStrings = this.strings[language];
124
+ Object.keys(localizedStrings).map(function (key) {
125
+ // eslint-disable-next-line no-prototype-builtins
126
+ if (localizedStrings.hasOwnProperty(key)) {
127
+ _this2[key] = localizedStrings[key];
128
+ }
129
+
130
+ return null;
131
+ });
132
+ }
133
+ }
134
+ }, {
135
+ key: "_getBestMatchingLanguage",
136
+ value: function _getBestMatchingLanguage(language, props) {
137
+ if (props[language]) return language;
138
+ var idx = language.lastIndexOf('-');
139
+
140
+ if (idx >= 0) {
141
+ var lang = language.substring(0, idx);
142
+ return this._getBestMatchingLanguage(lang, props);
143
+ }
144
+
145
+ var underlineIdx = language.lastIndexOf('_');
146
+
147
+ if (underlineIdx >= 0) {
148
+ var _lang = language.substring(0, underlineIdx);
149
+
150
+ return this._getBestMatchingLanguage(_lang, props);
151
+ }
152
+
153
+ return this.defaultLang;
154
+ } // Format the passed string replacing the numbered placeholders
155
+ // i.e. I'd like some {0} and {1}, or just {0}
156
+ // Use example:
157
+ // strings.formatString(strings.question, strings.bread, strings.butter)
158
+
159
+ }, {
160
+ key: "formatString",
161
+ value: function formatString(str) {
162
+ var res = str;
163
+
164
+ for (var i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
165
+ res = this._replaceAll("{".concat(i, "}"), i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1], res);
166
+ }
167
+
168
+ return res;
169
+ }
170
+ }, {
171
+ key: "formatValue",
172
+ value: function formatValue(key) {
173
+ var res = typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
174
+
175
+ for (var i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
176
+ res = this._replaceAll("{".concat(i, "}"), i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1], res);
177
+ }
178
+
179
+ return res;
180
+ }
181
+ }, {
182
+ key: "_replaceAll",
183
+ value: function _replaceAll(find, replace, str) {
184
+ // eslint-disable-next-line no-useless-escape, no-param-reassign
185
+ find = find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
186
+ if (!str) return '';
187
+ return str.replace(new RegExp(find, 'g'), replace);
188
+ }
189
+ }, {
190
+ key: "getDpLang",
191
+ value: function getDpLang(code, value) {
192
+ var key;
193
+
194
+ if (typeof value === 'undefined') {
195
+ key = "dp_".concat(code).toLowerCase();
196
+ } else if (typeof value === 'boolean') {
197
+ var valStr = value ? 'on' : 'off';
198
+ key = "dp_".concat(code, "_").concat(valStr).toLowerCase();
199
+ } else {
200
+ key = "dp_".concat(code, "_").concat(value).toLowerCase();
201
+ }
202
+
203
+ return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
204
+ }
205
+ }, {
206
+ key: "getDpName",
207
+ value: function getDpName(code, defaultName) {
208
+ var key = "dp_".concat(code).toLowerCase();
209
+ return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : defaultName;
210
+ }
211
+ }, {
212
+ key: "getDpsLang",
213
+ value: function getDpsLang(key) {
214
+ var _this3 = this;
215
+
216
+ var strs = {};
217
+
218
+ if (_typeof(key) === 'object') {
219
+ if (typeof key.strKey === 'string') {
220
+ strs = I18n.t(key.strKey) !== key.strKey ? I18n.t(key.strKey) : typeof this[key.strKey] !== 'undefined' ? this[key.strKey] : I18n.t(key.strKey);
221
+ } else {
222
+ Object.keys(key).map(function (i) {
223
+ strs[key[i]] = I18n.t(key[i]) !== key[i] ? I18n.t(key[i]) : typeof _this3[key[i]] !== 'undefined' ? _this3[key[i]] : I18n.t(key[i]);
224
+ return null;
225
+ });
226
+ }
227
+ } else {
228
+ strs = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
229
+ }
230
+
231
+ return strs;
232
+ }
233
+ }, {
234
+ key: "getLang",
235
+ value: function getLang(key, defaultString) {
236
+ return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : typeof defaultString !== 'undefined' ? defaultString : I18n.t(key);
237
+ }
238
+ /**
239
+ * 获取picker标题
240
+ * @param {*} dpCode
241
+ */
242
+
243
+ }, {
244
+ key: "getRangeStrings",
245
+ value: function getRangeStrings(dpCode, schema) {
246
+ var _this4 = this;
247
+
248
+ var result = {};
249
+ if (typeof schema === 'undefined') return result;
250
+ var lists = schema.range;
251
+ lists.map(function (v) {
252
+ var key = "dp_".concat(dpCode, "_").concat(v).toLowerCase();
253
+ result[v] = I18n.t(key) !== key ? I18n.t(key) : typeof _this4[key] !== 'undefined' ? _this4[key] : I18n.t(key);
254
+ return null;
255
+ });
256
+ return result;
257
+ }
258
+ /**
259
+ * 开关倒计时转换为文案 time => 设备将在xxx后 关闭/开启
260
+ * 精确到分钟
261
+ * @param {*} t 倒计时剩余(秒)
262
+ * @param {*} power 设备当前的开关状态 (如果当前设备为开启状态, 则倒计时显示为关闭)
263
+ */
264
+
265
+ }, {
266
+ key: "parseCountdown",
267
+ value: function parseCountdown(t, power) {
268
+ var h = parseFloat("".concat(t / 3600));
269
+ var m = parseFloat("".concat(t / 60 - h * 60));
270
+ var tHour = I18n.t('t_hour') !== 't_hour' ? I18n.t('t_hour') : typeof this.t_hour !== 'undefined' ? this.t_hour : I18n.t('t_hour');
271
+ var tMinute = I18n.t('t_minute') !== 't_minute' ? I18n.t('t_minute') : typeof this.t_minute !== 'undefined' ? this.t_minute : I18n.t('t_minute');
272
+ var time = h >= 1.0 ? "".concat(Math.round(h)).concat(tHour) : "".concat(Math.round(m)).concat(tMinute);
273
+ var key = "countdown_".concat(power ? 'on' : 'off');
274
+ var str = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
275
+ return this.formatString(str, time);
276
+ }
277
+ }, {
278
+ key: "getFaultStrings",
279
+ value: function getFaultStrings(schema, faultCode, faultValue) {
280
+ var onlyPrior = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
281
+ if (!faultValue) return '';
282
+ var label = schema.label;
283
+ var labels = [];
284
+
285
+ for (var i = 0; i < label.length; i++) {
286
+ var value = label[i];
287
+ var isExist = getBitValue(faultValue, i);
288
+
289
+ if (isExist) {
290
+ labels.push(this.getDpLang(faultCode, value));
291
+ if (onlyPrior) break;
292
+ }
293
+ }
294
+
295
+ return onlyPrior ? labels[0] : labels.join(', ');
296
+ }
297
+ }]);
298
+
299
+ return I18N;
300
+ }();
301
+
302
+ export { I18N as default };
@@ -1,3 +1,4 @@
1
1
  export { parseDevice, getDevInfo, initDevInfo, initPanelEnvironment } from './devInfo';
2
2
  export * from './normalizeNetwork';
3
3
  export * from './publishDps';
4
+ export { default as I18N } from './i18n';
@@ -1,3 +1,4 @@
1
1
  export { parseDevice, getDevInfo, initDevInfo, initPanelEnvironment } from './devInfo';
2
2
  export * from './normalizeNetwork';
3
- export * from './publishDps';
3
+ export * from './publishDps';
4
+ export { default as I18N } from './i18n';
@@ -1,4 +1,4 @@
1
- import { getNetworkType, onNetworkStatusChange } from '../';
1
+ import { getNetworkType, onNetworkStatusChange } from '../..';
2
2
  import { GetTTTSuccessData, GetTTTEventListenerParams, NetworkState } from './types';
3
3
  declare type GetNetworkResult = GetTTTSuccessData<typeof getNetworkType>;
4
4
  declare type NetworkStatusChangeParam = GetTTTEventListenerParams<typeof onNetworkStatusChange>;
@@ -1,4 +1,4 @@
1
- import { publishDpsBase } from '../';
1
+ import { publishDpsBase } from '../..';
2
2
  import { GetTTTAllParams, DpState } from './types';
3
3
  declare type PublishDpsOptions = Omit<GetTTTAllParams<typeof publishDpsBase>, 'deviceId' | 'dps'>;
4
4
  /**
@@ -3,7 +3,7 @@ import "core-js/modules/es.object.to-string.js";
3
3
  import "core-js/modules/web.dom-collections.for-each.js";
4
4
  import "core-js/modules/es.object.keys.js";
5
5
  import "core-js/modules/es.promise.js";
6
- import { publishDpsBase } from '../';
6
+ import { publishDpsBase } from '../..';
7
7
  import { getDevInfo } from './devInfo';
8
8
  var DEFAULT_OPTIONS = {
9
9
  mode: 2,
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @example
3
+ * // 17 = 10001(2)
4
+ * getBitValue(17, 0)
5
+ * // 1
6
+ * @example
7
+ * getBitValue(17, 1)
8
+ * // 0
9
+ * @example
10
+ * getBitValue(17, 4)
11
+ * // 1
12
+ * @param {Number} idx, idx is reverse, and it begins 0
13
+ * @returns {Number} a num
14
+ */
15
+ export declare const getBitValue: (num: number, idx: number) => number;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @example
3
+ * // 17 = 10001(2)
4
+ * getBitValue(17, 0)
5
+ * // 1
6
+ * @example
7
+ * getBitValue(17, 1)
8
+ * // 0
9
+ * @example
10
+ * getBitValue(17, 4)
11
+ * // 1
12
+ * @param {Number} idx, idx is reverse, and it begins 0
13
+ * @returns {Number} a num
14
+ */
15
+ export var getBitValue = function (num, idx) {
16
+ return (num & 1 << idx) >> idx;
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/api",
3
- "version": "1.3.1-beta.0",
3
+ "version": "1.3.1-beta.1",
4
4
  "description": "Ray universal api",
5
5
  "keywords": [
6
6
  "ray"
@@ -26,13 +26,13 @@
26
26
  "build:kit:api": "node scripts/api-creator.mjs"
27
27
  },
28
28
  "dependencies": {
29
- "@ray-js/framework": "^1.3.1-beta.0",
30
- "@ray-js/router": "^1.3.1-beta.0",
29
+ "@ray-js/framework": "^1.3.1-beta.1",
30
+ "@ray-js/router": "^1.3.1-beta.1",
31
31
  "@ray-js/wechat": "^0.0.16",
32
32
  "base64-browser": "^1.0.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@ray-js/cli": "^1.3.1-beta.0",
35
+ "@ray-js/cli": "^1.3.1-beta.1",
36
36
  "art-template": "^4.13.2",
37
37
  "fs-extra": "^10.1.0",
38
38
  "miniprogram-api-typings": "^3.4.3",
@@ -44,6 +44,6 @@
44
44
  "email": "tuyafe@tuya.com"
45
45
  }
46
46
  ],
47
- "gitHead": "5449d8320c74a36dc564a2c0c1fbe342b6ac6934",
47
+ "gitHead": "81bd8c71794b8bc83d884f2c86856fece31fad7c",
48
48
  "repository": {}
49
49
  }