MCPcopy Create free account
hub / github.com/denoland/std / getEscapedString

Function getEscapedString

csv/stringify.ts:130–144  ·  view source on GitHub ↗
(value: unknown, sep: string)

Source from the content-addressed store, hash-verified

128const BYTE_ORDER_MARK = "\ufeff";
129
130function getEscapedString(value: unknown, sep: string): string {
131 if (value === undefined || value === null) return "";
132 let str = "";
133
134 if (typeof value === "object") str = JSON.stringify(value);
135 else str = String(value);
136
137 // Is regex.test more performant here? If so, how to dynamically create?
138 // https://stackoverflow.com/questions/3561493/
139 if (str.includes(sep) || str.includes(LF) || str.includes(QUOTE)) {
140 return `${QUOTE}${str.replaceAll(QUOTE, `${QUOTE}${QUOTE}`)}${QUOTE}`;
141 }
142
143 return str;
144}
145
146type NormalizedColumn = Omit<ColumnDetails, "header" | "prop"> & {
147 header: string;

Callers 1

stringifyFunction · 0.85

Calls 2

stringifyMethod · 0.80
includesMethod · 0.80

Tested by

no test coverage detected