| 171 | * falls back to util.inspect if there's an error (circular reference) |
| 172 | */ |
| 173 | export function ejson(strings: TemplateStringsArray, ...values: any[]) { |
| 174 | const stringParts = [strings[0]]; |
| 175 | for (const [idx, value] of values.entries()) { |
| 176 | if (typeof value === 'object') { |
| 177 | let stringifiedObject: string; |
| 178 | try { |
| 179 | stringifiedObject = EJSON.stringify(value, { relaxed: false }); |
| 180 | } catch { |
| 181 | stringifiedObject = inspect(value, { |
| 182 | depth: Infinity, |
| 183 | showHidden: true, |
| 184 | compact: true |
| 185 | }); |
| 186 | } |
| 187 | stringParts.push(stringifiedObject); |
| 188 | } else { |
| 189 | stringParts.push(String(value)); |
| 190 | } |
| 191 | stringParts.push(strings[idx + 1]); |
| 192 | } |
| 193 | |
| 194 | return stringParts.join(''); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Run an async function after some set timeout |