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

tcompare

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tcompare - npm Package Compare versions

Comparing version 6.0.1-1 to 6.0.1-2

dist/cjs/match-only-strict.d.ts

59

dist/cjs/format.d.ts

@@ -1,16 +0,69 @@

/// <reference types="node" />
import type { Style } from './styles.js';
/// <reference types="node" resolution-mode="require"/>
import { Style, StyleType } from './styles.js';
/**
* The base class for all other comparators, and used
* directly by comparators for their "simplePrint" methods.
* It doesn't do comparison, just formatting.
*/
export interface FormatOptions {
/** set when formatting keys and values of collections */
parent?: Format;
/** sort items alphabetically by key */
sort?: boolean;
/**
* test whether an object has been seen, and get a reference to the
* Format handling them, if so.
*
* overridden in child classes when doing simplePrint()
*/
seen?: (obj?: any) => false | Format;
style?: string;
/** how to print this thing */
style?: StyleType;
/**
* optinally override {@link Style#bufferChunkSize }
* */
bufferChunkSize?: number;
/**
* Set when printing child fields
*
* @internal
*/
key?: any;
/**
* used when formatting Map keys
*
* @internal
*/
isKey?: boolean;
/**
* level within the object graph being printed
*
* @internal
*/
level?: number;
/**
* indentation level of this object within the object graph
*
* @internal
*/
indent?: string;
/**
* used when provisionally exploring a path for comparison
*
* @internal
*/
provisional?: boolean;
/**
* Include any and all enumerable properties, including those inherited on
* the prototype chain. By default, only `own` properties are printed.
*/
includeEnumerable?: boolean;
/**
* Include getter properties
*/
includeGetters?: boolean;
/**
* The object being compared against in comparison classes. (Not used
* in {@link Format}.)
*/
expect?: any;

@@ -17,0 +70,0 @@ }

3

dist/cjs/format.js
"use strict";
// Format is the base class for all other comparators, and used
// directly by comparators for their "simplePrint" methods.
// It doesn't do comparison, just formatting.
Object.defineProperty(exports, "__esModule", { value: true });

@@ -6,0 +3,0 @@ exports.Format = void 0;

import { Has } from './has.js';
/**
* The same as {@link Has}, but strictly compare all properties
*/
export declare class HasStrict extends Has {

@@ -3,0 +6,0 @@ test(): boolean | "COMPLEX";

@@ -6,2 +6,5 @@ "use strict";

const strict_js_1 = require("./strict.js");
/**
* The same as {@link Has}, but strictly compare all properties
*/
class HasStrict extends has_js_1.Has {

@@ -8,0 +11,0 @@ test() {

import { Same } from './same.js';
/**
* The same as {@link Same}, but ignore any fields present in the
* test object and not present in the expect pattern.
*/
export declare class Has extends Same {

@@ -3,0 +7,0 @@ simpleMatch(): void;

@@ -6,2 +6,6 @@ "use strict";

const same_js_1 = require("./same.js");
/**
* The same as {@link Same}, but ignore any fields present in the
* test object and not present in the expect pattern.
*/
class Has extends same_js_1.Same {

@@ -8,0 +12,0 @@ // don't care about object shape, only that it has

@@ -0,16 +1,40 @@

/**
* Export all implementation classes, and convenience methods for each
* @module
*/
import { FormatOptions } from './format.js';
import { SameOptions } from './same.js';
/**
* The return value from all comparison functions.
*/
export interface Result {
/**
* Diff of formatted test object and expected pattern. Only shows
* properties which differ, not the entire object.
*/
diff: string;
/**
* whether or not the objects are a satisfying match
*/
match: boolean;
}
export type CompareOptions = FormatOptions & Pick<SameOptions, 'diffContext'>;
/** format a value and return the formatted string */
export declare const format: (obj: any, options?: FormatOptions) => string;
/** convenience method for {@link Same} */
export declare const same: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link Strict} */
export declare const strict: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link Has} */
export declare const has: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link HasStrict} */
export declare const hasStrict: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link Match} */
export declare const match: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link MatchOnly} */
export declare const matchOnly: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link MatchStrict} */
export declare const matchStrict: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link MatchOnlyStrict} */
export declare const matchOnlyStrict: (obj: any, pattern: any, options?: CompareOptions) => Result;
export { Format } from './format.js';

@@ -22,2 +46,3 @@ export type { FormatOptions } from './format.js';

export { MatchStrict } from './match-strict.js';
export { MatchOnlyStrict } from './match-only-strict.js';
export { Match } from './match.js';

