Comparing version 6.3.0 to 6.4.0
@@ -89,2 +89,3 @@ /// <reference types="node" /> | ||
export declare class Format { | ||
#private; | ||
options: FormatOptions; | ||
@@ -189,3 +190,3 @@ parent: Format | null; | ||
printErrorBody(): void; | ||
getPojoKeys(obj?: any): string[]; | ||
getPojoKeys(obj?: any): PropertyKey[]; | ||
printPojo(): void; | ||
@@ -196,3 +197,3 @@ pojoIsEmpty(obj?: any): boolean; | ||
printPojoBody(): void; | ||
getPojoEntries(obj: any): [string, any][]; | ||
getPojoEntries(obj: any): [PropertyKey, any][]; | ||
printPojoTail(): void; | ||
@@ -199,0 +200,0 @@ printPojoEntry(key: any, val: any): void; |
@@ -304,4 +304,18 @@ "use strict"; | ||
} | ||
#printSymbol(sym) { | ||
const keyFor = Symbol.keyFor(sym); | ||
const s = String(sym); | ||
if (s.startsWith('Symbol(Symbol.')) { | ||
// check to see if it's a key on the Symbol global. | ||
// return Symbol.iterator, not Symbol(Symbol.iterator) | ||
const symKey = s.substring('Symbol(Symbol.'.length, s.length - 1); | ||
if (symKey && | ||
Symbol[symKey] === sym) { | ||
return `Symbol.${symKey}`; | ||
} | ||
} | ||
return keyFor ? 'Symbol.for' + s.substring('Symbol'.length) : s; | ||
} | ||
printSymbol() { | ||
this.memo += this.object.toString(); | ||
this.memo += this.#printSymbol(this.object); | ||
} | ||
@@ -355,3 +369,5 @@ printBigInt() { | ||
this.parent.child(this.key, { isKey: true }, Format).print() | ||
: JSON.stringify(this.key); | ||
: typeof this.key === 'string' | ||
? JSON.stringify(this.key) | ||
: `[${this.#printSymbol(this.key)}]`; | ||
} | ||
@@ -617,27 +633,40 @@ printCircular(seen) { | ||
} | ||
#getPojoKeys(obj, symbols = false) { | ||
// fast path, own string props only | ||
if (!symbols) { | ||
return Object.keys(obj); | ||
} | ||
// get all enumerable symbols | ||
const keys = Object.getOwnPropertySymbols(obj); | ||
return keys.filter(k => Object.getOwnPropertyDescriptor(obj, k)?.enumerable); | ||
} | ||
getPojoKeys(obj = this.object) { | ||
if (this.options.includeEnumerable) { | ||
const keys = []; | ||
// optimized fast path, for/in over enumerable string keys only | ||
for (const i in obj) { | ||
keys.push(i); | ||
} | ||
// walk up proto chain collecting all strings and symbols | ||
for (let p = obj; p; p = Object.getPrototypeOf(p)) { | ||
keys.push(...this.#getPojoKeys(p, true)); | ||
} | ||
return keys; | ||
} | ||
else if (this.options.includeGetters) { | ||
const own = new Set(Object.keys(obj)); | ||
const proto = Object.getPrototypeOf(obj); | ||
if (proto) { | ||
const desc = Object.getOwnPropertyDescriptors(proto); | ||
for (const [name, prop] of Object.entries(desc)) { | ||
if (prop.enumerable && typeof prop.get === 'function') { | ||
// public wrappers around internal things are worth showing | ||
own.add(name); | ||
} | ||
const keys = this.#getPojoKeys(obj).concat(this.#getPojoKeys(obj, true)); | ||
if (!this.options.includeGetters) { | ||
return keys; | ||
} | ||
const own = new Set(keys); | ||
const proto = Object.getPrototypeOf(obj); | ||
if (proto) { | ||
const desc = Object.getOwnPropertyDescriptors(proto); | ||
for (const [name, prop] of Object.entries(desc)) { | ||
if (prop.enumerable && typeof prop.get === 'function') { | ||
// public wrappers around internal things are worth showing | ||
own.add(name); | ||
} | ||
} | ||
return Array.from(own); | ||
} | ||
else { | ||
return Object.keys(obj); | ||
} | ||
return Array.from(own); | ||
} | ||
@@ -685,3 +714,3 @@ printPojo() { | ||
return this.sort | ||
? ent.sort((a, b) => a[0].localeCompare(b[0], 'en')) | ||
? ent.sort((a, b) => String(a[0]).localeCompare(String(b[0]), 'en')) | ||
: ent; | ||
@@ -688,0 +717,0 @@ } |
@@ -9,3 +9,3 @@ import { Same } from './same.js'; | ||
isArray(): boolean; | ||
getPojoEntries(obj: any): [string, any][]; | ||
getPojoEntries(obj: any): [PropertyKey, any][]; | ||
printMapEntryUnexpected(_key: any, _val: any): void; | ||
@@ -12,0 +12,0 @@ get objectAsArray(): any[] | null; |
@@ -40,3 +40,3 @@ "use strict"; | ||
return this.sort | ||
? ent.sort((a, b) => a[0].localeCompare(b[0], 'en')) | ||
? ent.sort((a, b) => String(a[0]).localeCompare(String(b[0]), 'en')) | ||
: ent; | ||
@@ -43,0 +43,0 @@ } |
@@ -68,3 +68,3 @@ import { Format, FormatOptions } from './format.js'; | ||
printPojoEmpty(): void; | ||
getPojoKeys(obj?: any): string[]; | ||
getPojoKeys(obj?: any): PropertyKey[]; | ||
printPojoHead(): void; | ||
@@ -71,0 +71,0 @@ printPojoTail(): void; |
@@ -89,2 +89,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
export declare class Format { | ||
#private; | ||
options: FormatOptions; | ||
@@ -189,3 +190,3 @@ parent: Format | null; | ||
printErrorBody(): void; | ||
getPojoKeys(obj?: any): string[]; | ||
getPojoKeys(obj?: any): PropertyKey[]; | ||
printPojo(): void; | ||
@@ -196,3 +197,3 @@ pojoIsEmpty(obj?: any): boolean; | ||
printPojoBody(): void; | ||
getPojoEntries(obj: any): [string, any][]; | ||
getPojoEntries(obj: any): [PropertyKey, any][]; | ||
printPojoTail(): void; | ||
@@ -199,0 +200,0 @@ printPojoEntry(key: any, val: any): void; |
@@ -301,4 +301,18 @@ import { styles } from './styles.js'; | ||
} | ||
#printSymbol(sym) { | ||
const keyFor = Symbol.keyFor(sym); | ||
const s = String(sym); | ||
if (s.startsWith('Symbol(Symbol.')) { | ||
// check to see if it's a key on the Symbol global. | ||
// return Symbol.iterator, not Symbol(Symbol.iterator) | ||
const symKey = s.substring('Symbol(Symbol.'.length, s.length - 1); | ||
if (symKey && | ||
Symbol[symKey] === sym) { | ||
return `Symbol.${symKey}`; | ||
} | ||
} | ||
return keyFor ? 'Symbol.for' + s.substring('Symbol'.length) : s; | ||
} | ||
printSymbol() { | ||
this.memo += this.object.toString(); | ||
this.memo += this.#printSymbol(this.object); | ||
} | ||
@@ -352,3 +366,5 @@ printBigInt() { | ||
this.parent.child(this.key, { isKey: true }, Format).print() | ||
: JSON.stringify(this.key); | ||
: typeof this.key === 'string' | ||
? JSON.stringify(this.key) | ||
: `[${this.#printSymbol(this.key)}]`; | ||
} | ||
@@ -614,27 +630,40 @@ printCircular(seen) { | ||
} | ||
#getPojoKeys(obj, symbols = false) { | ||
// fast path, own string props only | ||
if (!symbols) { | ||
return Object.keys(obj); | ||
} | ||
// get all enumerable symbols | ||
const keys = Object.getOwnPropertySymbols(obj); | ||
return keys.filter(k => Object.getOwnPropertyDescriptor(obj, k)?.enumerable); | ||
} | ||
getPojoKeys(obj = this.object) { | ||
if (this.options.includeEnumerable) { | ||
const keys = []; | ||
// optimized fast path, for/in over enumerable string keys only | ||
for (const i in obj) { | ||
keys.push(i); | ||
} | ||
// walk up proto chain collecting all strings and symbols | ||
for (let p = obj; p; p = Object.getPrototypeOf(p)) { | ||
keys.push(...this.#getPojoKeys(p, true)); | ||
} | ||
return keys; | ||
} | ||
else if (this.options.includeGetters) { | ||
const own = new Set(Object.keys(obj)); | ||
const proto = Object.getPrototypeOf(obj); | ||
if (proto) { | ||
const desc = Object.getOwnPropertyDescriptors(proto); | ||
for (const [name, prop] of Object.entries(desc)) { | ||
if (prop.enumerable && typeof prop.get === 'function') { | ||
// public wrappers around internal things are worth showing | ||
own.add(name); | ||
} | ||
const keys = this.#getPojoKeys(obj).concat(this.#getPojoKeys(obj, true)); | ||
if (!this.options.includeGetters) { | ||
return keys; | ||
} | ||
const own = new Set(keys); | ||
const proto = Object.getPrototypeOf(obj); | ||
if (proto) { | ||
const desc = Object.getOwnPropertyDescriptors(proto); | ||
for (const [name, prop] of Object.entries(desc)) { | ||
if (prop.enumerable && typeof prop.get === 'function') { | ||
// public wrappers around internal things are worth showing | ||
own.add(name); | ||
} | ||
} | ||
return Array.from(own); | ||
} | ||
else { | ||
return Object.keys(obj); | ||
} | ||
return Array.from(own); | ||
} | ||
@@ -682,3 +711,3 @@ printPojo() { | ||
return this.sort | ||
? ent.sort((a, b) => a[0].localeCompare(b[0], 'en')) | ||
? ent.sort((a, b) => String(a[0]).localeCompare(String(b[0]), 'en')) | ||
: ent; | ||
@@ -685,0 +714,0 @@ } |
@@ -9,3 +9,3 @@ import { Same } from './same.js'; | ||
isArray(): boolean; | ||
getPojoEntries(obj: any): [string, any][]; | ||
getPojoEntries(obj: any): [PropertyKey, any][]; | ||
printMapEntryUnexpected(_key: any, _val: any): void; | ||
@@ -12,0 +12,0 @@ get objectAsArray(): any[] | null; |
@@ -37,3 +37,3 @@ import { Format } from './format.js'; | ||
return this.sort | ||
? ent.sort((a, b) => a[0].localeCompare(b[0], 'en')) | ||
? ent.sort((a, b) => String(a[0]).localeCompare(String(b[0]), 'en')) | ||
: ent; | ||
@@ -40,0 +40,0 @@ } |
@@ -68,3 +68,3 @@ import { Format, FormatOptions } from './format.js'; | ||
printPojoEmpty(): void; | ||
getPojoKeys(obj?: any): string[]; | ||
getPojoKeys(obj?: any): PropertyKey[]; | ||
printPojoHead(): void; | ||
@@ -71,0 +71,0 @@ printPojoTail(): void; |
{ | ||
"name": "tcompare", | ||
"version": "6.3.0", | ||
"version": "6.4.0", | ||
"description": "A comprehensive comparison library, for use in test frameworks", | ||
@@ -5,0 +5,0 @@ "tshy": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
479536
5036