@daysnap/utils 0.0.16 → 0.0.18

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/each.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 支持遍历数组和对象
3
+ */
4
+ export declare function each<T>(data: T[], callback: (item: T, index: number) => void): void;
5
+ export declare function each<T>(data: Record<string, T>, callback: (item: T, key: string) => void): void;
package/es/each.js ADDED
@@ -0,0 +1,12 @@
1
+ export function each(data, callback) {
2
+ if (Array.isArray(data)) {
3
+ // eslint-disable-next-line no-plusplus
4
+ for (var index = 0, length = data.length; index < length; index++) {
5
+ callback.call(data[index], data[index], index);
6
+ }
7
+ } else {
8
+ Object.keys(data).forEach(function (key) {
9
+ callback.call(data[key], data[key], key);
10
+ });
11
+ }
12
+ }
package/lib/each.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 支持遍历数组和对象
3
+ */
4
+ export declare function each<T>(data: T[], callback: (item: T, index: number) => void): void;
5
+ export declare function each<T>(data: Record<string, T>, callback: (item: T, key: string) => void): void;
package/lib/each.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.each = each;
7
+
8
+ function each(data, callback) {
9
+ if (Array.isArray(data)) {
10
+ // eslint-disable-next-line no-plusplus
11
+ for (var index = 0, length = data.length; index < length; index++) {
12
+ callback.call(data[index], data[index], index);
13
+ }
14
+ } else {
15
+ Object.keys(data).forEach(function (key) {
16
+ callback.call(data[key], data[key], key);
17
+ });
18
+ }
19
+ }
package/package.json CHANGED
@@ -1,20 +1,10 @@
1
1
  {
2
2
  "name": "@daysnap/utils",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "通用的工具库",
5
- "type": "module",
6
5
  "main": "lib/index.js",
7
6
  "module": "es/index.js",
8
7
  "typings": "lib/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./lib/index.d.ts",
12
- "require": "./lib/index.js",
13
- "import": "./es/index.js",
14
- "default": "./lib/index.js"
15
- },
16
- "./package.json": "./package.json"
17
- },
18
8
  "scripts": {
19
9
  "ts-node": "npx ts-node --project ./tsconfig.json ./src/filename.ts",
20
10
  "gen": "plop --plopfile ./scripts/gen.js --force",