New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fspkg

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fspkg - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

bin/fspkg

16

lib/builder.js

@@ -19,7 +19,21 @@ var fs = require('fs');

* Creates an instance of `Builder` with the given options.
*
* **Options**
*
* - format (String): The output format (module, json or object)
* - filter (String|Function): Filter function or comma-separated
* string of file extensions.
**/
function Builder(options) {
options = options || {};
options.filter = options.filter || filter.Default;
options.format = options.format || 'module';
if (options.filter) {
if (Object.prototype.toString.call(options.filter) === '[object String]') {
options.filter = filter.createExtensionFilter(options.filter);
}
} else {
options.filter = filter.Default;
}
this.options = options;

@@ -26,0 +40,0 @@ }

31

lib/filter.js

@@ -0,1 +1,14 @@

var createExtensionFilter = function(extensions) {
extensions = extensions.replace(/ ?, ?/g, '|');
var regex = new RegExp('\\w\\.(' + extensions + ')$', "i");
return function(path) {
return path
// include files of specified type
&& regex.test(path)
// exclude anything in a .git or node_modules directory
&& path.match(/\/(\.git|node_modules)\//) === null;
};
};
/**

@@ -6,2 +19,10 @@ * namespace Filter

/**
* Filter.createExtensionFilter(extensions) -> Function
* - extensions (String): Comma-separated list of file extensions
*
* Returns a function which filters paths by file extensions
**/
createExtensionFilter: createExtensionFilter,
/**
* Filter.Default(path) -> Boolean

@@ -12,10 +33,4 @@ * - path (String): The path to be tested.

**/
Default: function(path) {
// path must be given...
return path
// include files of type mustache, html, htm, txt
&& path.match(/\w\.(mustache|html|htm|txt)$/i)
// exclude anything in a .git or node_modules directory
&& path.match(/\/(\.git|node_modules)\//) === null;
}
Default: createExtensionFilter('mustache,html,htm,txt')
};

@@ -19,7 +19,21 @@ var fs = require('fs');

* Creates an instance of `SyncBuilder` with the given options.
*
* **Options**
*
* - format (String): The output format (module, json or object)
* - filter (String|Function): Filter function or comma-separated
* string of file extensions.
**/
function SyncBuilder(options) {
options = options || {};
options.filter = options.filter || filter.Default;
options.format = options.format || 'module';
if (options.filter) {
if (Object.prototype.toString.call(options.filter) === '[object String]') {
options.filter = filter.createExtensionFilter(options.filter);
}
} else {
options.filter = filter.Default;
}
this.options = options;

@@ -26,0 +40,0 @@ }

@@ -6,3 +6,3 @@ {

"tags" : ["json", "fs", "file", "fileify", "datauri", "mustache", "commonjs"],
"version": "0.1.0",
"version": "0.2.0",
"homepage": "https://github.com/dandean/fspkg",

@@ -14,2 +14,3 @@ "repository": {

"main": "main",
"bin" : { "fspkg" : "./bin/fspkg" },
"scripts": {

@@ -22,3 +23,4 @@ "test": "make test"

"dependencies": {
"mime": "*"
"mime": "*",
"commander": "*"
},

@@ -25,0 +27,0 @@ "devDependencies": {

@@ -23,6 +23,20 @@ fspkg: File System Packager

Command-line API
----------------
API
---
```sh
Usage: fspkg [options] <source>
Options:
-h, --help output usage information
-V, --version output the version number
-s, --save-path [savePath] save path: prints to stdout if not given
-e, --extensions [extensions] file extensions to include in the package; default is "mustache,html,htm,txt"
```
Node.js API
-----------
`fspkg` exposes both async and sync API's.

@@ -33,3 +47,3 @@

The module export is a shortcut to instantiating a new `Builder` and immediately
its `build` method, packaging the file-system at `path`.
calling its `build` method, packaging the file-system at `path`.

@@ -71,9 +85,13 @@ ```text

* filter (Function(String path)): A function which filters file paths found in the
directory to be packaged. Should return `true` to include the file, `false` to
exclude it. Defaults to `fspkg.Filter.Default` when `filter` option is not
provided.
* filter (Function|String): A function or string which filters file paths
found in the directory to be packaged.
If a `String`, it should be a comma-separated list of file extensions,
such as "foo,bar,baz". If a `Function`, should return `true` to include
the file, `false` to exclude it.
Defaults to "mustache,html,htm,txt".
* format (String): The format to return from the `build` method:
"module", "json" or "object". Defaults to "module";
"module", "json" or "object". Defaults to "module";

@@ -111,9 +129,13 @@

* filter (Function(String path)): A function which filters file paths found in the
directory to be packaged. Should return `true` to include the file, `false` to
exclude it. Defaults to `fspkg.Filter.Default` when `filter` option is not
provided.
* filter (Function|String): A function or string which filters file paths
found in the directory to be packaged.
If a `String`, it should be a comma-separated list of file extensions,
such as "foo,bar,baz". If a `Function`, should return `true` to include
the file, `false` to exclude it.
Defaults to "mustache,html,htm,txt".
* format (String): The format to return from the `build` method:
"module", "json" or "object". Defaults to "module";
"module", "json" or "object". Defaults to "module";

@@ -189,4 +211,6 @@

To install the command-line utility, add the `-g` flag during installation.
License

@@ -193,0 +217,0 @@ -------

@@ -44,11 +44,11 @@ var fs = require('fs');

it('should should have a `Builder` property which is a function', function(){
it('should have a `Builder` property which is a function', function(){
assert.ok(fspkg.Builder instanceof Function);
});
it('should should have a `SyncBuilder` property which is a function', function(){
it('should have a `SyncBuilder` property which is a function', function(){
assert.ok(fspkg.SyncBuilder instanceof Function);
});
it('should should have a `Filter` property', function(){
it('should have a `Filter` property', function(){
assert.ok('Filter' in fspkg);

@@ -69,3 +69,3 @@ });

it('should should include "html", "htm", "mustache" and "txt" files by default', function() {
it('should include "html", "htm", "mustache" and "txt" files by default', function() {
// console.log(result, Object.keys(result), Object.keys(result).length);

@@ -140,3 +140,3 @@ var count = Object.keys(result).length;

it('should should include "html", "htm", "mustache" and "txt" files by default', function() {
it('should include "html", "htm", "mustache" and "txt" files by default', function() {
var count = Object.keys(result1).length;

@@ -143,0 +143,0 @@ assert.equal(5, count, 'Should have found 5 files but found ' + count);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc