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

find

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find - npm Package Compare versions

Comparing version 0.2.9 to 0.3.0

62

index.js

@@ -19,2 +19,3 @@ var fs = require('fs');

// dirSync: function([pat,] root) {}
// use:: function(options) {}

@@ -49,3 +50,3 @@ };

function existed(name) {
return fs.existsSync(name)
return fs.existsSync(name);
}

@@ -55,5 +56,10 @@ function fsType(type) {

try {
return fs.lstatSync(name)['is' + type]()
} catch(e) {
fss.errorHandler(e);
return fs.lstatSync(name)['is' + type]();
} catch(err) {
if (!/^(EPERM|EACCES)$/.test(err.code)) {
fss.errorHandler(err);
}
else {
console.warn('Warning: Cannot access %s', name);
}
}

@@ -64,2 +70,5 @@ }

return function(input) {
if (type === 'Function') {
return typeof input === 'function';
}
return ({}).toString.call(input) === '[object ' + type + ']';

@@ -85,4 +94,4 @@ }

['readdir', 'lstat'].forEach(function(method) {
var origin = fs[method];
fss[method] = function(path, callback) {
var origin = fs[method];
return origin.apply(fs, [path, function(err) {

@@ -109,7 +118,10 @@ fss.errorHandler(err);

fs.realpath(name, function(err, origin) {
if (err && /(ENOENT|ELOOP)/.test(err.code)) {
if (err && /^(ENOENT|ELOOP|EPERM|EACCES)$/.test(err.code)) {
fn(name);
} else {
fss.errorHandler(err);
fss.readlink(origin, fn, --depth);
if (err) {
fss.errorHandler(err);
} else {
fss.readlink(origin, fn, --depth);
}
}

@@ -135,4 +147,7 @@ });

} catch (err) {
if (/(ENOENT|ELOOP)/.test(err.code)) return name;
else fss.errorHandler(err);
if (/^(ENOENT|ELOOP|EPERM|EACCES)$/.test(err.code)) {
return name;
} else {
fss.errorHandler(err);
}
}

@@ -391,1 +406,28 @@ return fss.readlinkSync(origin, --depth);

var fsMethods = [
'existsSync',
'lstatSync',
'realpath',
'realpathSync',
'readdir',
'readdirSync'
];
/**
* Configuations for internal usage
*
* @param {Object} options
* @api public
*/
find.use = function(options) {
if (options && options.fs) {
if (fsMethods.every(n => !!options.fs[n])) {
fs = options.fs;
} else {
throw new Error('The provided fs object is not compatiable with native fs.');
}
}
return find;
}

6

package.json
{
"name": "find",
"version": "0.2.9",
"version": "0.3.0",
"description": "Find files or directories by name",

@@ -12,4 +12,4 @@ "url": "https://github.com/yuanchuan/find",

"devDependencies": {
"mocha": "^2.2.4",
"tmp": "^0.0.25"
"mocha": "^6.0.2",
"tmp": "^0.0.33"
},

@@ -16,0 +16,0 @@ "keywords": [

@@ -39,5 +39,8 @@ # find [![Status](https://travis-ci.org/yuanchuan/find.svg?branch=master)](https://travis-ci.org/yuanchuan/find "See test builds")

## Changelog
#### 0.3.0
* Added `.use()` method
#### 0.2.0
* the first `pattern` option is now optional
* will follow symbolic links
* The first `pattern` option is now optional
* Will follow symbolic links

@@ -118,1 +121,19 @@

```
#### .use(Options)
* `fs`: The internal fs object to be used.
```javascript
const { fs, vol } = require('memfs');
const json = {
'./README.md': '1',
'./src/index.js': '2'
};
vol.fromJSON(json, '/app');
find
.use({ fs: fs })
.file('/app', console.log);
```

@@ -14,3 +14,3 @@ var fs = require('fs');

if (Array.isArray(dir)) dir = dir[0];
var opts = { template: dir + '/tmp-XXXXXX' + (ext || '') };
var opts = { template: path.join(dir, '/tmp-XXXXXX' + (ext || '')) };
for (var i = 0; i < num; ++i) {

@@ -23,2 +23,7 @@ targets.push(tmp[type + 'Sync'](opts).name);

function assertEqual(a, b) {
assert.deepEqual(a.sort(), b.sort());
}
var createFilesUnder = createBy('file');

@@ -35,6 +40,2 @@ var createDirUnder = createBy('dir');

function assertEqual(arra, arrb) {
return assert.equal(arra.sort().join(''), arrb.sort().join(''));
}
describe('API test', function() {

@@ -134,10 +135,2 @@ var testdir;

it('`find.*` should find by regular expression against the full path', function() {
var html = createFilesUnder(testdir, 1, '.html')[0];
var extensionless = path.join(path.dirname(html), path.basename(html, '.html'));
htmlAll = find.fileSync(new RegExp(extensionless), testdir);
assert.equal( html, htmlAll.join(''));
});
it('`find.*` should follow file symbolic links', function(done) {

@@ -261,8 +254,12 @@ var files = createFilesUnder(testdir, 2);

it('should throw exception at root which does not exist', function(done) {
var catched = false;
it('`.error()`should catch exceptions', function(done) {
var catched;
try {
find.fileSync('__not_exist');
find
.file('__not_exist', function(f) { })
.error(function(err) {
catched = true;
});
} catch(e) {
catched = true;
catched = false;
}

@@ -275,12 +272,8 @@ setTimeout(function() {

it('`.error()`should catch exceptions', function(done) {
var catched;
it('should throw exception at root which does not exist', function(done) {
var catched = false;
try {
find
.file('__not_exist', function(f) { })
.error(function(err) {
catched = true;
});
find.fileSync('__not_exist');
} catch(e) {
catched = false;
catched = true;
}

@@ -292,2 +285,3 @@ setTimeout(function() {

});
});

Sorry, the diff of this file is not supported yet

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