+5
-0
@@ -5,2 +5,7 @@ # noda Change Log | ||
| ## [0.3.0] - Feb 21st, 2018 | ||
| * `noda.inReaddir()` added. | ||
| * `noda.nextRead()` added. | ||
| ## [0.2.0] - Feb 1st, 2018 | ||
@@ -7,0 +12,0 @@ |
+61
-0
@@ -111,2 +111,15 @@ /** | ||
| /** | ||
| * Read the contents of a directory. | ||
| * @param {string} subpath path relative to the homedir of current package | ||
| * @return {string[]} | ||
| */ | ||
| let inReaddir = function(subpath) { | ||
| // Find home directory of the package in which the caller is located. | ||
| let dirname = getCallerPackageDir(); | ||
| let pathname = path.join(dirname, subpath); | ||
| return fs.readdirSync(pathname); | ||
| }; | ||
| /** | ||
| * To require some sub module in same package with fixed subpath wherever the caller is located. | ||
@@ -231,2 +244,44 @@ * | ||
| /** | ||
| * Read file next to the file in which the caller is located. | ||
| * @param {string} subpath path relative to the directory of the caller file | ||
| * @param {string} [encoding] | ||
| * @param {boolean} [nullIfNotFound] | ||
| * @return {string|Buffer} | ||
| */ | ||
| let nextRead = function(subpath, encoding, nullIfNotFound) { | ||
| if (arguments.length == 3) { | ||
| // DO NOTHING. | ||
| } | ||
| else if (arguments.length == 2) { | ||
| if (typeof arguments[1] == 'boolean') { | ||
| encoding = null; | ||
| nullIfNotFound = arguments[1]; | ||
| } | ||
| else if (typeof arguments[1] == 'string') { | ||
| encoding = arguments[1]; | ||
| nullIfNotFound = false; | ||
| } | ||
| else { | ||
| throw new Error('The second argument should be a string (encoding) or boolean (nullIfNotFound) value.'); | ||
| } | ||
| } | ||
| // Find the directory of the file in which the caller is located. | ||
| let dirname = getCallerDir(); | ||
| let pathname = path.join(dirname, subpath); | ||
| let ret = null; | ||
| if (!fs.existsSync(pathname)) { | ||
| if (!nullIfNotFound) { | ||
| throw new Error(`File not found: ${pathname}`); | ||
| } | ||
| } | ||
| else { | ||
| ret = fs.readFileSync(pathname, encoding); | ||
| } | ||
| return ret; | ||
| } | ||
| /** | ||
| * Find sub-directory or file in ascent directory and return the full path. | ||
@@ -291,9 +346,15 @@ * @param {string} pathname relative pathname of sub-directory or file | ||
| inRead, | ||
| inReaddir, | ||
| inRequire, | ||
| inRequireDir, | ||
| inResolve, | ||
| nextRead, | ||
| osRequire, | ||
| requireDir, | ||
| upResolve, | ||
| downResolve, | ||
| 'existsInPackage': inExists, | ||
@@ -300,0 +361,0 @@ 'readInPackage': inRead, |
+1
-1
| { | ||
| "name": "noda", | ||
| "version": "0.2.0", | ||
| "version": "0.3.0", | ||
| "description": "NOde Developing Assistant", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+11
-2
| # noda | ||
| __NOde Developing Assistant__ | ||
| __noda__ is a very lower-level package which will help you easily accessing files and directories in your package. | ||
| __noda__ is a very lower-level package which will help you easily accessing files and directories in your package or adjacent to your Node.js file. | ||
@@ -38,3 +38,6 @@ ## Table of contents | ||
| 1. The phrase "current package" refers to the NPM package which contains the nodejs file where code `noda.*` located. | ||
| 2. Parameter `subpath` refers to pathname relative to the basepath of "current package". | ||
| 1. Parameter `subpath` refers to pathname relative to the basepath of "current package". | ||
| 1. Because all functions are synchronous, postfix `Sync` is omitted. | ||
| 1. For functions with name prefixed with preposition *in*, the scope is "current package". E.g. `noda.inRead()` will read a file in current package. | ||
| 1. For functions with name prefixed with preposition *next*, *up* and *down*, the scope is "current file". E.g. `noda.nextRead()` will read a file adjacent to current file. | ||
@@ -51,2 +54,5 @@ * __noda.currentPackage__() | ||
| * __noda.inReaddir__(string *subpath*) | ||
| Read the contents of a directory. | ||
| * __noda.inRequire__(string *subpath*) | ||
@@ -62,2 +68,5 @@ Require js or json. | ||
| * __noda.nextRead__(string *subpath* [, string *encoding*, boolean *nullIfNotFound* ]) | ||
| Read content of file. | ||
| * __noda.osRequire__(string *dirname*) | ||
@@ -64,0 +73,0 @@ Require module whose name is same with the name of current platform. Relative __dirname__ is acceptable. |
Sorry, the diff of this file is not supported yet
19566
13.39%412
14.13%128
7.56%7
-12.5%