lz-node-utils
Advanced tools
Comparing version 0.1.8 to 0.1.9
@@ -8,4 +8,5 @@ module.exports = { | ||
'lib/**/*.js', | ||
'test/**/*.js' | ||
] | ||
} | ||
}; |
@@ -9,4 +9,5 @@ module.exports = ( function() { | ||
ucwords: require( './ucwords' ), | ||
_deepExtend: require( './deepExtend' ) | ||
_deepExtend: require( './deepExtend' ), | ||
expandSourceFiles: require( './expandSourceFiles' ) | ||
}; | ||
}() ); |
{ | ||
"name": "lz-node-utils", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Useful utility functions for node.", | ||
@@ -12,5 +12,7 @@ "main": "lib/util.js", | ||
"underscore": "^1.7.0", | ||
"yaml-front-matter": "lzilioli/js-yaml-front-matter#182516d" | ||
"yaml-front-matter": "git+https://github.com/lzilioli/js-yaml-front-matter#182516d" | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.10.0", | ||
"comparejs": "^0.1.2", | ||
"grunt": "^0.4.5", | ||
@@ -20,4 +22,7 @@ "grunt-contrib-jshint": "^0.10.0", | ||
"grunt-jsbeautifier": "^0.2.7", | ||
"grunt-release": "^0.9.0", | ||
"grunt-shell": "^1.1.1", | ||
"jshint-stylish": "^1.0.0", | ||
"load-grunt-config": "^0.16.0", | ||
"mocha": "^2.0.1", | ||
"shelljs": "^0.3.0" | ||
@@ -33,3 +38,7 @@ }, | ||
}, | ||
"homepage": "https://github.com/lzilioli/lz-node-utils" | ||
"homepage": "https://github.com/lzilioli/lz-node-utils", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha --reporter spec test/test.js" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -9,3 +9,3 @@ lz-node-utils | ||
```bash | ||
npm install --save-dev git+http://git@github.com/lzilioli/lz-node-utils.git | ||
npm install --save lz-node-utils | ||
``` | ||
@@ -23,2 +23,4 @@ | ||
**THEY ARE ALL SYNCHRONOUS** | ||
- `file.expand` | ||
@@ -32,4 +34,18 @@ - `file.expandMapping` | ||
### `util.reqfn(rootDir)` | ||
### `util.pth` | ||
Like path.join, but returns an absolute path to the referenced location. | ||
```javascript | ||
util.pth('grunt/config/file.json'); // returns /path/to/repo/grunt/config/file.json | ||
util.pth('grunt', 'config', 'file.json'); // also returns /path/to/repo/grunt/config/file.json | ||
util.pth('grunt/', '/config', '//', '/file.json'); // also returns /path/to/repo/grunt/config/file.json | ||
``` | ||
**Disclaimer** | ||
The absolute path returned is determined by prepending `process.cwd()` to the arguments that are passed to the function, and passing the result to `path.join()`. This is known to be effective for locally developed node applications, but has not been tested in a server environment, for globally installed npm modules, or in a Dockerized environment. Use at your own risk, but also if you run into an issue, let me know. I'd like this to be more versitle. | ||
### `util.getReqfn(rootDir)` | ||
Returns a function that, when called, will require a module relative to `rootDir`. | ||
@@ -49,12 +65,10 @@ | ||
### `util.pth` | ||
**Note** | ||
Like path.join, but returns an absolute path to the referenced location. | ||
This function relies on `util.path()` under the hood, so please be aware of the disclaimer (above) if using `util.getReqFn()`. | ||
```javascript | ||
util.pth('grunt/config/file.json'); // returns /path/to/repo/grunt/config/file.json | ||
util.pth('grunt', 'config', 'file.json'); // also returns /path/to/repo/grunt/config/file.json | ||
util.pth('grunt/', '/config', '//', '/file.json'); // also returns /path/to/repo/grunt/config/file.json | ||
``` | ||
### `util._deepExtend(_)` | ||
Extends the passed instance of `_` with a deepExtend function, which works like extend, but does so recursively. | ||
### `util.loadAppSettings(<defaultSettingsPath>, <userSettingsPath>)` | ||
@@ -64,2 +78,4 @@ | ||
Unlike most libraries' extend function, this works with nested settings objects. It uses the `deepExtend()` function added to underscore by `util._deepExtend()` | ||
Arguments default to `config/default-settings.js` and `config/settings.js`, respectively. | ||
@@ -71,16 +87,39 @@ | ||
### `util._deepExtend(_)` | ||
### `util.expandSourceFiles(sourceFiles)` | ||
Extends the passed instance of `_` with a deepExtend function, which works like extend, but does so recursively. | ||
The **`sourceFiles`** argument should be an object containing key/value pairs, where each value specifies a set of files associated with the given key. | ||
You can specify values in 1 of 3 ways: | ||
# Version History | ||
1. string - `'templates/**/*.tmpl'` | ||
2. array - `[ 'templates/**/*.tmpl', 'templates/**/*.handlebars' ]` | ||
3. object - This will be converted to an array of string (argument type 2), where each value corresponds to a value in src with cwd prepended to it. | ||
```javascript | ||
{ | ||
cwd: 'templates/', | ||
src: '**\/*.tmpl' // can also be an array | ||
} | ||
``` | ||
- v0.1.0 - Initial release | ||
- v0.1.1 - added `util.reqFn`, `util.pth`, and `util.loadAppSettings` | ||
- v0.1.2 - added `util.stripYamlFront` | ||
- v0.1.4 - added `util.ucwords` | ||
- v0.1.5 - added `util._deepExtend` | ||
- v0.1.6 - `util.loadAppSettings` now behaves as expected with nested objects | ||
- v0.1.7 ~~upgrade to latest `yaml-front-matter` (with my [pull request](https://github.com/dworthen/js-yaml-front-matter/pull/1)!)~~ | ||
- v0.1.8 Use my fork of `js-yaml-front-matter`, which npm installs cleanly. | ||
This argumt ultimately gets passed to `util.file.expand()` to build out a list of existing files that match the passed argument. | ||
Each key in sourceFiles will be converted to an object of the form: | ||
```javascript | ||
{ contents: <file contents>, | ||
path: <relative path to file from cwd>, | ||
fqp: <fully qualified path to file> | ||
} | ||
``` | ||
**Example** | ||
```javascript | ||
// if in templates/ directory you have template1.tmpl and template2.tmpl | ||
util.expandSourceFiles({ | ||
templates: [ 'templates/**/*.tmpl' ] | ||
}); | ||
// returns [ 'templates/template1.tmpl', 'templates/template2.tmpl' ] | ||
``` | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable and can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
27746
29
595
120
0
12