MCPcopy
hub / github.com/didi/mpx / forEach

Function forEach

packages/utils/src/base.js:50–70  ·  view source on GitHub ↗
(obj, fn)

Source from the content-addressed store, hash-verified

48}
49
50function forEach (obj, fn) {
51 if (obj === null || typeof obj === 'undefined') {
52 return
53 }
54
55 if (typeof obj !== 'object') {
56 obj = [obj]
57 }
58
59 if (isArray(obj)) {
60 for (let i = 0, l = obj.length; i < l; i++) {
61 fn(obj[i], i, obj)
62 }
63 } else {
64 for (const key in obj) {
65 if (Object.prototype.hasOwnProperty.call(obj, key)) {
66 fn(obj[key], key, obj)
67 }
68 }
69 }
70}
71
72function isNumberStr (str) {
73 return /^\d+$/.test(str)

Callers 2

deepMergeFunction · 0.90
serializeFunction · 0.90

Calls 2

isArrayFunction · 0.85
fnFunction · 0.85

Tested by

no test coverage detected