Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aircall/logger

Package Overview
Dependencies
Maintainers
5
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aircall/logger - npm Package Compare versions

Comparing version 2.7.1 to 2.8.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [2.8.0](https://gitlab.com/aircall/shared/front-end-modules/compare/@aircall/logger@2.7.1...@aircall/logger@2.8.0) (2022-09-01)
### Features
* **logger:** add max depth to mapDeep helper [PH-7468] ([4256c30](https://gitlab.com/aircall/shared/front-end-modules/commit/4256c30769f13a756c31e03ba277cbffb209faa0))
## [2.7.1](https://gitlab.com/aircall/shared/front-end-modules/compare/@aircall/logger@2.7.0...@aircall/logger@2.7.1) (2022-08-26)

@@ -8,0 +19,0 @@

2

dist/utils.d.ts

@@ -15,3 +15,3 @@ declare type ObjectRecord = Record<string, any>;

*/
declare type DeepMap = (object: ObjectRecord, iteratee: Iteratee) => any;
declare type DeepMap = (object: ObjectRecord, iteratee: Iteratee, maxDepth?: number) => any;
export declare const deepMap: DeepMap;

@@ -18,0 +18,0 @@ /**

@@ -28,9 +28,19 @@ "use strict";

exports.map = map;
const deepMap = (object, iteratee) => {
return (0, exports.map)(object, (value, key) => {
if ((0, exports.isArray)(value) || (0, exports.isObject)(value)) {
return (0, exports.deepMap)(value, iteratee);
const deepMap = (object, iteratee, maxDepth = 10) => {
let count = 0;
const closure = (object, iteratee) => {
if (count > maxDepth) {
count = 0;
return null;
}
return iteratee(value, key, object);
});
return (0, exports.map)(object, (value, key) => {
if ((0, exports.isArray)(value) || (0, exports.isObject)(value)) {
count++;
return closure(value, iteratee);
}
count = 0;
return iteratee(value, key, object);
});
};
return closure(object, iteratee);
};

@@ -37,0 +47,0 @@ exports.deepMap = deepMap;

{
"name": "@aircall/logger",
"version": "2.7.1",
"version": "2.8.0",
"main": "dist/index.js",

@@ -14,3 +14,3 @@ "types": "dist/index.d.ts",

},
"gitHead": "00a21b92c7a79ae4b941fab731ed5659fe1ace3c",
"gitHead": "15ff4196f1a1653dfe35b3dedfd4c5710eadbd05",
"dependencies": {

@@ -17,0 +17,0 @@ "@datadog/browser-logs": "4.17.1",

@@ -146,2 +146,160 @@ import { mapObject, map, deepMap, containsAValue } from './utils';

});
it('should stop when maxDepth is exceeded', () => {
const input = {
a: 10,
b: [1, 2, 3],
c: {
level01: {
level02: {
level03: {
level04: {
level05: {
level06: {
level07: {
level08: {
level09: { level10: { level11: 'hello' } }
}
}
}
}
}
}
}
}
}
};
const iteratee = (value: any) => {
if (typeof value === 'number' || typeof value === 'string') {
return value + ' test';
}
return value;
};
const result = deepMap(input, iteratee);
expect(result).toEqual({
a: '10 test',
b: ['1 test', '2 test', '3 test'],
c: {
level01: {
level02: {
level03: {
level04: {
level05: {
level06: {
level07: { level08: { level09: { level10: null } } }
}
}
}
}
}
}
}
});
});
it('should not stop whe maxDepth is not exceeded', () => {
const input = {
a: 10,
b: [1, 2, 3],
c: {
level01: {
level02: {
level03: {
level04: {
level05: {
level06: {
level07: {
level08: {
level09: {
level10: { level11: 'hello' }
}
}
}
}
}
}
}
}
}
}
};
const iteratee = (value: any) => {
if (typeof value === 'number' || typeof value === 'string') {
return value + ' test';
}
return value;
};
const result = deepMap(input, iteratee, 11);
expect(result).toEqual({
a: '10 test',
b: ['1 test', '2 test', '3 test'],
c: {
level01: {
level02: {
level03: {
level04: {
level05: {
level06: {
level07: {
level08: {
level09: {
level10: { level11: 'hello test' }
}
}
}
}
}
}
}
}
}
}
});
});
it('should not compute a cumulative depth', () => {
const iteratee = (value: any) => {
if (typeof value === 'number' || typeof value === 'string') {
return value + ' test';
}
return value;
};
const input = {
objA: {
level01: {
level02: 'hello'
}
},
objB: {
level01: {
level02: 'hello'
}
}
};
const result = deepMap(input, iteratee, 2);
expect(result).toEqual({
objA: {
level01: {
level02: 'hello test'
}
},
objB: {
level01: {
level02: 'hello test'
}
}
});
});
});

@@ -148,0 +306,0 @@

@@ -37,11 +37,24 @@ type ObjectRecord = Record<string, any>;

*/
type DeepMap = (object: ObjectRecord, iteratee: Iteratee) => any;
export const deepMap: DeepMap = (object, iteratee) => {
return map(object, (value, key) => {
if (isArray(value) || isObject(value)) {
return deepMap(value, iteratee);
type DeepMap = (object: ObjectRecord, iteratee: Iteratee, maxDepth?: number) => any;
export const deepMap: DeepMap = (object, iteratee, maxDepth = 10) => {
let count = 0;
const closure: DeepMap = (object, iteratee) => {
if (count > maxDepth) {
count = 0;
return null;
}
return iteratee(value, key, object);
});
return map(object, (value, key) => {
if (isArray(value) || isObject(value)) {
count++;
return closure(value, iteratee);
}
count = 0;
return iteratee(value, key, object);
});
};
return closure(object, iteratee);
};

@@ -48,0 +61,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc