UNPKG

@visulima/string

Version:

Functions for manipulating strings.

17 lines (13 loc) 1.77 kB
var d=Object.defineProperty;var a=(e,t)=>d(e,"name",{value:t,configurable:!0});import{createRequire as g}from"node:module";import{getStringWidth as l}from"../get-string-width.js";const u=g(import.meta.url),n=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,f=a(e=>{if(typeof n<"u"&&n.versions&&n.versions.node){const[t,s]=n.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return n.getBuiltinModule(e)}return u(e)},"__cjs_getBuiltinModule"),{stripVTControlCharacters:h,format:m}=f("node:util");var S=Object.defineProperty,o=a((e,t)=>S(e,"name",{value:t,configurable:!0}),"r");const p=o(e=>{const t=h(e);return{ansi:e,json:JSON.stringify(e),lengthDifference:e.length-t.length,stripped:t,visible:e.replaceAll("\x1B",String.raw`\u001B`)}},"formatAnsiString"),j=o((e,t)=>{const s=p(e),i=p(t);return{message:o(()=>{if(e===t)return"ANSI strings are identical";const r=s.stripped===i.stripped;return m(`ANSI string comparison failed: Actual: - Visible content: %s - With escape codes: %s - JSON: %s - Length: %d Expected: - Visible content: %s - With escape codes: %s - JSON: %s - Length: %d %s `,s.stripped,s.visible,s.json,l(s.ansi),i.stripped,i.visible,i.json,l(i.ansi),r?"✓ Visible content is identical, but escape codes differ":"✗ Visible content differs")},"message"),pass:e===t}},"expectAnsiStrings"),v=o((e,t)=>{const s=p(e),i=p(t),r=s.stripped===i.stripped,c=e===t;return{actual:s,ansiEqual:c,expected:i,strippedEqual:r,summary:{actualLength:e.length,actualStrippedLength:s.stripped.length,ansiEqual:c,expectedLength:t.length,expectedStrippedLength:i.stripped.length,strippedEqual:r}}},"compareAnsiStrings");export{v as compareAnsiStrings,j as expectAnsiStrings,p as formatAnsiString};