nsole
Version:
A drop-in isomorphic console.* replacement that's pretty, small, fast, and flexible
26 lines (23 loc) • 2.61 kB
TypeScript
/** @about
@desc: the super slim version; no plugin or global PTAG_* logic, but same api/struc
@size: 865 bytes; about half the size of the default; a-whole-lot of bang for the byte
@minified copy-n-paste -> plug-n-play
let slim=(M,I,N,V,E,R='_id',z='_def',F='_lvl',O=N??{},Z=[3,'?','#D6D'],J={debug:[5,'>','#89A'],log:[4,'>','#2AE'],info:[4,'i','#1AA'],check:Z,warn:[2,'!','#F77'],error:[1,'X','#F36'],_fg:O._fg??'#000',_dl:O._dl??['',':',':'],_css:O._css??[' ',' ',' ',' ','color:^;']},K=(q,j=J)=>({...j,...q??J}),G=()=>{},B=console)=>new Proxy({[R]:M??'{}',[z]:K(),[F]:I??5},{get:(q,j)=>{let g=q[z]??J,f=g[j],l=~~q[F],e=j==F||j==R||j==z?q[j]:l&&(-1==l||!f&&j in B)?B[j]??B.log:!l||f?.[0]>l?G:null;if(!e&&(q[j]??G)===G){q[z]=f?g:K({[j]:Z},g);let l=''==g._fg,[,e,c,r,_]=q[z][j],[o,n,s]=g._dl.map(C=>l?C:`%c${C}%c`);q[j]=(B[_??j]??B.log).bind(B,o+e+n+q[R]?.replace('{}',j)+s,...l?[]:g._css.concat('').map(C=>C&&((g._css[4]??'')+C).replace(/\^+/g,T=>'^'==T?r??c:'^^'==T?r??g._fg:c)))}return e||q[j]},set:(q,j,w)=>{q[j]=j==F?w??I:j==R?w??M:K(w,q[z]);for(let j in q[z])q[j]=G;return!0}});
slim().log('slim')
slim().debug('it');
slim().check('down');
*** */
import type { ColorSpace, Definitions, DefinitionsD, DefinitionsDP, LogFn, PluginFn, PtagInstance } from './types.ts';
/**
* slim ptag logger; no plugin or global PTAG_* logic, but same api/struc
* @template M - custom log method names (otherwise ptag infers/handles automatically from def)
* @param {string} [id='{}'] - (id)entifier tag/text with '{}' method placeholder
* @param {L} [level=5] - log visibility threshold (-1=native, 0=silent, 1-5=verbosity)
* @param {Definitions<M>} [definitions] - method definitions & styling overrides
* @param {PluginFn<M>} [pluginFn] - log transformation/interception plugin
* @param {ColorSpace} [colorSpace=1] - color space/support (0-1=on/off, -neg=same + disables-cache)
* @returns {PtagInstance} configured ptag (ProxyConstructor) instance
*/
export declare const slim: <M extends string = never>(id?: null | string, level?: null | number, definitions?: null | Definitions<M>, _pluginFn?: null | PluginFn<M>, _colorSpace?: null | ColorSpace, i?: "_id", s?: "_def", l?: "_lvl", dstyle?: Definitions<M>, check?: [number, string, string], _defs?: DefinitionsD<M>, setStyle?: (value?: null | DefinitionsDP, dvalue?: DefinitionsD) => DefinitionsD, lnoop?: LogFn, gconsole?: Console) => PtagInstance<M>;
export default slim;
//# sourceMappingURL=slim.d.ts.map