electron-log
Advanced tools
Comparing version 5.1.0-beta.1 to 5.1.0-beta.2
{ | ||
"name": "electron-log", | ||
"version": "5.1.0-beta.1", | ||
"version": "5.1.0-beta.2", | ||
"description": "Just a simple logging module for your Electron application", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -21,15 +21,20 @@ 'use strict'; | ||
it('should serialize object', () => { | ||
expect(serialize(null, { a: 1 })).toEqual({ a: 1 }); | ||
expect(serialize('', { a: 1 })).toEqual({ a: 1 }); | ||
}); | ||
it('should serialize errors', () => { | ||
expect(serialize(null, new Error('test'))).toMatch('Error: test\n'); | ||
expect(serialize('', new Error('test'))).toMatch('Error: test\n'); | ||
}); | ||
it('should serialize functions', () => { | ||
expect(serialize(null, () => 1)).toEqual('[function] () => 1'); | ||
expect(serialize('', () => 1)).toEqual('[function] () => 1'); | ||
}); | ||
it('should serialize Date', () => { | ||
expect(serialize('', new Date('2000-01-01T00:00:00.000Z'))) | ||
.toEqual('2000-01-01T00:00:00.000Z'); | ||
}); | ||
it('should serialize set', () => { | ||
expect(serialize(null, new Set([1]))).toEqual([1]); | ||
expect(serialize('', new Set([1]))).toEqual([1]); | ||
}); | ||
@@ -39,3 +44,3 @@ | ||
if (Object.fromEntries) { | ||
expect(serialize(null, new Map([['a', 1]]))).toEqual({ a: 1 }); | ||
expect(serialize('', new Map([['a', 1]]))).toEqual({ a: 1 }); | ||
} | ||
@@ -42,0 +47,0 @@ }); |
@@ -124,2 +124,6 @@ 'use strict'; | ||
if (value instanceof Date) { | ||
return value.toISOString(); | ||
} | ||
if (serializeMapAndSet && value instanceof Map && Object.fromEntries) { | ||
@@ -126,0 +130,0 @@ return Object.fromEntries(value); |
@@ -12,10 +12,18 @@ 'use strict'; | ||
serializeFn(data, { depth = 5, seen = new WeakSet() } = {}) { | ||
if (seen.has(data)) { | ||
return '[Circular]'; | ||
} | ||
if (depth < 1) { | ||
if (isPrimitive(data)) { | ||
return data; | ||
} | ||
if (Array.isArray(data)) { | ||
return '[Array]'; | ||
} | ||
return `[${typeof data}]`; | ||
} | ||
if (seen.has(data)) { | ||
return data; | ||
} | ||
if (['function', 'symbol'].includes(typeof data)) { | ||
@@ -25,4 +33,3 @@ return data.toString(); | ||
// Primitive types (including null and undefined) | ||
if (Object(data) !== data) { | ||
if (isPrimitive(data)) { | ||
return data; | ||
@@ -44,2 +51,6 @@ } | ||
if (data instanceof Date) { | ||
return data.toISOString(); | ||
} | ||
if (data instanceof Error) { | ||
@@ -105,1 +116,10 @@ return data.stack; | ||
} | ||
/** | ||
* Is type primitive, including null and undefined | ||
* @param {any} value | ||
* @returns {boolean} | ||
*/ | ||
function isPrimitive(value) { | ||
return Object(value) !== value; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
126888
3986
3