Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 138 lines (102 sloc) 3.185 kb
0641b9fe »
2011-03-16 Update README
1 Pathname
2 ========
3
0bafac0b »
2011-03-12 Add README
4 Summary
5 -------
748124dd »
2011-03-16 Add package.json
6 OOP wrapper for `fs`, `path` and `Stat` functions.
0bafac0b »
2011-03-12 Add README
7
0641b9fe »
2011-03-16 Update README
8 Simple, clear and concise way to manipulate paths, files and directories.
0bafac0b »
2011-03-12 Add README
9 Inspired by the Ruby stdlib class of the same name.
10
11
12 Features
13 --------
14 * Unified Sync/Async API
15 * Direct mapping of core nodejs functions, so that API is consistent and intuitive
16 * Returns `this` when possible, allowing for method chaining
0641b9fe »
2011-03-16 Update README
17 * Additional convenience methods
18
19
20 Install
21 -------
e312eb22 »
2011-09-18 Update README
22 ```sh
23 $ npm install pathname
24 ```
c3224e19 »
2011-05-11 Updates README
25
26 And in your app:
27
e312eb22 »
2011-09-18 Update README
28 ```javascript
29 var Pathname = require("pathname").Pathname;
30 ```
0bafac0b »
2011-03-12 Add README
31
32
33 Examples
34 --------
35
36 ### Unified Sync/Async API
37
38 Pathname abstracts away the `funcname()` vs `funcnameSync()` distiction made in
0641b9fe »
2011-03-16 Update README
39 core nodejs `fs` functions, and substitutes it for an intuitive equivalent;
40 when called with a callback, the function is async - when called without a
41 callback, it is synchronous.
0bafac0b »
2011-03-12 Add README
42
e312eb22 »
2011-09-18 Update README
43 ```javascript
44 var path = 'tmp/foo.txt'; // contents: "bar"
0bafac0b »
2011-03-12 Add README
45
e312eb22 »
2011-09-18 Update README
46 // async
47 fs.readFile(path, function(data) {
48 data; // 'bar'
49 });
50 new Pathname(path).readFile(function (data) {
51 data; // 'bar'
52 });
0bafac0b »
2011-03-12 Add README
53
e312eb22 »
2011-09-18 Update README
54 // sync
55 fs.readFileSync(path); // 'bar'
56 new Pathname(path).readFile(); // 'bar'
57 ```
0bafac0b »
2011-03-12 Add README
58
0641b9fe »
2011-03-16 Update README
59 Notice the sync version doesn't end with `Sync`.
0bafac0b »
2011-03-12 Add README
60
61
62 ### Direct Mapping
63
64 All functions provided by the `path`, `fs` and `Stat` modules are available on
65 `Pathname`, and they all take the exact same arguments, with the exception that
c50e7ad2 »
2011-03-26 Updates docs
66 an initial path or file descriptor argument is always implicit.
0bafac0b »
2011-03-12 Add README
67
e312eb22 »
2011-09-18 Update README
68 ```javascript
69 // path functions
70 path.basename()
71 path.dirname()
72 path.extname()
73 path.exists()
74 // ...
75
76 // Stat functions
77 path.isFile()
78 path.isDirectory()
79 path.isSymbolicLink()
80 // ...
81
82 // fs functions
83 path.readFile()
84 path.writeFile(data, encoding)
85 path.watchFile()
86 path.link(dstpath)
87 path.mkdir()
88 // ...
89 ```
0bafac0b »
2011-03-12 Add README
90
91
92 ### Method Chaining
93
0641b9fe »
2011-03-16 Update README
94 Methods return `this` when no other value is expected. In async versions,
95 `this` is passed as second argument when `err` would otherwise be the only
96 expected argument. This behaviour allows for chaining of Pathname method calls.
0bafac0b »
2011-03-12 Add README
97
e312eb22 »
2011-09-18 Update README
98 ```javascript
99 // sync
100 new Pathname(__dirname ).parent().join('lib/my_module/version');
101 new Pathname('/tmp/foo').parent().siblings();
102 new Pathname('/tmp/foo').mkdir().join('bar').touch().watchFile();
103 new Pathname('/tmp/foo').writeFile('bar').readFile();
104
105 // async
106 new Pathname('/tmp/foo').mkdir(function(err, path) {
107 path.join('bar').touch(function(err, path) {
108 path.watchFile();
109 });
110 });
111 ```
0bafac0b »
2011-03-12 Add README
112
113 ### Additional Methods
114
e312eb22 »
2011-09-18 Update README
115 Pathname also provides a few extra methods, which can be quite useful. Especially interesting is the `tree()` function, which allows walking a directory tree recursively. See the
c50e7ad2 »
2011-03-26 Updates docs
116 [api docs][1] or `man pathname` for details.
0bafac0b »
2011-03-12 Add README
117
e312eb22 »
2011-09-18 Update README
118 ```javascript
119 toString(), parent(), children(), siblings(), tree(), touch(), rmR(), mkdirP(), traverse(), components()
120 ```
0bafac0b »
2011-03-12 Add README
121
0641b9fe »
2011-03-16 Update README
122
123 Links
124 -----
125 * code: <http://github.com/mynyml/pathname>
126 * docs: <http://github.com/mynyml/pathname/blob/master/README.md>
127 * wiki: <http://wiki.github.com/mynyml/pathname>
128 * bugs: <http://github.com/mynyml/pathname/issues>
129
130
f2802d22 »
2011-06-26 Updates README
131 Contributors
132 ------------
133 * [fat][2]
134 * Kenji Toyama
0641b9fe »
2011-03-16 Update README
135
136
f2802d22 »
2011-06-26 Updates README
137 [1]: https://github.com/mynyml/pathname/blob/master/doc/pathname.md
138 [2]: https://github.com/fat
0641b9fe »
2011-03-16 Update README
139
Something went wrong with that request. Please try again.