@@ -24,0 +49,0 @@ export { Same } from './same.js';

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.styles = exports.Strict = exports.Same = exports.Match = exports.MatchStrict = exports.MatchOnly = exports.Has = exports.HasStrict = exports.Format = exports.matchStrict = exports.matchOnly = exports.match = exports.hasStrict = exports.has = exports.strict = exports.same = exports.format = void 0;
exports.styles = exports.Strict = exports.Same = exports.Match = exports.MatchOnlyStrict = exports.MatchStrict = exports.MatchOnly = exports.Has = exports.HasStrict = exports.Format = exports.matchOnlyStrict = exports.matchStrict = exports.matchOnly = exports.match = exports.hasStrict = exports.has = exports.strict = exports.same = exports.format = void 0;
/**
* Export all implementation classes, and convenience methods for each
* @module
*/
const format_js_1 = require("./format.js");

@@ -9,2 +13,3 @@ const has_strict_js_1 = require("./has-strict.js");

const match_strict_js_1 = require("./match-strict.js");
const match_only_strict_js_1 = require("./match-only-strict.js");
const match_js_1 = require("./match.js");

@@ -22,11 +27,21 @@ const same_js_1 = require("./same.js");

}));
/** format a value and return the formatted string */
const format = (obj, options = {}) => new format_js_1.Format(obj, options).print();
exports.format = format;
/** convenience method for {@link Same} */
exports.same = fn(same_js_1.Same);
/** convenience method for {@link Strict} */
exports.strict = fn(strict_js_1.Strict);
/** convenience method for {@link Has} */
exports.has = fn(has_js_1.Has);
/** convenience method for {@link HasStrict} */
exports.hasStrict = fn(has_strict_js_1.HasStrict);
/** convenience method for {@link Match} */
exports.match = fn(match_js_1.Match);
/** convenience method for {@link MatchOnly} */
exports.matchOnly = fn(match_only_js_1.MatchOnly);
/** convenience method for {@link MatchStrict} */
exports.matchStrict = fn(match_strict_js_1.MatchStrict);
/** convenience method for {@link MatchOnlyStrict} */
exports.matchOnlyStrict = fn(match_only_strict_js_1.MatchOnlyStrict);
var format_js_2 = require("./format.js");

@@ -42,2 +57,4 @@ Object.defineProperty(exports, "Format", { enumerable: true, get: function () { return format_js_2.Format; } });

Object.defineProperty(exports, "MatchStrict", { enumerable: true, get: function () { return match_strict_js_2.MatchStrict; } });
var match_only_strict_js_2 = require("./match-only-strict.js");
Object.defineProperty(exports, "MatchOnlyStrict", { enumerable: true, get: function () { return match_only_strict_js_2.MatchOnlyStrict; } });
var match_js_2 = require("./match.js");

@@ -44,0 +61,0 @@ Object.defineProperty(exports, "Match", { enumerable: true, get: function () { return match_js_2.Match; } });

