tools-min-ns 1.11.0 → 1.12.0

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/README.md CHANGED
@@ -5,6 +5,14 @@ cnpm i tools-min-ns --save
5
5
  ```
6
6
 
7
7
  # updates
8
+ ## v1.12.0
9
+ > CheckUtil
10
+ 新增方法isValidFileName
11
+
12
+ ## v1.11.1
13
+ > BrowserUtil
14
+ 修复window暴露问题。
15
+
8
16
  ## v1.10.3
9
17
  > ArrayUtil
10
18
  新增universalSort
@@ -26,7 +26,7 @@ declare namespace BrowserUtil {
26
26
  * 判断是否微信内置浏览器
27
27
  * @returns boolean
28
28
  */
29
- const isWeixinBrowser: () => any;
29
+ const isWeixinBrowser: () => boolean;
30
30
  /**
31
31
  * 判断是否微信小程序WebView
32
32
  * @returns boolean
@@ -36,17 +36,17 @@ declare namespace BrowserUtil {
36
36
  * 判断是否是支付宝浏览器
37
37
  * @returns boolean
38
38
  */
39
- const isAlipayBrowser: () => any;
39
+ const isAlipayBrowser: () => boolean;
40
40
  /**
41
41
  * 判断是否是支付宝小程序webview
42
42
  * @returns boolean
43
43
  */
44
- const isAlipayMiniWebView: () => any;
44
+ const isAlipayMiniWebView: () => boolean;
45
45
  /**
46
46
  * 判断是否是浙里办
47
47
  * @returns boolean
48
48
  */
49
- const isMgopBrowser: () => any;
49
+ const isMgopBrowser: () => boolean;
50
50
  /** 全屏 */
51
51
  function fullScreen(root: string | HTMLElement, callback?: (isFull: boolean) => void): void;
52
52
  /** 是否全屏 */
@@ -116,10 +116,10 @@ var __generator = this && this.__generator || function (thisArg, body) {
116
116
  import BaseUtil from '../base/BaseUtil';
117
117
  import env from '../env/env';
118
118
  import fingerprint from './fingerprint';
119
- var userAgent = env.getGlobal().navigator.userAgent;
120
- var isInUserAgent = function isInUserAgent(v) {
121
- return userAgent === null || userAgent === void 0 ? void 0 : userAgent.toLowerCase().includes(v);
122
- };
119
+ function isInUserAgent(v) {
120
+ var _a, _b;
121
+ return !!((_b = (_a = env.getGlobal()) === null || _a === void 0 ? void 0 : _a.navigator.userAgent) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(v));
122
+ }
123
123
  var BrowserUtil;
124
124
  (function (BrowserUtil) {
125
125
  var _this = this;
@@ -168,6 +168,8 @@ var BrowserUtil;
168
168
  * @returns Opera | IE | Edge | Firefox | Safari | Chrome | OverIE10 | ""
169
169
  */
170
170
  BrowserUtil.browserGetType = function () {
171
+ var _a;
172
+ var userAgent = ((_a = env.getGlobal()) === null || _a === void 0 ? void 0 : _a.navigator.userAgent) || '';
171
173
  if (userAgent.indexOf('Opera') > -1 || userAgent.indexOf('OPR') > -1) {
172
174
  return 'Opera';
173
175
  } else if (userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1) {
@@ -190,6 +192,8 @@ var BrowserUtil;
190
192
  * @returns boolean
191
193
  */
192
194
  BrowserUtil.isMobileBrowser = function () {
195
+ var _a;
196
+ var userAgent = ((_a = env.getGlobal()) === null || _a === void 0 ? void 0 : _a.navigator.userAgent) || '';
193
197
  return !!userAgent.toLowerCase().match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|SymbianOS|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
194
198
  };
195
199
  /**
@@ -1,6 +1,15 @@
1
1
  import { STR_TYPE } from '../common';
2
2
  export type StrType = keyof typeof STR_TYPE;
3
3
  declare namespace CheckUtil {
4
+ /**
5
+ * 检查文件/夹名是否合法
6
+ * @param str
7
+ * @example
8
+ console.log(isValidFileName("valid-name.txt")); // true
9
+ console.log(isValidFileName("invalid/name.txt")); // false
10
+ console.log(isValidFileName("invalid:name.txt")); // false
11
+ */
12
+ const isValidFileName: (str: string) => boolean;
4
13
  /**
5
14
  * 检查手机号是否合法
6
15
  * @param {String} phone 手机号
@@ -154,6 +154,29 @@ import BaseUtil from '../base/BaseUtil';
154
154
  import { STR_TYPE } from '../common';
155
155
  var CheckUtil;
156
156
  (function (CheckUtil) {
157
+ /**
158
+ * 检查文件/夹名是否合法
159
+ * @param str
160
+ * @example
161
+ console.log(isValidFileName("valid-name.txt")); // true
162
+ console.log(isValidFileName("invalid/name.txt")); // false
163
+ console.log(isValidFileName("invalid:name.txt")); // false
164
+ */
165
+ CheckUtil.isValidFileName = function (str) {
166
+ if (!str) return false;
167
+ var illegalChars = /[\/\:\*\?"<>\|]/g; // Windows非法字符
168
+ var illegalCharsUnix = /\//g; // Unix/Linux非法字符(斜杠)
169
+ var nullChar = /\0/g; // null字符
170
+ // 检查Windows非法字符
171
+ if (illegalChars.test(str)) {
172
+ return false;
173
+ }
174
+ // 检查Unix/Linux非法字符(斜杠)和null字符
175
+ if (illegalCharsUnix.test(str) || nullChar.test(str)) {
176
+ return false;
177
+ }
178
+ return true;
179
+ };
157
180
  /**
158
181
  * 检查手机号是否合法
159
182
  * @param {String} phone 手机号
@@ -26,7 +26,7 @@ declare namespace BrowserUtil {
26
26
  * 判断是否微信内置浏览器
27
27
  * @returns boolean
28
28
  */
29
- const isWeixinBrowser: () => any;
29
+ const isWeixinBrowser: () => boolean;
30
30
  /**
31
31
  * 判断是否微信小程序WebView
32
32
  * @returns boolean
@@ -36,17 +36,17 @@ declare namespace BrowserUtil {
36
36
  * 判断是否是支付宝浏览器
37
37
  * @returns boolean
38
38
  */
39
- const isAlipayBrowser: () => any;
39
+ const isAlipayBrowser: () => boolean;
40
40
  /**
41
41
  * 判断是否是支付宝小程序webview
42
42
  * @returns boolean
43
43
  */
44
- const isAlipayMiniWebView: () => any;
44
+ const isAlipayMiniWebView: () => boolean;
45
45
  /**
46
46
  * 判断是否是浙里办
47
47
  * @returns boolean
48
48
  */
49
- const isMgopBrowser: () => any;
49
+ const isMgopBrowser: () => boolean;
50
50
  /** 全屏 */
51
51
  function fullScreen(root: string | HTMLElement, callback?: (isFull: boolean) => void): void;
52
52
  /** 是否全屏 */
@@ -126,10 +126,10 @@ Object.defineProperty(exports, "__esModule", {
126
126
  var BaseUtil_1 = __importDefault(require("../base/BaseUtil"));
127
127
  var env_1 = __importDefault(require("../env/env"));
128
128
  var fingerprint_1 = __importDefault(require("./fingerprint"));
129
- var userAgent = env_1.default.getGlobal().navigator.userAgent;
130
- var isInUserAgent = function isInUserAgent(v) {
131
- return userAgent === null || userAgent === void 0 ? void 0 : userAgent.toLowerCase().includes(v);
132
- };
129
+ function isInUserAgent(v) {
130
+ var _a, _b;
131
+ return !!((_b = (_a = env_1.default.getGlobal()) === null || _a === void 0 ? void 0 : _a.navigator.userAgent) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(v));
132
+ }
133
133
  var BrowserUtil;
134
134
  (function (BrowserUtil) {
135
135
  var _this = this;
@@ -178,6 +178,8 @@ var BrowserUtil;
178
178
  * @returns Opera | IE | Edge | Firefox | Safari | Chrome | OverIE10 | ""
179
179
  */
180
180
  BrowserUtil.browserGetType = function () {
181
+ var _a;
182
+ var userAgent = ((_a = env_1.default.getGlobal()) === null || _a === void 0 ? void 0 : _a.navigator.userAgent) || '';
181
183
  if (userAgent.indexOf('Opera') > -1 || userAgent.indexOf('OPR') > -1) {
182
184
  return 'Opera';
183
185
  } else if (userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1) {
@@ -200,6 +202,8 @@ var BrowserUtil;
200
202
  * @returns boolean
201
203
  */
202
204
  BrowserUtil.isMobileBrowser = function () {
205
+ var _a;
206
+ var userAgent = ((_a = env_1.default.getGlobal()) === null || _a === void 0 ? void 0 : _a.navigator.userAgent) || '';
203
207
  return !!userAgent.toLowerCase().match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|SymbianOS|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
204
208
  };
205
209
  /**
@@ -1,6 +1,15 @@
1
1
  import { STR_TYPE } from '../common';
2
2
  export type StrType = keyof typeof STR_TYPE;
3
3
  declare namespace CheckUtil {
4
+ /**
5
+ * 检查文件/夹名是否合法
6
+ * @param str
7
+ * @example
8
+ console.log(isValidFileName("valid-name.txt")); // true
9
+ console.log(isValidFileName("invalid/name.txt")); // false
10
+ console.log(isValidFileName("invalid:name.txt")); // false
11
+ */
12
+ const isValidFileName: (str: string) => boolean;
4
13
  /**
5
14
  * 检查手机号是否合法
6
15
  * @param {String} phone 手机号
@@ -164,6 +164,29 @@ var BaseUtil_1 = __importDefault(require("../base/BaseUtil"));
164
164
  var common_1 = require("../common");
165
165
  var CheckUtil;
166
166
  (function (CheckUtil) {
167
+ /**
168
+ * 检查文件/夹名是否合法
169
+ * @param str
170
+ * @example
171
+ console.log(isValidFileName("valid-name.txt")); // true
172
+ console.log(isValidFileName("invalid/name.txt")); // false
173
+ console.log(isValidFileName("invalid:name.txt")); // false
174
+ */
175
+ CheckUtil.isValidFileName = function (str) {
176
+ if (!str) return false;
177
+ var illegalChars = /[\/\:\*\?"<>\|]/g; // Windows非法字符
178
+ var illegalCharsUnix = /\//g; // Unix/Linux非法字符(斜杠)
179
+ var nullChar = /\0/g; // null字符
180
+ // 检查Windows非法字符
181
+ if (illegalChars.test(str)) {
182
+ return false;
183
+ }
184
+ // 检查Unix/Linux非法字符(斜杠)和null字符
185
+ if (illegalCharsUnix.test(str) || nullChar.test(str)) {
186
+ return false;
187
+ }
188
+ return true;
189
+ };
167
190
  /**
168
191
  * 检查手机号是否合法
169
192
  * @param {String} phone 手机号
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tools-min-ns",
3
3
  "description": "工具包适用于前端以及node",
4
- "version": "1.11.0",
4
+ "version": "1.12.0",
5
5
  "main": "lib/index.js",
6
6
  "license": "MIT",
7
7
  "author": "nanshen",