Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@vitest/utils

Package Overview
Dependencies
Maintainers
5
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vitest/utils - npm Package Compare versions

Comparing version
4.1.0-beta.1
to
4.1.0-beta.2
+2
-1
dist/display.d.ts

@@ -20,4 +20,5 @@ import { PrettyFormatOptions } from '@vitest/pretty-format';

maxLength?: number;
filterNode?: string | ((node: any) => boolean);
}
declare function stringify(object: unknown, maxDepth?: number, { maxLength, ...options }?: StringifyOptions): string;
declare function stringify(object: unknown, maxDepth?: number, { maxLength, filterNode, ...options }?: StringifyOptions): string;
declare const formatRegExp: RegExp;

@@ -24,0 +25,0 @@ declare function format(...args: unknown[]): string;

@@ -1,2 +0,2 @@

import { plugins, format as format$1 } from '@vitest/pretty-format';
import { plugins, createDOMElementFilter, format as format$1 } from '@vitest/pretty-format';

@@ -586,5 +586,15 @@ const ansiColors = {

];
function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
function stringify(object, maxDepth = 10, { maxLength, filterNode, ...options } = {}) {
const MAX_LENGTH = maxLength ?? 1e4;
let result;
// Convert string selector to filter function
const filterFn = typeof filterNode === "string" ? createNodeFilterFromSelector(filterNode) : filterNode;
const plugins = filterFn ? [
ReactTestComponent,
ReactElement,
createDOMElementFilter(filterFn),
DOMCollection,
Immutable,
AsymmetricMatcher
] : PLUGINS;
try {

@@ -594,3 +604,3 @@ result = format$1(object, {

escapeString: false,
plugins: PLUGINS,
plugins,
...options

@@ -603,3 +613,3 @@ });

escapeString: false,
plugins: PLUGINS,
plugins,
...options

@@ -611,5 +621,25 @@ });

maxLength,
filterNode,
...options
}) : result;
}
function createNodeFilterFromSelector(selector) {
const ELEMENT_NODE = 1;
const COMMENT_NODE = 8;
return (node) => {
// Filter out comments
if (node.nodeType === COMMENT_NODE) {
return false;
}
// Filter out elements matching the selector
if (node.nodeType === ELEMENT_NODE && node.matches) {
try {
return !node.matches(selector);
} catch {
return true;
}
}
return true;
};
}
const formatRegExp = /%[sdjifoOc%]/g;

@@ -616,0 +646,0 @@ function baseFormat(args, options = {}) {

@@ -38,2 +38,3 @@ import { Nullable, Arrayable } from './types.js';

declare function withTrailingSlash(path: string): string;
declare function filterOutComments(s: string): string;
declare function isBareImport(id: string): boolean;

@@ -72,4 +73,5 @@ declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;

declare function deepMerge<T extends object = object>(target: T, ...sources: any[]): T;
declare function unique<T>(array: T[]): T[];
export { assertTypes, cleanUrl, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isBareImport, isExternalUrl, isNegativeNaN, isObject, isPrimitive, nanoid, noop, notNullish, objectAttr, shuffle, slash, toArray, unwrapId, withTrailingSlash, wrapId };
export { assertTypes, cleanUrl, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, filterOutComments, getCallLastIndex, getOwnProperties, getType, isBareImport, isExternalUrl, isNegativeNaN, isObject, isPrimitive, nanoid, noop, notNullish, objectAttr, shuffle, slash, toArray, unique, unwrapId, withTrailingSlash, wrapId };
export type { DeferPromise };

@@ -91,2 +91,27 @@ import { VALID_ID_PREFIX, NULL_BYTE_PLACEHOLDER } from './constants.js';

}
function filterOutComments(s) {
const result = [];
let commentState = "none";
for (let i = 0; i < s.length; ++i) {
if (commentState === "singleline") {
if (s[i] === "\n") {
commentState = "none";
}
} else if (commentState === "multiline") {
if (s[i - 1] === "*" && s[i] === "/") {
commentState = "none";
}
} else if (commentState === "none") {
if (s[i] === "/" && s[i + 1] === "/") {
commentState = "singleline";
} else if (s[i] === "/" && s[i + 1] === "*") {
commentState = "multiline";
i += 2;
} else {
result.push(s[i]);
}
}
}
return result.join("");
}
const bareImportRE = /^(?![a-z]:)[\w@](?!.*:\/\/)/i;

@@ -295,3 +320,6 @@ function isBareImport(id) {

}
function unique(array) {
return Array.from(new Set(array));
}
export { assertTypes, cleanUrl, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isBareImport, isExternalUrl, isNegativeNaN, isObject, isPrimitive, nanoid, noop, notNullish, objectAttr, shuffle, slash, toArray, unwrapId, withTrailingSlash, wrapId };
export { assertTypes, cleanUrl, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, filterOutComments, getCallLastIndex, getOwnProperties, getType, isBareImport, isExternalUrl, isNegativeNaN, isObject, isPrimitive, nanoid, noop, notNullish, objectAttr, shuffle, slash, toArray, unique, unwrapId, withTrailingSlash, wrapId };

@@ -238,2 +238,4 @@ import { isPrimitive, notNullish } from './helpers.js';

];
const NOW_LENGTH = Date.now().toString().length;
const REGEXP_VITEST = new RegExp(`vitest=\\d{${NOW_LENGTH}}`);
function extractLocation(urlLike) {

@@ -263,2 +265,5 @@ // Fail-fast but return locations like "(native)"

}
if (url.includes("vitest=")) {
url = url.replace(REGEXP_VITEST, "").replace(/[?&]$/, "");
}
return [

@@ -265,0 +270,0 @@ url,

{
"name": "@vitest/utils",
"type": "module",
"version": "4.1.0-beta.1",
"version": "4.1.0-beta.2",
"description": "Shared Vitest utility functions",

@@ -85,3 +85,3 @@ "license": "MIT",

"tinyrainbow": "^3.0.3",
"@vitest/pretty-format": "4.1.0-beta.1"
"@vitest/pretty-format": "4.1.0-beta.2"
},

@@ -88,0 +88,0 @@ "devDependencies": {