mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
1178686a4c
swc_bundler: - Fix remapping of exports. (denoland/deno#9350)
56 lines
1.5 KiB
TypeScript
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;
|
|
}
|