(args: unknown[], options: FormatOptions = {})
| 127 | } |
| 128 | |
| 129 | function baseFormat(args: unknown[], options: FormatOptions = {}): string { |
| 130 | const formatArg = (item: unknown, inspecOptions?: LoupeOptions) => { |
| 131 | if (options.prettifyObject) { |
| 132 | return stringify(item, undefined, { |
| 133 | printBasicPrototype: false, |
| 134 | escapeString: false, |
| 135 | }) |
| 136 | } |
| 137 | return inspect(item, inspecOptions) |
| 138 | } |
| 139 | |
| 140 | if (typeof args[0] !== 'string') { |
| 141 | const objects = [] |
| 142 | for (let i = 0; i < args.length; i++) { |
| 143 | objects.push(formatArg(args[i], { depth: 0, colors: false })) |
| 144 | } |
| 145 | return objects.join(' ') |
| 146 | } |
| 147 | |
| 148 | const len = args.length |
| 149 | let i = 1 |
| 150 | const template = args[0] |
| 151 | let str = String(template).replace(formatRegExp, (x) => { |
| 152 | if (x === '%%') { |
| 153 | return '%' |
| 154 | } |
| 155 | if (i >= len) { |
| 156 | return x |
| 157 | } |
| 158 | switch (x) { |
| 159 | case '%s': { |
| 160 | const value = args[i++] |
| 161 | if (typeof value === 'bigint') { |
| 162 | return `${value.toString()}n` |
| 163 | } |
| 164 | if (typeof value === 'number' && value === 0 && 1 / value < 0) { |
| 165 | return '-0' |
| 166 | } |
| 167 | if (typeof value === 'object' && value !== null) { |
| 168 | if (typeof value.toString === 'function' && value.toString !== Object.prototype.toString) { |
| 169 | return value.toString() |
| 170 | } |
| 171 | return formatArg(value, { depth: 0, colors: false }) |
| 172 | } |
| 173 | return String(value) |
| 174 | } |
| 175 | case '%d': { |
| 176 | const value = args[i++] |
| 177 | if (typeof value === 'bigint') { |
| 178 | return `${value.toString()}n` |
| 179 | } |
| 180 | if (typeof value === 'symbol') { |
| 181 | return 'NaN' |
| 182 | } |
| 183 | return Number(value).toString() |
| 184 | } |
| 185 | case '%i': { |
| 186 | const value = args[i++] |
no test coverage detected