import { Same } from './same.js';
/**
* this uses the test method from {@link Match}, but requires that *only* the
* specified fields in the pattern are present in the object.
*
* It does still allow a field to be present in the object and not the pattern
* if the value is set to null or undefined.
*/
export declare class MatchOnly extends Same {

@@ -3,0 +10,0 @@ test(): boolean | "COMPLEX";

"use strict";
// this uses the test method from match, but requires that *only*
// the specified fields in the pattern are present in the object.
//
// Note: it does still allow a field to be present in the object
// and not the pattern if the value is set to null or undefined.
Object.defineProperty(exports, "__esModule", { value: true });

@@ -11,2 +6,9 @@ exports.MatchOnly = void 0;

const same_js_1 = require("./same.js");
/**
* this uses the test method from {@link Match}, but requires that *only* the
* specified fields in the pattern are present in the object.
*
* It does still allow a field to be present in the object and not the pattern
* if the value is set to null or undefined.
*/
class MatchOnly extends same_js_1.Same {

@@ -13,0 +15,0 @@ test() {

import { Match } from './match.js';
/**
* Identical to {@link Match}, *except* in the case of two simple types.
* If the value loosely equals the expected pattern, but is not strictly
* equal, then the test returns false.
*/
export declare class MatchStrict extends Match {

@@ -3,0 +8,0 @@ test(): boolean | "COMPLEX";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MatchStrict = void 0;
// this is a weird one. Basically, it is identical to Match,
// EXCEPT in the case of two simple types. If the object == expect,
// but the object does not === expect, then it returns false.
const match_js_1 = require("./match.js");
/**
* Identical to {@link Match}, *except* in the case of two simple types.
* If the value loosely equals the expected pattern, but is not strictly
* equal, then the test returns false.
*/
class MatchStrict extends match_js_1.Match {

@@ -9,0 +11,0 @@ test() {

import { Has } from './has.js';
/**
* The loosed and most flexibly magical matching strategy.
*
* - If the objects pass the {@link Has} test, then return true.
* - If the pattern is a regular expression, then test it against the
* string form of the test value.
* - If the pattern is a string, and the test value is a string, then test
* that the pattern appears somewhere in the test value.
* - If the pattern is a string, and the test value is a Date, then test
* parse the pattern as a Date and verify that they have the same value
* - If the pattern is a constructor, then test that the value is an
* instance of the constructor. In the case of scalar constructors, like
* Number, Boolean, etc, also pass if the `typeof` the value matches.
* That is `Match(1, { expect: Number })` passes.
* - If the pattern is the `Array` constructor, then pass for any iterable
* valuef.
*/
export declare class Match extends Has {

@@ -3,0 +20,0 @@ test(): boolean | 'COMPLEX';

@@ -6,2 +6,19 @@ "use strict";

const has_js_1 = require("./has.js");
/**
* The loosed and most flexibly magical matching strategy.
*
* - If the objects pass the {@link Has} test, then return true.
* - If the pattern is a regular expression, then test it against the
* string form of the test value.
* - If the pattern is a string, and the test value is a string, then test
* that the pattern appears somewhere in the test value.
* - If the pattern is a string, and the test value is a Date, then test
* parse the pattern as a Date and verify that they have the same value
* - If the pattern is a constructor, then test that the value is an
* instance of the constructor. In the case of scalar constructors, like
* Number, Boolean, etc, also pass if the `typeof` the value matches.
* That is `Match(1, { expect: Number })` passes.
* - If the pattern is the `Array` constructor, then pass for any iterable
* valuef.
*/
class Match extends has_js_1.Has {

@@ -8,0 +25,0 @@ test() {

import { Format, FormatOptions } from './format.js';
/**
* Options for all comparator operations
*/
export interface SameOptions extends FormatOptions {
/** the pattern to test against */
expect: any;

@@ -7,4 +11,27 @@ parent?: Same;

expectKey?: any;
/**
* how many lines of context to print around changes in diffs
* @default 10
*/
diffContext?: number;
}
/**
* Base class for all comparators
*
* We walk through both of the expect and actual objects,
* creating a Same node for each field in common, based on
* their similarity:
* - true (they're a match) omit from the result (the child node is discarded)
* - false (they're simply nonmatching) format both expect and object
* - COMPLEX - walk through child nodes
* - if match: child node is discarded
* - else, child node is retained (along with its non-matching children)
*
* We 'discard' by just having the print method return ''
*
* When walking child nodes, we use the shouldCompare(key) method to determine
* whether to check a given field. In this class, this is always true (because
* we are testing for full deep sameness), but in {@link Has} and subclasses,
* it's more complicated (only test nodes that exist in the expect object).
*/
export declare class Same extends Format {

@@ -11,0 +38,0 @@ provisional: boolean;

"use strict";
// Same is the base class for all comparators
//
// We walk through both of the expect and actual objects,
// creating a Same node for each field in common, based on
// their similarity:
// - true (they're a match) omit from the result (the child node is discarded)
// - false (they're simply nonmatching) format both expect and object
// - COMPLEX - walk through child nodes
// - if match: child node is discarded
// - else, child node is retained (along with its non-matching children)
//
// We 'discard' by just having the print method return ''
//
// When walking child nodes, we use the shouldCompare(key) method to determine
// whether to check a given field. In this class, this is always true (because
// we are testing for full deep sameness), but in Has classes, it's more
// complicated (only test nodes that exist in the expect object).
Object.defineProperty(exports, "__esModule", { value: true });

@@ -33,2 +16,21 @@ exports.Same = void 0;

const { defineProperty } = Object;
/**
* Base class for all comparators
*
* We walk through both of the expect and actual objects,
* creating a Same node for each field in common, based on
* their similarity:
* - true (they're a match) omit from the result (the child node is discarded)
* - false (they're simply nonmatching) format both expect and object
* - COMPLEX - walk through child nodes
* - if match: child node is discarded
* - else, child node is retained (along with its non-matching children)
*
* We 'discard' by just having the print method return ''
*
* When walking child nodes, we use the shouldCompare(key) method to determine
* whether to check a given field. In this class, this is always true (because
* we are testing for full deep sameness), but in {@link Has} and subclasses,
* it's more complicated (only test nodes that exist in the expect object).
*/
class Same extends format_js_1.Format {

@@ -35,0 +37,0 @@ provisional;

import { Same } from './same.js';
/**
* The same as {@link Same}, but without type coercion
*/
export declare class Strict extends Same {

@@ -3,0 +6,0 @@ test(): boolean | "COMPLEX";

@@ -6,2 +6,5 @@ "use strict";

const same_js_1 = require("./same.js");
/**
* The same as {@link Same}, but without type coercion
*/
class Strict extends same_js_1.Same {

@@ -8,0 +11,0 @@ test() {

@@ -1,18 +0,38 @@

/// <reference types="node" />
/// <reference types="node" resolution-mode="require"/>
import type { Format } from './format.js';
export type StyleType = 'pretty' | 'js' | 'tight';
/**
* A set of functions defining how various sorts of things get converted
* into strings.
*/
export interface Style {
/** a function, optionally with a class name */
fn: (fn: Function, cls: string) => string;
/** an empty `Set` */
setEmpty: (cls: string) => string;
/** start of a `Set` */
setHead: (cls: string) => string;
/** end of a `Set` */
setTail: (indent: string) => string;
/** separator between entries in a `Set` */
setEntrySep: () => string;
/** an empty `Map` */
mapEmpty: (cls: string) => string;
/** start of a `Map` */
mapHead: (cls: string) => string;
/** end of a `Map` */
mapTail: (indent: string) => string;
/** start of a key in a `Map` */
mapKeyStart: () => string;
/** separator between key and value in a `Map` */
mapKeyValSep: () => string;
/** separator between entries in a `Map` */
mapEntrySep: () => string;
/** what to print when we encounter a circular reference */
circular: (node: Format) => string;
/** how to print node identifiers for circular references */
nodeId: (id: number) => string;
/** an empty `Error` object */
errorEmpty: (er: Error, cls: string) => string;
/** start of an `Error` object */
errorHead: (er: (Error | {

@@ -24,35 +44,67 @@ name?: string;

}, cls: string) => string;
/** end of an `Error` object */
errorTail: (indent: string) => string;
/** empty JavaScript object */
pojoEmpty: (cls: string) => string;
/** start of a JavaScript object */
pojoHead: (cls: string) => string;
/** end of a JavaScript object */
pojoTail: (indent: string) => string;
/** separator between key and value in a JavaScript object */
pojoKeyValSep: () => string;
/** separator between entries in a JavaScript object */
pojoEntrySep: () => string;
/** an empty `Array` */
arrayEmpty: (cls: string) => string;
/** start of an `Array` */
arrayHead: (cls: string) => string;
/** end of an `Array` */
arrayTail: (indent: string) => string;
/** separator between entries in an `Array` */
arrayEntrySep: () => string;
/**
* how many bytes of a `Buffer` to show per line. can be overridden by
* the Format constructor options.
* */
bufferChunkSize: number;
/** an empty `Buffer` */
bufferEmpty: () => string;
/** start of a short `Buffer` */
bufferStart: () => string;
/** contents of a short `Buffer` */
bufferBody: (buf: Buffer) => string;
/** end of a short `Buffer` */
bufferEnd: (buf: Buffer) => string;
/** start of a long `Buffer` */
bufferHead: () => string;
/** line numbers to print for lines in a long `Buffer` */
bufferKey: (i: number) => string;
/** line of bytes in a long `Buffer` */
bufferLine: (buf: Buffer, chunkSize: number) => string;
/** separator between lines in a long `Buffer` */
bufferLineSep: () => string;
/** end of a long `Buffer` */
bufferTail: (indent: string) => string;
/** separator between line number and contents of a long `Buffer` */
bufferKeySep: () => string;
/** an empty string */
stringEmpty: () => string;
/** a string that fits on one line */
stringOneLine: (str: string) => string;
/** start of a long string */
stringHead: () => string;
/** separator between lines of a long string */
stringLineSep: () => string;
/** each line of a long string */
stringLine: (str: string) => string;
/** end of a long string */
stringTail: (indent: string) => string;
/** indicator as to whether this style is suitable for use in diffs */
diffable: boolean;
/** beginning of a thing being printed */
start: (indent: string, key: string, sep: string) => string;
}
export declare const styles: {
[style: string]: Style;
[style in StyleType]: Style;
};
//# sourceMappingURL=styles.d.ts.map

@@ -8,4 +8,7 @@ "use strict";

.toString();
exports.styles = {};
exports.styles.pretty = {
/**
* The default style, suitable for diffs, and optimized for human
* readability.
*/
const pretty = {
fn: (fn, cls) => {

@@ -95,3 +98,11 @@ const name = fn.name;

};
exports.styles.js = {
/**
* A style that can (mostly) be copy-pasted into a JS program
* and used as-is.
*
* Of course, object and function identities won't really work,
* and if there are circular references, then the results won't
* be valid JavaScript.
*/
const js = {
fn: (fn, _) => fn.toString(),

@@ -146,5 +157,8 @@ setEmpty: cls => `new ${cls}()`,

};
// this one won't work for diffs
// same as the js style, but no indentation or \n
exports.styles.tight = {
/**
* same as the {@link js} style, but no indentation or \n
*
* Not suitable for diffs, as everything is printed on one line.
*/
const tight = {
fn: (fn, _) => fn.toString(),

@@ -188,11 +202,16 @@ setEmpty: cls => `new ${cls}()`,

stringTail: _ => '',
bufferHead: exports.styles.js.bufferHead,
bufferKey: exports.styles.js.bufferKey,
bufferLine: exports.styles.js.bufferLine,
bufferLineSep: exports.styles.js.bufferLineSep,
bufferTail: exports.styles.js.bufferTail,
bufferKeySep: exports.styles.js.bufferKeySep,
bufferHead: js.bufferHead,
bufferKey: js.bufferKey,
bufferLine: js.bufferLine,
bufferLineSep: js.bufferLineSep,
bufferTail: js.bufferTail,
bufferKeySep: js.bufferKeySep,
diffable: false,
start: (_indent, key, sep) => `${key}${sep}`,
};
exports.styles = {
pretty,
js,
tight,
};
//# sourceMappingURL=styles.js.map

@@ -1,16 +0,69 @@

/// <reference types="node" />
import type { Style } from './styles.js';
/// <reference types="node" resolution-mode="require"/>
import { Style, StyleType } from './styles.js';
/**
* The base class for all other comparators, and used
* directly by comparators for their "simplePrint" methods.
* It doesn't do comparison, just formatting.
*/
export interface FormatOptions {
/** set when formatting keys and values of collections */
parent?: Format;
/** sort items alphabetically by key */
sort?: boolean;
/**
* test whether an object has been seen, and get a reference to the
* Format handling them, if so.
*
* overridden in child classes when doing simplePrint()
*/
seen?: (obj?: any) => false | Format;
style?: string;
/** how to print this thing */
style?: StyleType;
/**
* optinally override {@link Style#bufferChunkSize }
* */
bufferChunkSize?: number;
/**
* Set when printing child fields
*
* @internal
*/
key?: any;
/**
* used when formatting Map keys
*
* @internal
*/
isKey?: boolean;
/**
* level within the object graph being printed
*
* @internal
*/
level?: number;
/**
* indentation level of this object within the object graph
*
* @internal
*/
indent?: string;
/**
* used when provisionally exploring a path for comparison
*
* @internal
*/
provisional?: boolean;
/**
* Include any and all enumerable properties, including those inherited on
* the prototype chain. By default, only `own` properties are printed.
*/
includeEnumerable?: boolean;
/**
* Include getter properties
*/
includeGetters?: boolean;
/**
* The object being compared against in comparison classes. (Not used
* in {@link Format}.)
*/
expect?: any;

@@ -17,0 +70,0 @@ }

@@ -1,4 +0,1 @@

// Format is the base class for all other comparators, and used
// directly by comparators for their "simplePrint" methods.
// It doesn't do comparison, just formatting.
import { styles } from './styles.js';

@@ -5,0 +2,0 @@ const arrayFrom = (obj) => {

import { Has } from './has.js';
/**
* The same as {@link Has}, but strictly compare all properties
*/
export declare class HasStrict extends Has {

@@ -3,0 +6,0 @@ test(): boolean | "COMPLEX";

import { Has } from './has.js';
import { Strict } from './strict.js';
/**
* The same as {@link Has}, but strictly compare all properties
*/
export class HasStrict extends Has {

@@ -4,0 +7,0 @@ test() {

import { Same } from './same.js';
/**
* The same as {@link Same}, but ignore any fields present in the
* test object and not present in the expect pattern.
*/
export declare class Has extends Same {

@@ -3,0 +7,0 @@ simpleMatch(): void;

import { Format } from './format.js';
import { Same } from './same.js';
/**
* The same as {@link Same}, but ignore any fields present in the
* test object and not present in the expect pattern.
*/
export class Has extends Same {

@@ -4,0 +8,0 @@ // don't care about object shape, only that it has

@@ -0,16 +1,40 @@

/**
* Export all implementation classes, and convenience methods for each
* @module
*/
import { FormatOptions } from './format.js';
import { SameOptions } from './same.js';
/**
* The return value from all comparison functions.
*/
export interface Result {
/**
* Diff of formatted test object and expected pattern. Only shows
* properties which differ, not the entire object.
*/
diff: string;
/**
* whether or not the objects are a satisfying match
*/
match: boolean;
}
export type CompareOptions = FormatOptions & Pick<SameOptions, 'diffContext'>;
/** format a value and return the formatted string */
export declare const format: (obj: any, options?: FormatOptions) => string;
/** convenience method for {@link Same} */
export declare const same: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link Strict} */
export declare const strict: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link Has} */
export declare const has: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link HasStrict} */
export declare const hasStrict: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link Match} */
export declare const match: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link MatchOnly} */
export declare const matchOnly: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link MatchStrict} */
export declare const matchStrict: (obj: any, pattern: any, options?: CompareOptions) => Result;
/** convenience method for {@link MatchOnlyStrict} */
export declare const matchOnlyStrict: (obj: any, pattern: any, options?: CompareOptions) => Result;
export { Format } from './format.js';

@@ -22,2 +46,3 @@ export type { FormatOptions } from './format.js';

export { MatchStrict } from './match-strict.js';
export { MatchOnlyStrict } from './match-only-strict.js';
export { Match } from './match.js';

@@ -24,0 +49,0 @@ export { Same } from './same.js';

@@ -0,1 +1,5 @@

/**
* Export all implementation classes, and convenience methods for each
* @module
*/
import { Format } from './format.js';

@@ -6,2 +10,3 @@ import { HasStrict } from './has-strict.js';

import { MatchStrict } from './match-strict.js';
import { MatchOnlyStrict } from './match-only-strict.js';
import { Match } from './match.js';

@@ -19,10 +24,20 @@ import { Same } from './same.js';

}));
/** format a value and return the formatted string */
export const format = (obj, options = {}) => new Format(obj, options).print();
/** convenience method for {@link Same} */
export const same = fn(Same);
/** convenience method for {@link Strict} */
export const strict = fn(Strict);
/** convenience method for {@link Has} */
export const has = fn(Has);
/** convenience method for {@link HasStrict} */
export const hasStrict = fn(HasStrict);
/** convenience method for {@link Match} */
export const match = fn(Match);
/** convenience method for {@link MatchOnly} */
export const matchOnly = fn(MatchOnly);
/** convenience method for {@link MatchStrict} */
export const matchStrict = fn(MatchStrict);
/** convenience method for {@link MatchOnlyStrict} */
export const matchOnlyStrict = fn(MatchOnlyStrict);
export { Format } from './format.js';

@@ -33,2 +48,3 @@ export { HasStrict } from './has-strict.js';

export { MatchStrict } from './match-strict.js';
export { MatchOnlyStrict } from './match-only-strict.js';
export { Match } from './match.js';

@@ -35,0 +51,0 @@ export { Same } from './same.js';

import { Same } from './same.js';
/**
* this uses the test method from {@link Match}, but requires that *only* the
* specified fields in the pattern are present in the object.
*
* It does still allow a field to be present in the object and not the pattern
* if the value is set to null or undefined.
*/
export declare class MatchOnly extends Same {

@@ -3,0 +10,0 @@ test(): boolean | "COMPLEX";

@@ -1,8 +0,10 @@

// this uses the test method from match, but requires that *only*
// the specified fields in the pattern are present in the object.
//
// Note: it does still allow a field to be present in the object
// and not the pattern if the value is set to null or undefined.
import { Match } from './match.js';
import { Same } from './same.js';
/**
* this uses the test method from {@link Match}, but requires that *only* the
* specified fields in the pattern are present in the object.
*
* It does still allow a field to be present in the object and not the pattern
* if the value is set to null or undefined.
*/
export class MatchOnly extends Same {

@@ -9,0 +11,0 @@ test() {

import { Match } from './match.js';
/**
* Identical to {@link Match}, *except* in the case of two simple types.
* If the value loosely equals the expected pattern, but is not strictly
* equal, then the test returns false.
*/
export declare class MatchStrict extends Match {

@@ -3,0 +8,0 @@ test(): boolean | "COMPLEX";

@@ -1,5 +0,7 @@

// this is a weird one. Basically, it is identical to Match,
// EXCEPT in the case of two simple types. If the object == expect,
// but the object does not === expect, then it returns false.
import { Match } from './match.js';
/**
* Identical to {@link Match}, *except* in the case of two simple types.
* If the value loosely equals the expected pattern, but is not strictly
* equal, then the test returns false.
*/
export class MatchStrict extends Match {

@@ -6,0 +8,0 @@ test() {

import { Has } from './has.js';
/**
* The loosed and most flexibly magical matching strategy.
*
* - If the objects pass the {@link Has} test, then return true.
* - If the pattern is a regular expression, then test it against the
* string form of the test value.
* - If the pattern is a string, and the test value is a string, then test
* that the pattern appears somewhere in the test value.
* - If the pattern is a string, and the test value is a Date, then test
* parse the pattern as a Date and verify that they have the same value
* - If the pattern is a constructor, then test that the value is an
* instance of the constructor. In the case of scalar constructors, like
* Number, Boolean, etc, also pass if the `typeof` the value matches.
* That is `Match(1, { expect: Number })` passes.
* - If the pattern is the `Array` constructor, then pass for any iterable
* valuef.
*/
export declare class Match extends Has {

@@ -3,0 +20,0 @@ test(): boolean | 'COMPLEX';

import { Format } from './format.js';
import { Has } from './has.js';
/**
* The loosed and most flexibly magical matching strategy.
*
* - If the objects pass the {@link Has} test, then return true.
* - If the pattern is a regular expression, then test it against the
* string form of the test value.
* - If the pattern is a string, and the test value is a string, then test
* that the pattern appears somewhere in the test value.
* - If the pattern is a string, and the test value is a Date, then test
* parse the pattern as a Date and verify that they have the same value
* - If the pattern is a constructor, then test that the value is an
* instance of the constructor. In the case of scalar constructors, like
* Number, Boolean, etc, also pass if the `typeof` the value matches.
* That is `Match(1, { expect: Number })` passes.
* - If the pattern is the `Array` constructor, then pass for any iterable
* valuef.
*/
export class Match extends Has {

@@ -4,0 +21,0 @@ test() {

import { Format, FormatOptions } from './format.js';
/**
* Options for all comparator operations
*/
export interface SameOptions extends FormatOptions {
/** the pattern to test against */
expect: any;

@@ -7,4 +11,27 @@ parent?: Same;

expectKey?: any;
/**
* how many lines of context to print around changes in diffs
* @default 10
*/
diffContext?: number;
}
/**
* Base class for all comparators
*
* We walk through both of the expect and actual objects,
* creating a Same node for each field in common, based on
* their similarity:
* - true (they're a match) omit from the result (the child node is discarded)
* - false (they're simply nonmatching) format both expect and object
* - COMPLEX - walk through child nodes
* - if match: child node is discarded
* - else, child node is retained (along with its non-matching children)
*
* We 'discard' by just having the print method return ''
*
* When walking child nodes, we use the shouldCompare(key) method to determine
* whether to check a given field. In this class, this is always true (because
* we are testing for full deep sameness), but in {@link Has} and subclasses,
* it's more complicated (only test nodes that exist in the expect object).
*/
export declare class Same extends Format {

@@ -11,0 +38,0 @@ provisional: boolean;

@@ -1,18 +0,1 @@

// Same is the base class for all comparators
//
// We walk through both of the expect and actual objects,
// creating a Same node for each field in common, based on
// their similarity:
// - true (they're a match) omit from the result (the child node is discarded)
// - false (they're simply nonmatching) format both expect and object
// - COMPLEX - walk through child nodes
// - if match: child node is discarded
// - else, child node is retained (along with its non-matching children)
//
// We 'discard' by just having the print method return ''
//
// When walking child nodes, we use the shouldCompare(key) method to determine
// whether to check a given field. In this class, this is always true (because
// we are testing for full deep sameness), but in Has classes, it's more
// complicated (only test nodes that exist in the expect object).
import { createTwoFilesPatch } from 'diff';

@@ -30,2 +13,21 @@ import { Format } from './format.js';

const { defineProperty } = Object;
/**
* Base class for all comparators
*
* We walk through both of the expect and actual objects,
* creating a Same node for each field in common, based on
* their similarity:
* - true (they're a match) omit from the result (the child node is discarded)
* - false (they're simply nonmatching) format both expect and object
* - COMPLEX - walk through child nodes
* - if match: child node is discarded
* - else, child node is retained (along with its non-matching children)
*
* We 'discard' by just having the print method return ''
*
* When walking child nodes, we use the shouldCompare(key) method to determine
* whether to check a given field. In this class, this is always true (because
* we are testing for full deep sameness), but in {@link Has} and subclasses,
* it's more complicated (only test nodes that exist in the expect object).
*/
export class Same extends Format {

@@ -32,0 +34,0 @@ provisional;

import { Same } from './same.js';
/**
* The same as {@link Same}, but without type coercion
*/
export declare class Strict extends Same {

@@ -3,0 +6,0 @@ test(): boolean | "COMPLEX";

import { Format } from './format.js';
import { Same } from './same.js';
/**
* The same as {@link Same}, but without type coercion
*/
export class Strict extends Same {

@@ -4,0 +7,0 @@ test() {

@@ -1,18 +0,38 @@

/// <reference types="node" />
/// <reference types="node" resolution-mode="require"/>
import type { Format } from './format.js';
export type StyleType = 'pretty' | 'js' | 'tight';
/**
* A set of functions defining how various sorts of things get converted
* into strings.
*/
export interface Style {
/** a function, optionally with a class name */
fn: (fn: Function, cls: string) => string;
/** an empty `Set` */
setEmpty: (cls: string) => string;
/** start of a `Set` */
setHead: (cls: string) => string;
/** end of a `Set` */
setTail: (indent: string) => string;
/** separator between entries in a `Set` */
setEntrySep: () => string;
/** an empty `Map` */
mapEmpty: (cls: string) => string;
/** start of a `Map` */
mapHead: (cls: string) => string;
/** end of a `Map` */
mapTail: (indent: string) => string;
/** start of a key in a `Map` */
mapKeyStart: () => string;
/** separator between key and value in a `Map` */
mapKeyValSep: () => string;
/** separator between entries in a `Map` */
mapEntrySep: () => string;
/** what to print when we encounter a circular reference */
circular: (node: Format) => string;
/** how to print node identifiers for circular references */
nodeId: (id: number) => string;
/** an empty `Error` object */
errorEmpty: (er: Error, cls: string) => string;
/** start of an `Error` object */
errorHead: (er: (Error | {

@@ -24,35 +44,67 @@ name?: string;

}, cls: string) => string;
/** end of an `Error` object */
errorTail: (indent: string) => string;
/** empty JavaScript object */
pojoEmpty: (cls: string) => string;
/** start of a JavaScript object */
pojoHead: (cls: string) => string;
/** end of a JavaScript object */
pojoTail: (indent: string) => string;
/** separator between key and value in a JavaScript object */
pojoKeyValSep: () => string;
/** separator between entries in a JavaScript object */
pojoEntrySep: () => string;
/** an empty `Array` */
arrayEmpty: (cls: string) => string;
/** start of an `Array` */
arrayHead: (cls: string) => string;
/** end of an `Array` */
arrayTail: (indent: string) => string;
/** separator between entries in an `Array` */
arrayEntrySep: () => string;
/**
* how many bytes of a `Buffer` to show per line. can be overridden by
* the Format constructor options.
* */
bufferChunkSize: number;
/** an empty `Buffer` */
bufferEmpty: () => string;
/** start of a short `Buffer` */
bufferStart: () => string;
/** contents of a short `Buffer` */
bufferBody: (buf: Buffer) => string;
/** end of a short `Buffer` */
bufferEnd: (buf: Buffer) => string;
/** start of a long `Buffer` */
bufferHead: () => string;
/** line numbers to print for lines in a long `Buffer` */
bufferKey: (i: number) => string;
/** line of bytes in a long `Buffer` */
bufferLine: (buf: Buffer, chunkSize: number) => string;
/** separator between lines in a long `Buffer` */
bufferLineSep: () => string;
/** end of a long `Buffer` */
bufferTail: (indent: string) => string;
/** separator between line number and contents of a long `Buffer` */
bufferKeySep: () => string;
/** an empty string */
stringEmpty: () => string;
/** a string that fits on one line */
stringOneLine: (str: string) => string;
/** start of a long string */
stringHead: () => string;
/** separator between lines of a long string */
stringLineSep: () => string;
/** each line of a long string */
stringLine: (str: string) => string;
/** end of a long string */
stringTail: (indent: string) => string;
/** indicator as to whether this style is suitable for use in diffs */
diffable: boolean;
/** beginning of a thing being printed */
start: (indent: string, key: string, sep: string) => string;
}
export declare const styles: {
[style: string]: Style;
[style in StyleType]: Style;
};
//# sourceMappingURL=styles.d.ts.map

@@ -5,4 +5,7 @@ // can't use buf.toString('ascii') because that unmasks high bytes

.toString();
export const styles = {};
styles.pretty = {
/**
* The default style, suitable for diffs, and optimized for human
* readability.
*/
const pretty = {
fn: (fn, cls) => {

@@ -92,3 +95,11 @@ const name = fn.name;

};
styles.js = {
/**
* A style that can (mostly) be copy-pasted into a JS program
* and used as-is.
*
* Of course, object and function identities won't really work,
* and if there are circular references, then the results won't
* be valid JavaScript.
*/
const js = {
fn: (fn, _) => fn.toString(),

@@ -143,5 +154,8 @@ setEmpty: cls => `new ${cls}()`,

};
// this one won't work for diffs
// same as the js style, but no indentation or \n
styles.tight = {
/**
* same as the {@link js} style, but no indentation or \n
*
* Not suitable for diffs, as everything is printed on one line.
*/
const tight = {
fn: (fn, _) => fn.toString(),

@@ -185,11 +199,16 @@ setEmpty: cls => `new ${cls}()`,

stringTail: _ => '',
bufferHead: styles.js.bufferHead,
bufferKey: styles.js.bufferKey,
bufferLine: styles.js.bufferLine,
bufferLineSep: styles.js.bufferLineSep,
bufferTail: styles.js.bufferTail,
bufferKeySep: styles.js.bufferKeySep,
bufferHead: js.bufferHead,
bufferKey: js.bufferKey,
bufferLine: js.bufferLine,
bufferLineSep: js.bufferLineSep,
bufferTail: js.bufferTail,
bufferKeySep: js.bufferKeySep,
diffable: false,
start: (_indent, key, sep) => `${key}${sep}`,
};
export const styles = {
pretty,
js,
tight,
};
//# sourceMappingURL=styles.js.map
{
"name": "tcompare",
"version": "6.0.1-1",
"version": "6.0.1-2",
"description": "A comprehensive comparison library, for use in test frameworks",
"author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)",
"license": "ISC",
"main": "./dist/cjs/index.js",
"module": "./dist/mjs/index.js",
"type": "module",
"exports": {

@@ -10,0 +9,0 @@ "./package.json": {

@@ -19,4 +19,5 @@ # tcompare

hasStrict,
matchStrict,
matchOnly,
matchStrict,
matchOnlyStrict,
} from 'tcompare'

@@ -103,4 +104,8 @@ import type { Result } from 'tcompare'

testing as `match()`, but will fail when two values are
equivalent but not strictly equal. (That is, when `a == b &&
!(a === b)`.)
equivalent but not strictly equal. (That is, when
`a == b && !(a === b)`.)
- `matchOnlyStrict(object, pattern, [options])` - Same comparison
testing as `matchOnly()`, but will fail when two values are
equivalent but not strictly equal. (That is, when
`a == b && !(a === b)`.)

@@ -130,2 +135,3 @@ There are classes exported to correspond to each of these. All of these are

+-- MatchOnly (uses Match.prototype.test)
+-- MatchOnlyStrict (uses MatchStrict.prototype.test)
```

@@ -132,0 +138,0 @@

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

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

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

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

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