node-em
The em
extends few core NodeJS modules with
simpler object oriented interface and immutable objects.
em.URL
extends Node's core url moduleem.Path
extends Node's core path module
Installation
It can be installed directly from NPM:
npm install em
License
Open source, MIT-style license.
Examples
URL
You can create instances of URL
by calling URL.create(path)
or
new URL(path)
.
However URL.create()
only creates new objects when it must. For
example when called with an another instance of URL
it can simply
return it since it's immutable and cannot be changed.
Each method of URL
returns an another URL object so you can chain its
methods:
var url = URL ;console;
One of the coolest features of URL
is that parsing can be done just
in time on demand. In the previous example the URL wasn't parsed until
you requested url.href
! However if you need you can call
url.parse()
and get a real object with no magic members and JIT.
Path
The Path
works the same way.
You can create objects by calling Path.create('/foo/bar')
or
new Path('/foo/bar')
. Paths are immutable, too.
var path = Path;console; // Returns '/foo/bar/docroot'console; // Returns 'index'
Further examples
At the moment for further details please take a look at tests.