nim
Node.js command-line tool for inspecting objects, function implementations and listing properties, with syntax highlighting.
Why
If you're like me, you regularly boot up node's REPL just to explore
objects or gain insight on how things work by logging function
implementations. nim
is a slightly more convenient way of doing this.
$ nim pathjoin { var paths = Arrayprototypeslice; return exports;}
Installation
$ npm install -g nim
Usage
Usage: nim [options]
Options:
-h, --help output usage information
-V, --version output the version number
--color Coloured output
--repl Start a REPL
Examples:
nim - List Global Properties
nim process - Inspect Global Properties
nim os - Inspect Core Modules
nim process.versions - Inspect Properties
nim express - Inspect Local Packages
nim "crypto.getCiphers()" - Inspect Simple Function Calls
nim stream. - List Available Properties
nim stream . - List Prototype Properties
Inspect Global Variables
$ nim process title: 'node' version: 'v0.10.24' argv: 'node' '/usr/local/bin/nim' 'process' ...
Inspect Properties
$ nim processversions http_parser: '1.0' node: '0.10.29' v8: '3.14.5.9' ares: '1.9.0-DEV' uv: '0.10.27' zlib: '1.2.3' modules: '11' openssl: '1.0.1h'
Inspect Core Modules
$ nim os endianness: Function hostname: Function loadavg: Function uptime: Function freemem: Function totalmem: Function cpus: Function type: Function release: Function networkInterfaces: Function arch: Function platform: Function tmpdir: Function tmpDir: Function getNetworkInterfaces: Function: deprecated EOL: '\n'
Inspect Local Packages
nim
will try load the appropriate package using regular local package resolution.
$ nim express { var { app; }; ; ; apprequest = __proto__: req app: app ; appresponse = __proto__: res app: app ; app; return app;}
$ nim express nim express expressconstructorexpresstoStringexpresstoLocaleStringexpressvalueOfexpresshasOwnPropertyexpressisPrototypeOfexpresspropertyIsEnumerableexpress__defineGetter__express__lookupGetter__express__defineSetter__express__lookupSetter__ expresslengthexpressnameexpressargumentsexpresscallerexpressconstructorexpressbindexpresstoStringexpresscallexpressapply expresslengthexpressnameexpressargumentsexpresscallerexpressprototypeexpressapplicationexpressrequestexpressresponseexpressRouteexpressRouterexpressqueryexpressstaticexpressjsonexpressurlencodedexpressbodyParserexpresscompressexpresscookieSessionexpresssessionexpressloggerexpresscookieParserexpressfaviconexpressresponseTimeexpresserrorHandlerexpresstimeoutexpressmethodOverrideexpressvhostexpresscsrfexpressdirectoryexpresslimitexpressmultipartexpressstaticCache
Inspect Simple Function Calls
Remember to escape parens or wrap the expression in quotes.
$ nim "crypto.getCiphers()" 'CAST-cbc' 'aes-128-cbc' 'aes-128-cbc-hmac-sha1' ... 'seed-cfb' 'seed-ecb' 'seed-ofb'
This is similar to the result you'd get from node -p "require('crypto').getCiphers()"
with added syntax highlighting.
List Available Properties
You can list properties of an object by appending a .
to the name of
the object you want to inspect. This lists all the properties of the
current object and each object in its prototype chain.
$ nim stream streamconstructorstreamtoStringstreamtoLocaleStringstreamvalueOfstreamhasOwnPropertystreamisPrototypeOfstreampropertyIsEnumerablestream__defineGetter__stream__lookupGetter__stream__defineSetter__stream__lookupSetter__ streamlengthstreamnamestreamargumentsstreamcallerstreamconstructorstreambindstreamtoStringstreamcallstreamapply streamlengthstreamnamestreamargumentsstreamcallerstreamprototypestreamsuper_streamReadablestreamWritablestreamDuplexstreamTransformstreamPassThroughstreamStream
List Prototype Properties
For example, listing the properties on stream.prototype
:
$ nim stream streamprototypeconstructorstreamprototypetoStringstreamprototypetoLocaleStringstreamprototypevalueOfstreamprototypehasOwnPropertystreamprototypeisPrototypeOfstreamprototypepropertyIsEnumerablestreamprototype__defineGetter__streamprototype__lookupGetter__streamprototype__defineSetter__streamprototype__lookupSetter__ streamprototypeconstructorstreamprototypesetMaxListenersstreamprototypeemitstreamprototypeaddListenerstreamprototypeonstreamprototypeoncestreamprototyperemoveListenerstreamprototyperemoveAllListenersstreamprototypelisteners streamprototypeconstructorstreamprototypepipe
The above is a convenience syntax and exactly equivalent to inspecting the prototype with .
directly:
$ nim streamprototype streamprototypeconstructorstreamprototypetoStringstreamprototypetoLocaleStringstreamprototypevalueOfstreamprototypehasOwnPropertystreamprototypeisPrototypeOfstreamprototypepropertyIsEnumerablestreamprototype__defineGetter__streamprototype__lookupGetter__streamprototype__defineSetter__streamprototype__lookupSetter__ streamprototypeconstructorstreamprototypesetMaxListenersstreamprototypeemitstreamprototypeaddListenerstreamprototypeonstreamprototypeoncestreamprototyperemoveListenerstreamprototyperemoveAllListenersstreamprototypelisteners streamprototypeconstructorstreamprototypepipe
Pagination
Sometimes nim
's output can be many screenfuls. Feel free to pipe nim
through your pager of choice:
e.g.
$ nim crypto | less
If your pager is having trouble displaying colorcodes, pass it the -r
flag:
$ nim crypto | less -r$ nim crypto | more -r
REPL
Save on keystrokes when issuing multiple nim
commands!
$ nim --repl
nim> path
{
resolve: [Function],
normalize: [Function],
join: [Function],
relative: [Function],
sep: '/',
delimiter: ':',
dirname: [Function],
basename: [Function],
extname: [Function],
exists: [Function: deprecated],
existsSync: [Function: deprecated],
_makeLong: [Function]
}
nim> url
{
parse: [Function: urlParse],
resolve: [Function: urlResolve],
resolveObject: [Function: urlResolveObject],
format: [Function: urlFormat],
Url: [Function: Url]
}
nim>
TODO
- --Better formatting for property listings. Make more like obj. completion in repl.--
- Add tests.
- Auto-completion on
.
. - More intuitive syntax for telling nim to list properties?
- Opt in (or out) of printing a flattened property list (i.e. do not display which level of the prototype hierarchy a property is implemented on)
- Maybe support running against a custom scope from inside a paused execution context saved to disk?
License
MIT