Clean up the oopsie. Rebuild the blank exercises.

This commit is contained in:
Michael Frank
2021-05-09 00:39:21 +12:00
parent b984cb4c6f
commit d28d80c46f
1565 changed files with 27186 additions and 199003 deletions
+81 -45
View File
@@ -1,53 +1,89 @@
'use strict';
var path = require('path');
var pathExists = require('path-exists');
var Promise = require('pinkie-promise');
const path = require('path');
const locatePath = require('locate-path');
const pathExists = require('path-exists');
function splitPath(x) {
return path.resolve(x || '').split(path.sep);
}
const stop = Symbol('findUp.stop');
function join(parts, filename) {
return path.resolve(parts.join(path.sep) + path.sep, filename);
}
module.exports = async (name, options = {}) => {
let directory = path.resolve(options.cwd || '');
const {root} = path.parse(directory);
const paths = [].concat(name);
module.exports = function (filename, opts) {
opts = opts || {};
var parts = splitPath(opts.cwd);
return new Promise(function (resolve) {
(function find() {
var fp = join(parts, filename);
pathExists(fp).then(function (exists) {
if (exists) {
resolve(fp);
} else if (parts.pop()) {
find();
} else {
resolve(null);
}
});
})();
});
};
module.exports.sync = function (filename, opts) {
opts = opts || {};
var parts = splitPath(opts.cwd);
var len = parts.length;
while (len--) {
var fp = join(parts, filename);
if (pathExists.sync(fp)) {
return fp;
const runMatcher = async locateOptions => {
if (typeof name !== 'function') {
return locatePath(paths, locateOptions);
}
parts.pop();
}
const foundPath = await name(locateOptions.cwd);
if (typeof foundPath === 'string') {
return locatePath([foundPath], locateOptions);
}
return null;
return foundPath;
};
// eslint-disable-next-line no-constant-condition
while (true) {
// eslint-disable-next-line no-await-in-loop
const foundPath = await runMatcher({...options, cwd: directory});
if (foundPath === stop) {
return;
}
if (foundPath) {
return path.resolve(directory, foundPath);
}
if (directory === root) {
return;
}
directory = path.dirname(directory);
}
};
module.exports.sync = (name, options = {}) => {
let directory = path.resolve(options.cwd || '');
const {root} = path.parse(directory);
const paths = [].concat(name);
const runMatcher = locateOptions => {
if (typeof name !== 'function') {
return locatePath.sync(paths, locateOptions);
}
const foundPath = name(locateOptions.cwd);
if (typeof foundPath === 'string') {
return locatePath.sync([foundPath], locateOptions);
}
return foundPath;
};
// eslint-disable-next-line no-constant-condition
while (true) {
const foundPath = runMatcher({...options, cwd: directory});
if (foundPath === stop) {
return;
}
if (foundPath) {
return path.resolve(directory, foundPath);
}
if (directory === root) {
return;
}
directory = path.dirname(directory);
}
};
module.exports.exists = pathExists;
module.exports.sync.exists = pathExists.sync;
module.exports.stop = stop;
+4 -16
View File
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+27 -22
View File
@@ -1,27 +1,30 @@
{
"_from": "find-up@^1.0.0",
"_id": "find-up@1.1.2",
"_from": "find-up@^4.1.0",
"_id": "find-up@4.1.0",
"_inBundle": false,
"_integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=",
"_integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==",
"_location": "/find-up",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "find-up@^1.0.0",
"raw": "find-up@^4.1.0",
"name": "find-up",
"escapedName": "find-up",
"rawSpec": "^1.0.0",
"rawSpec": "^4.1.0",
"saveSpec": null,
"fetchSpec": "^1.0.0"
"fetchSpec": "^4.1.0"
},
"_requiredBy": [
"/pkg-dir"
"/@istanbuljs/load-nyc-config",
"/pkg-dir",
"/read-pkg-up",
"/yargs"
],
"_resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz",
"_shasum": "6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f",
"_spec": "find-up@^1.0.0",
"_where": "/Users/cloyd/coderrr/odin/javascript-exercises/node_modules/pkg-dir",
"_resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz",
"_shasum": "97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19",
"_spec": "find-up@^4.1.0",
"_where": "/home/michael/projects/javascript-exercises/node_modules/@istanbuljs/load-nyc-config",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
@@ -32,21 +35,24 @@
},
"bundleDependencies": false,
"dependencies": {
"path-exists": "^2.0.0",
"pinkie-promise": "^2.0.0"
"locate-path": "^5.0.0",
"path-exists": "^4.0.0"
},
"deprecated": false,
"description": "Find a file by walking up parent directories",
"description": "Find a file or directory by walking up parent directories",
"devDependencies": {
"ava": "*",
"tempfile": "^1.1.1",
"xo": "*"
"ava": "^2.1.0",
"is-path-inside": "^2.1.0",
"tempy": "^0.3.0",
"tsd": "^0.7.3",
"xo": "^0.24.0"
},
"engines": {
"node": ">=0.10.0"
"node": ">=8"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"homepage": "https://github.com/sindresorhus/find-up#readme",
"keywords": [
@@ -65,7 +71,6 @@
"parents",
"folder",
"directory",
"dir",
"walk",
"walking",
"path"
@@ -77,7 +82,7 @@
"url": "git+https://github.com/sindresorhus/find-up.git"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"version": "1.1.2"
"version": "4.1.0"
}
+99 -15
View File
@@ -1,12 +1,12 @@
# find-up [![Build Status](https://travis-ci.org/sindresorhus/find-up.svg?branch=master)](https://travis-ci.org/sindresorhus/find-up)
> Find a file by walking up parent directories
> Find a file or directory by walking up parent directories
## Install
```
$ npm install --save find-up
$ npm install find-up
```
@@ -23,50 +23,134 @@ $ npm install --save find-up
└── example.js
```
`example.js`
```js
// example.js
const path = require('path');
const findUp = require('find-up');
findUp('unicorn.png').then(filepath => {
console.log(filepath);
(async () => {
console.log(await findUp('unicorn.png'));
//=> '/Users/sindresorhus/unicorn.png'
});
console.log(await findUp(['rainbow.png', 'unicorn.png']));
//=> '/Users/sindresorhus/unicorn.png'
console.log(await findUp(async directory => {
const hasUnicorns = await findUp.exists(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}, {type: 'directory'}));
//=> '/Users/sindresorhus'
})();
```
## API
### findUp(filename, [options])
### findUp(name, options?)
### findUp(matcher, options?)
Returns a promise for the filepath or `null`.
Returns a `Promise` for either the path or `undefined` if it couldn't be found.
### findUp.sync(filename, [options])
### findUp([...name], options?)
Returns a filepath or `null`.
Returns a `Promise` for either the first path found (by respecting the order of the array) or `undefined` if none could be found.
#### filename
### findUp.sync(name, options?)
### findUp.sync(matcher, options?)
Returns a path or `undefined` if it couldn't be found.
### findUp.sync([...name], options?)
Returns the first path found (by respecting the order of the array) or `undefined` if none could be found.
#### name
Type: `string`
Filename of the file to find.
Name of the file or directory to find.
#### matcher
Type: `Function`
A function that will be called with each directory until it returns a `string` with the path, which stops the search, or the root directory has been reached and nothing was found. Useful if you want to match files with certain patterns, set of permissions, or other advanced use-cases.
When using async mode, the `matcher` may optionally be an async or promise-returning function that returns the path.
#### options
Type: `object`
##### cwd
Type: `string`
Type: `string`<br>
Default: `process.cwd()`
Directory to start from.
##### type
Type: `string`<br>
Default: `'file'`<br>
Values: `'file'` `'directory'`
The type of paths that can match.
##### allowSymlinks
Type: `boolean`<br>
Default: `true`
Allow symbolic links to match if they point to the chosen path type.
### findUp.exists(path)
Returns a `Promise<boolean>` of whether the path exists.
### findUp.sync.exists(path)
Returns a `boolean` of whether the path exists.
#### path
Type: `string`
Path to a file or directory.
### findUp.stop
A [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) that can be returned by a `matcher` function to stop the search and cause `findUp` to immediately return `undefined`. Useful as a performance optimization in case the current working directory is deeply nested in the filesystem.
```js
const path = require('path');
const findUp = require('find-up');
(async () => {
await findUp(directory => {
return path.basename(directory) === 'work' ? findUp.stop : 'logo.png';
});
})();
```
## Related
- [find-up-cli](https://github.com/sindresorhus/find-up-cli) - CLI for this module
- [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file
- [pkg-dir](https://github.com/sindresorhus/pkg-dir) - Find the root directory of an npm package
- [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module like `require.resolve()` but from a given path
## License
---
MIT © [Sindre Sorhus](http://sindresorhus.com)
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-find-up?utm_source=npm-find-up&utm_medium=referral&utm_campaign=readme">Get professional support for 'find-up' with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>