swc/bundler/tests/.cache/deno/9bdac2ed843b57239c26b1ed98d19b782d97c261.ts
강동윤 1178686a4c
fix(bundler): Fix bundler (#1576)
swc_bundler:
 - Fix remapping of exports. (denoland/deno#9350)
2021-04-16 18:09:38 +00:00

56 lines
1.5 KiB
TypeScript

// Loaded from https://deno.land/x/cliffy@v0.12.1/packages/x/format.ts
// Copied from https://github.com/defunctzombie/node-util/blob/master/util.ts
// Modified to format %o and %O as deno objects
const { inspect } = Deno;
const formatRegExp = /%[sdjoO%]/g;
export default function format( ...args: any[] ) {
if ( typeof args[ 0 ] !== 'string' ) {
let objects = [];
for ( let i = 0; i < arguments.length; i++ ) {
objects.push( inspect( arguments[ i ] ) );
}
return objects.join( ' ' );
}
let i = 1;
const f = args[ 0 ];
const len = args.length;
let str = String( f ).replace( formatRegExp, function ( x ) {
if ( x === '%%' ) {
return '%';
}
if ( i >= len ) {
return x;
}
switch ( x ) {
case '%s':
return String( args[ i++ ] );
case '%d':
return String( Number( args[ i++ ] ) );
case '%j':
try {
return JSON.stringify( args[ i++ ] );
} catch ( _ ) {
return '[Circular]';
}
case '%o':
case '%O':
return inspect( args[ i++ ] );
default:
return x;
}
} );
for ( let x = args[ i ]; i < len; x = args[ ++i ] ) {
if ( x == null || typeof x !== 'object' ) {
str += ' ' + x;
} else {
str += ' ' + inspect( x );
}
}
return str;
}