mazey 3.4.1 → 3.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mazey",
3
- "version": "3.4.1",
3
+ "version": "3.5.1",
4
4
  "description": "Mazey's library for front-end.",
5
5
  "main": "lib/index.cjs.js",
6
6
  "module": "lib/index.esm.js",
@@ -72,8 +72,8 @@
72
72
  "@typescript-eslint/eslint-plugin": "^4.22.0",
73
73
  "@typescript-eslint/parser": "^4.22.0",
74
74
  "clean-webpack-plugin": "^1.0.1",
75
- "cross-env": "^7.0.3",
76
75
  "core-js": "^3.6.5",
76
+ "cross-env": "^7.0.3",
77
77
  "date-fns": "^2.29.3",
78
78
  "eslint": "^6.8.0",
79
79
  "eslint-config-standard": "^14.1.0",
@@ -95,10 +95,11 @@
95
95
  "rollup-plugin-commonjs": "^10.1.0",
96
96
  "rollup-plugin-copy": "^3.4.0",
97
97
  "rollup-plugin-terser": "^7.0.2",
98
- "rollup-plugin-typescript2": "^0.27.2",
98
+ "rollup-plugin-typescript2": "^0.30.0",
99
99
  "ts-loader": "^8.0.2",
100
+ "tslib": "^2.4.1",
100
101
  "typedoc": "^0.18.0",
101
- "typescript": "^3.9.7",
102
+ "typescript": "^4.4.4",
102
103
  "webpack": "^4.30.0",
103
104
  "webpack-cli": "^3.3.2",
104
105
  "webpack-dev-server": "^3.10.3"
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
- /* mazey */
1
+ /**
2
+ * @author: Mazey Chu
3
+ */
2
4
 
3
5
  /**
4
6
  * EN: Computes the longest common substring of two strings.
@@ -2065,6 +2067,64 @@ export function isNonEmptyArray(arr: any[]): boolean {
2065
2067
  return ret;
2066
2068
  }
2067
2069
 
2070
+ /**
2071
+ * Determine the validity of the data.
2072
+ *
2073
+ * Usage:
2074
+ *
2075
+ * ```
2076
+ * const validData = {
2077
+ * a: {
2078
+ * b: {
2079
+ * c: 413
2080
+ * }
2081
+ * }
2082
+ * };
2083
+ *
2084
+ * const isValidDataResA = isValidData(validData, ['a', 'b', 'c'], 2333);
2085
+ * const isValidDataResB = isValidData(validData, ['a', 'b', 'c'], 413);
2086
+ * const isValidDataResC = isValidData(validData, ['d', 'd'], 413);
2087
+ *
2088
+ * console.log('isValidDataResA:', isValidDataResA);
2089
+ * console.log('isValidDataResB:', isValidDataResB);
2090
+ * console.log('isValidDataResC:', isValidDataResC);
2091
+ * ```
2092
+ *
2093
+ * Output:
2094
+ *
2095
+ * ```
2096
+ * isValidDataResA: false
2097
+ * isValidDataResB: true
2098
+ * isValidDataResC: false
2099
+ * ```
2100
+ *
2101
+ * @param {any} data Original Data
2102
+ * @param {string[]} attributes Data Attributes
2103
+ * @param {any} validValue Given Value for verifying.
2104
+ * @returns {boolean} Return TRUE if the data is valid.
2105
+ */
2106
+ export function isValidData(
2107
+ data: any,
2108
+ attributes: string[],
2109
+ validValue: any
2110
+ ): boolean {
2111
+ let ret = false;
2112
+ const foundRet = attributes.reduce((foundValue, curr) => {
2113
+ if (foundValue[curr]) {
2114
+ foundValue = foundValue[curr];
2115
+ } else {
2116
+ return Object.create(null);
2117
+ }
2118
+ // console.log('foundValue', foundValue);
2119
+ return foundValue;
2120
+ }, data);
2121
+ // console.log('foundRet', foundRet);
2122
+ if (foundRet === validValue) {
2123
+ ret = true;
2124
+ }
2125
+ return ret;
2126
+ }
2127
+
2068
2128
  /**
2069
2129
  * 语义化文件大小, 把字节转换成正常文件大小.
2070
2130
  */
@@ -2123,3 +2183,66 @@ export function genHashCode(str: string): number {
2123
2183
  }
2124
2184
  return hash;
2125
2185
  }
2186
+
2187
+ /**
2188
+ * Return the formatted date string in the given format.
2189
+ *
2190
+ * Usage:
2191
+ *
2192
+ * ```
2193
+ * console.log('Default formatDate value:', formatDate());
2194
+ * console.log('String formatDate value:', formatDate('Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)', 'yyyy-MM-dd hh:mm:ss'));
2195
+ * console.log('Number formatDate value:', formatDate(1641881235000, 'yyyy-MM-dd hh:mm:ss'));
2196
+ * console.log('Date formatDate value:', formatDate(new Date(2014, 1, 11), 'MM/dd/yyyy'));
2197
+ * ```
2198
+ *
2199
+ * Output:
2200
+ *
2201
+ * ```
2202
+ * Default formatDate value: 2023-01-11
2203
+ * String formatDate value: 2022-01-11 14:12:26
2204
+ * Number formatDate value: 2022-01-11 14:07:15
2205
+ * Date formatDate value: 02/11/2014
2206
+ * ```
2207
+ *
2208
+ * @param {Date|number|string} dateIns Original Date
2209
+ * @param {string} format Format String
2210
+ * @returns {string} Return the formatted date string.
2211
+ */
2212
+ export function formatDate(
2213
+ dateIns?: Date | number | string,
2214
+ format = 'yyyy-MM-dd'
2215
+ ): string {
2216
+ if (!dateIns) {
2217
+ dateIns = new Date();
2218
+ }
2219
+ const tempDate = new Date(dateIns);
2220
+ const o: {
2221
+ [key: string]: string | number;
2222
+ } = {
2223
+ yyyy: tempDate.getFullYear(),
2224
+ MM: tempDate.getMonth() + 1,
2225
+ dd: tempDate.getDate(),
2226
+ hh:
2227
+ tempDate.getHours() < 10
2228
+ ? '0' + tempDate.getHours()
2229
+ : tempDate.getHours(),
2230
+ mm:
2231
+ tempDate.getMinutes() < 10
2232
+ ? '0' + tempDate.getMinutes()
2233
+ : tempDate.getMinutes(),
2234
+ ss:
2235
+ tempDate.getSeconds() < 10
2236
+ ? '0' + tempDate.getSeconds()
2237
+ : tempDate.getSeconds()
2238
+ };
2239
+ let tempFormat = format || 'yyyy-MM-dd';
2240
+ Object.keys(o).forEach(key => {
2241
+ let value = o[key];
2242
+ if (key === 'MM' && Number(value) <= 9) {
2243
+ value = `0${value}`;
2244
+ }
2245
+ tempFormat = tempFormat.replace(key, String(value));
2246
+ });
2247
+ return tempFormat;
2248
+ }
package/src/t.html CHANGED
@@ -11,8 +11,8 @@
11
11
 
12
12
  <body>
13
13
  <script>
14
- location.href="./modules/_index_.html";
14
+ location.href="./modules/_src_index_.html";
15
15
  </script>
16
16
  </body>
17
17
 
18
- </html>
18
+ </html>