feat: refactoring project

This commit is contained in:
Carlos
2024-11-23 14:56:07 -05:00
parent f0c2a50c18
commit 1c6db5818d
2351 changed files with 39323 additions and 60326 deletions

332
node_modules/find-up/index.d.ts generated vendored
View File

@@ -1,137 +1,247 @@
import {Options as LocatePathOptions} from 'locate-path';
import {type Options as LocatePathOptions} from 'locate-path';
declare const stop: unique symbol;
/**
Return this in a `matcher` function to stop the search and force `findUp` to immediately return `undefined`.
*/
export const findUpStop: unique symbol;
declare namespace findUp {
interface Options extends LocatePathOptions {}
export type Match = string | typeof findUpStop | undefined;
type StopSymbol = typeof stop;
type Match = string | StopSymbol | undefined;
}
declare const findUp: {
export type Options = {
/**
Find a file or directory by walking up parent directories.
A directory path where the search halts if no matches are found before reaching this point.
@param name - Name of the file or directory to find. Can be multiple.
@returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
@example
```
// /
// └── Users
// └── sindresorhus
// ├── unicorn.png
// └── foo
// └── bar
// ├── baz
// └── example.js
// example.js
import findUp = require('find-up');
(async () => {
console.log(await findUp('unicorn.png'));
//=> '/Users/sindresorhus/unicorn.png'
console.log(await findUp(['rainbow.png', 'unicorn.png']));
//=> '/Users/sindresorhus/unicorn.png'
})();
```
Default: Root directory
*/
(name: string | string[], options?: findUp.Options): Promise<string | undefined>;
readonly stopAt?: string;
} & LocatePathOptions;
/**
Find a file or directory by walking up parent directories.
/**
Find a file or directory by walking up parent directories.
@param matcher - Called for each directory in the search. Return a path or `findUp.stop` to stop the search.
@returns The first path found or `undefined` if none could be found.
@param name - The name of the file or directory to find. Can be multiple.
@returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
@example
```
import path = require('path');
import findUp = require('find-up');
@example
```
// /
// └── Users
// └── sindresorhus
// ├── unicorn.png
// └── foo
// └── bar
// ├── baz
// └── example.js
(async () => {
console.log(await findUp(async directory => {
const hasUnicorns = await findUp.exists(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}, {type: 'directory'}));
//=> '/Users/sindresorhus'
})();
```
*/
(matcher: (directory: string) => (findUp.Match | Promise<findUp.Match>), options?: findUp.Options): Promise<string | undefined>;
// example.js
import {findUp} from 'find-up';
sync: {
/**
Synchronously find a file or directory by walking up parent directories.
console.log(await findUp('unicorn.png'));
//=> '/Users/sindresorhus/unicorn.png'
@param name - Name of the file or directory to find. Can be multiple.
@returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
*/
(name: string | string[], options?: findUp.Options): string | undefined;
console.log(await findUp(['rainbow.png', 'unicorn.png']));
//=> '/Users/sindresorhus/unicorn.png'
```
*/
export function findUp(name: string | readonly string[], options?: Options): Promise<string | undefined>;
/**
Synchronously find a file or directory by walking up parent directories.
/**
Find a file or directory by walking up parent directories.
@param matcher - Called for each directory in the search. Return a path or `findUp.stop` to stop the search.
@returns The first path found or `undefined` if none could be found.
@param matcher - Called for each directory in the search. Return a path or `findUpStop` to stop the search.
@returns The first path found or `undefined` if none could be found.
@example
```
import path = require('path');
import findUp = require('find-up');
@example
```
import path from 'node:path';
import {findUp, pathExists} from 'find-up';
console.log(findUp.sync(directory => {
const hasUnicorns = findUp.sync.exists(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}, {type: 'directory'}));
//=> '/Users/sindresorhus'
```
*/
(matcher: (directory: string) => findUp.Match, options?: findUp.Options): string | undefined;
console.log(await findUp(async directory => {
const hasUnicorns = await pathExists(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}, {type: 'directory'}));
//=> '/Users/sindresorhus'
```
*/
export function findUp(matcher: (directory: string) => (Match | Promise<Match>), options?: Options): Promise<string | undefined>;
/**
Synchronously check if a path exists.
/**
Synchronously find a file or directory by walking up parent directories.
@param path - Path to the file or directory.
@returns Whether the path exists.
@param name - The name of the file or directory to find. Can be multiple.
@returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
@example
```
import findUp = require('find-up');
@example
```
// /
// └── Users
// └── sindresorhus
// ├── unicorn.png
// └── foo
// └── bar
// ├── baz
// └── example.js
console.log(findUp.sync.exists('/Users/sindresorhus/unicorn.png'));
//=> true
```
*/
exists(path: string): boolean;
}
// example.js
import {findUpSync} from 'find-up';
/**
Check if a path exists.
console.log(findUpSync('unicorn.png'));
//=> '/Users/sindresorhus/unicorn.png'
@param path - Path to a file or directory.
@returns Whether the path exists.
console.log(findUpSync(['rainbow.png', 'unicorn.png']));
//=> '/Users/sindresorhus/unicorn.png'
```
*/
export function findUpSync(name: string | readonly string[], options?: Options): string | undefined;
@example
```
import findUp = require('find-up');
/**
Synchronously find a file or directory by walking up parent directories.
(async () => {
console.log(await findUp.exists('/Users/sindresorhus/unicorn.png'));
//=> true
})();
```
*/
exists(path: string): Promise<boolean>;
@param matcher - Called for each directory in the search. Return a path or `findUpStop` to stop the search.
@returns The first path found or `undefined` if none could be found.
/**
Return this in a `matcher` function to stop the search and force `findUp` to immediately return `undefined`.
*/
readonly stop: findUp.StopSymbol;
};
@example
```
import path from 'node:path';
import {findUpSync, pathExistsSync} from 'find-up';
export = findUp;
console.log(findUpSync(directory => {
const hasUnicorns = pathExistsSync(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}, {type: 'directory'}));
//=> '/Users/sindresorhus'
```
*/
export function findUpSync(matcher: (directory: string) => Match, options?: Options): string | undefined;
/**
Find files or directories by walking up parent directories.
@param name - The name of the file or directory to find. Can be multiple.
@returns All paths found (by respecting the order of `name`s) or an empty array if none could be found.
@example
```
// /
// └── Users
// └── sindresorhus
// ├── unicorn.png
// └── foo
// ├── unicorn.png
// └── bar
// ├── baz
// └── example.js
// example.js
import {findUpMultiple} from 'find-up';
console.log(await findUpMultiple('unicorn.png'));
//=> ['/Users/sindresorhus/foo/unicorn.png', '/Users/sindresorhus/unicorn.png']
console.log(await findUpMultiple(['rainbow.png', 'unicorn.png']));
//=> ['/Users/sindresorhus/foo/unicorn.png', '/Users/sindresorhus/unicorn.png']
```
*/
export function findUpMultiple(name: string | readonly string[], options?: Options): Promise<string[]>;
/**
Find files or directories by walking up parent directories.
@param matcher - Called for each directory in the search. Return a path or `findUpStop` to stop the search.
@returns All paths found or an empty array if none could be found.
@example
```
import path from 'node:path';
import {findUpMultiple, pathExists} from 'find-up';
console.log(await findUpMultiple(async directory => {
const hasUnicorns = await pathExists(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}, {type: 'directory'}));
//=> ['/Users/sindresorhus/foo', '/Users/sindresorhus']
```
*/
export function findUpMultiple(matcher: (directory: string) => (Match | Promise<Match>), options?: Options): Promise<string[]>;
/**
Synchronously find files or directories by walking up parent directories.
@param name - The name of the file or directory to find. Can be multiple.
@returns All paths found (by respecting the order of `name`s) or an empty array if none could be found.
@example
```
// /
// └── Users
// └── sindresorhus
// ├── unicorn.png
// └── foo
// ├── unicorn.png
// └── bar
// ├── baz
// └── example.js
// example.js
import {findUpMultipleSync} from 'find-up';
console.log(findUpMultipleSync('unicorn.png'));
//=> ['/Users/sindresorhus/foo/unicorn.png', '/Users/sindresorhus/unicorn.png']
console.log(findUpMultipleSync(['rainbow.png', 'unicorn.png']));
//=> ['/Users/sindresorhus/foo/unicorn.png', '/Users/sindresorhus/unicorn.png']
```
*/
export function findUpMultipleSync(name: string | readonly string[], options?: Options): string[];
/**
Synchronously find files or directories by walking up parent directories.
@param matcher - Called for each directory in the search. Return a path or `findUpStop` to stop the search.
@returns All paths found or an empty array if none could be found.
@example
```
import path from 'node:path';
import {findUpMultipleSync, pathExistsSync} from 'find-up';
console.log(findUpMultipleSync(directory => {
const hasUnicorns = pathExistsSync(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}, {type: 'directory'}));
//=> ['/Users/sindresorhus/foo', '/Users/sindresorhus']
```
*/
export function findUpMultipleSync(matcher: (directory: string) => Match, options?: Options): string[];
/**
Check if a path exists.
@param path - The path to a file or directory.
@returns Whether the path exists.
@example
```
import {pathExists} from 'find-up';
console.log(await pathExists('/Users/sindresorhus/unicorn.png'));
//=> true
```
*/
export function pathExists(path: string): Promise<boolean>;
/**
Synchronously check if a path exists.
@param path - Path to the file or directory.
@returns Whether the path exists.
@example
```
import {pathExistsSync} from 'find-up';
console.log(pathExistsSync('/Users/sindresorhus/unicorn.png'));
//=> true
```
*/
export function pathExistsSync(path: string): boolean;

74
node_modules/find-up/index.js generated vendored
View File

@@ -1,14 +1,15 @@
'use strict';
const path = require('path');
const locatePath = require('locate-path');
const pathExists = require('path-exists');
import path from 'node:path';
import {locatePath, locatePathSync} from 'locate-path';
import {toPath} from 'unicorn-magic';
const stop = Symbol('findUp.stop');
export const findUpStop = Symbol('findUpStop');
module.exports = async (name, options = {}) => {
let directory = path.resolve(options.cwd || '');
export async function findUpMultiple(name, options = {}) {
let directory = path.resolve(toPath(options.cwd) ?? '');
const {root} = path.parse(directory);
const paths = [].concat(name);
const stopAt = path.resolve(directory, toPath(options.stopAt ?? root));
const limit = options.limit ?? Number.POSITIVE_INFINITY;
const paths = [name].flat();
const runMatcher = async locateOptions => {
if (typeof name !== 'function') {
@@ -23,67 +24,84 @@ module.exports = async (name, options = {}) => {
return foundPath;
};
const matches = [];
// 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 === findUpStop) {
break;
}
if (foundPath) {
return path.resolve(directory, foundPath);
matches.push(path.resolve(directory, foundPath));
}
if (directory === root) {
return;
if (directory === stopAt || matches.length >= limit) {
break;
}
directory = path.dirname(directory);
}
};
module.exports.sync = (name, options = {}) => {
let directory = path.resolve(options.cwd || '');
return matches;
}
export function findUpMultipleSync(name, options = {}) {
let directory = path.resolve(toPath(options.cwd) ?? '');
const {root} = path.parse(directory);
const paths = [].concat(name);
const stopAt = path.resolve(directory, toPath(options.stopAt) ?? root);
const limit = options.limit ?? Number.POSITIVE_INFINITY;
const paths = [name].flat();
const runMatcher = locateOptions => {
if (typeof name !== 'function') {
return locatePath.sync(paths, locateOptions);
return locatePathSync(paths, locateOptions);
}
const foundPath = name(locateOptions.cwd);
if (typeof foundPath === 'string') {
return locatePath.sync([foundPath], locateOptions);
return locatePathSync([foundPath], locateOptions);
}
return foundPath;
};
const matches = [];
// eslint-disable-next-line no-constant-condition
while (true) {
const foundPath = runMatcher({...options, cwd: directory});
if (foundPath === stop) {
return;
if (foundPath === findUpStop) {
break;
}
if (foundPath) {
return path.resolve(directory, foundPath);
matches.push(path.resolve(directory, foundPath));
}
if (directory === root) {
return;
if (directory === stopAt || matches.length >= limit) {
break;
}
directory = path.dirname(directory);
}
};
module.exports.exists = pathExists;
return matches;
}
module.exports.sync.exists = pathExists.sync;
export async function findUp(name, options = {}) {
const matches = await findUpMultiple(name, {...options, limit: 1});
return matches[0];
}
module.exports.stop = stop;
export function findUpSync(name, options = {}) {
const matches = findUpMultipleSync(name, {...options, limit: 1});
return matches[0];
}
export {
pathExists,
pathExistsSync,
} from 'path-exists';

2
node_modules/find-up/license generated vendored
View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://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:

28
node_modules/find-up/package.json generated vendored
View File

@@ -1,16 +1,23 @@
{
"name": "find-up",
"version": "4.1.0",
"version": "7.0.0",
"description": "Find a file or directory by walking up parent directories",
"license": "MIT",
"repository": "sindresorhus/find-up",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": ">=8"
"node": ">=18"
},
"scripts": {
"test": "xo && ava && tsd"
@@ -40,14 +47,15 @@
"path"
],
"dependencies": {
"locate-path": "^5.0.0",
"path-exists": "^4.0.0"
"locate-path": "^7.2.0",
"path-exists": "^5.0.0",
"unicorn-magic": "^0.1.0"
},
"devDependencies": {
"ava": "^2.1.0",
"is-path-inside": "^2.1.0",
"tempy": "^0.3.0",
"tsd": "^0.7.3",
"xo": "^0.24.0"
"ava": "^5.3.1",
"is-path-inside": "^4.0.0",
"tempy": "^3.1.0",
"tsd": "^0.29.0",
"xo": "^0.56.0"
}
}

120
node_modules/find-up/readme.md generated vendored
View File

@@ -1,14 +1,12 @@
# find-up [![Build Status](https://travis-ci.org/sindresorhus/find-up.svg?branch=master)](https://travis-ci.org/sindresorhus/find-up)
# find-up
> Find a file or directory by walking up parent directories
## Install
```sh
npm install find-up
```
$ npm install find-up
```
## Usage
@@ -26,50 +24,65 @@ $ npm install find-up
`example.js`
```js
const path = require('path');
const findUp = require('find-up');
import path from 'node:path';
import {findUp, pathExists} from 'find-up';
(async () => {
console.log(await findUp('unicorn.png'));
//=> '/Users/sindresorhus/unicorn.png'
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(['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'
})();
console.log(await findUp(async directory => {
const hasUnicorns = await pathExists(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}, {type: 'directory'}));
//=> '/Users/sindresorhus'
```
## API
### findUp(name, options?)
### findUp(matcher, options?)
Returns a `Promise` for either the path or `undefined` if it couldn't be found.
Returns a `Promise` for either the path or `undefined` if it could not be found.
### findUp([...name], options?)
Returns a `Promise` for either the first path found (by respecting the order of the array) or `undefined` if none could be found.
### findUp.sync(name, options?)
### findUp.sync(matcher, options?)
### findUpMultiple(name, options?)
### findUpMultiple(matcher, options?)
Returns a path or `undefined` if it couldn't be found.
Returns a `Promise` for either an array of paths or an empty array if none could be found.
### findUp.sync([...name], options?)
### findUpMultiple([...name], options?)
Returns a `Promise` for either an array of the first paths found (by respecting the order of the array) or an empty array if none could be found.
### findUpSync(name, options?)
### findUpSync(matcher, options?)
Returns a path or `undefined` if it could not be found.
### findUpSync([...name], options?)
Returns the first path found (by respecting the order of the array) or `undefined` if none could be found.
### findUpMultipleSync(name, options?)
### findUpMultipleSync(matcher, options?)
Returns an array of paths or an empty array if none could be found.
### findUpMultipleSync([...name], options?)
Returns an array of the first paths found (by respecting the order of the array) or an empty array if none could be found.
#### name
Type: `string`
Name of the file or directory to find.
The name of the file or directory to find.
#### matcher
@@ -85,31 +98,38 @@ Type: `object`
##### cwd
Type: `string`<br>
Type: `URL | string`\
Default: `process.cwd()`
Directory to start from.
The directory to start from.
##### type
Type: `string`<br>
Default: `'file'`<br>
Values: `'file'` `'directory'`
Type: `string`\
Default: `'file'`\
Values: `'file' | 'directory'`
The type of paths that can match.
The type of path to match.
##### allowSymlinks
Type: `boolean`<br>
Type: `boolean`\
Default: `true`
Allow symbolic links to match if they point to the chosen path type.
### findUp.exists(path)
##### stopAt
Type: `URL | string`\
Default: Root directory
A directory path where the search halts if no matches are found before reaching this point.
### pathExists(path)
Returns a `Promise<boolean>` of whether the path exists.
### findUp.sync.exists(path)
### pathExistsSync(path)
Returns a `boolean` of whether the path exists.
@@ -117,40 +137,24 @@ Returns a `boolean` of whether the path exists.
Type: `string`
Path to a file or directory.
The path to a file or directory.
### findUp.stop
### findUpStop
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');
import path from 'node:path';
import {findUp, findUpStop} from 'find-up';
(async () => {
await findUp(directory => {
return path.basename(directory) === 'work' ? findUp.stop : 'logo.png';
});
})();
await findUp(directory => {
return path.basename(directory) === 'work' ? findUpStop : '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
- [package-up](https://github.com/sindresorhus/package-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
---
<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>