first
This commit is contained in:
22
node_modules/totalist/dist/index.js
generated
vendored
Normal file
22
node_modules/totalist/dist/index.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
const { join, resolve } = require('path');
|
||||
const { readdir, stat } = require('fs');
|
||||
const { promisify } = require('util');
|
||||
|
||||
const toStats = promisify(stat);
|
||||
const toRead = promisify(readdir);
|
||||
|
||||
module.exports = async function list(dir, callback, pre='') {
|
||||
dir = resolve('.', dir);
|
||||
await toRead(dir).then(arr => {
|
||||
return Promise.all(
|
||||
arr.map(str => {
|
||||
let abs = join(dir, str);
|
||||
return toStats(abs).then(stats => {
|
||||
return stats.isDirectory()
|
||||
? list(abs, callback, join(pre, str))
|
||||
: callback(join(pre, str), abs, stats)
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
22
node_modules/totalist/dist/index.mjs
generated
vendored
Normal file
22
node_modules/totalist/dist/index.mjs
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
import { join, resolve } from 'path';
|
||||
import { readdir, stat } from 'fs';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const toStats = promisify(stat);
|
||||
const toRead = promisify(readdir);
|
||||
|
||||
export default async function list(dir, callback, pre='') {
|
||||
dir = resolve('.', dir);
|
||||
await toRead(dir).then(arr => {
|
||||
return Promise.all(
|
||||
arr.map(str => {
|
||||
let abs = join(dir, str);
|
||||
return toStats(abs).then(stats => {
|
||||
return stats.isDirectory()
|
||||
? list(abs, callback, join(pre, str))
|
||||
: callback(join(pre, str), abs, stats)
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
13
node_modules/totalist/index.d.ts
generated
vendored
Normal file
13
node_modules/totalist/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
declare module 'totalist' {
|
||||
import { Stats } from 'fs';
|
||||
export type Caller = (relPath: string, absPath: string, stats: Stats) => any;
|
||||
function totalist(dir: string, callback: Caller, prefix?: string): Promise<void>;
|
||||
export = totalist;
|
||||
}
|
||||
|
||||
declare module 'totalist/sync' {
|
||||
import { Stats } from 'fs';
|
||||
export type Caller = (relPath: string, absPath: string, stats: Stats) => any;
|
||||
function totalist(dir: string, callback: Caller, prefix?: string): void;
|
||||
export = totalist;
|
||||
}
|
21
node_modules/totalist/license
generated
vendored
Normal file
21
node_modules/totalist/license
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (lukeed.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:
|
||||
|
||||
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.
|
77
node_modules/totalist/package.json
generated
vendored
Normal file
77
node_modules/totalist/package.json
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
{
|
||||
"_from": "totalist@^1.0.0",
|
||||
"_id": "totalist@1.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-gduQwd1rOdDMGxFG1gEvhV88Oirdo2p+KjoYFU7k2g+i7n6AFFbDQ5kMPUsW0pNbfQsB/cwXvT1i4Bue0s9g5g==",
|
||||
"_location": "/totalist",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "totalist@^1.0.0",
|
||||
"name": "totalist",
|
||||
"escapedName": "totalist",
|
||||
"rawSpec": "^1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/sirv"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/totalist/-/totalist-1.1.0.tgz",
|
||||
"_shasum": "a4d65a3e546517701e3e5c37a47a70ac97fe56df",
|
||||
"_spec": "totalist@^1.0.0",
|
||||
"_where": "C:\\Users\\zhouxueli\\Desktop\\scheduling-app\\node_modules\\sirv",
|
||||
"author": {
|
||||
"name": "Luke Edwards",
|
||||
"email": "luke.edwards05@gmail.com",
|
||||
"url": "https://lukeed.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/lukeed/totalist/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "A tiny (195B to 224B) utility to recursively list all (total) files in a directory",
|
||||
"devDependencies": {
|
||||
"bundt": "1.0.1",
|
||||
"esm": "3.2.25",
|
||||
"premove": "1.0.0",
|
||||
"uvu": "0.0.13"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"dist",
|
||||
"sync"
|
||||
],
|
||||
"homepage": "https://github.com/lukeed/totalist#readme",
|
||||
"keywords": [
|
||||
"list",
|
||||
"recursive",
|
||||
"files",
|
||||
"glob",
|
||||
"tree"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"modes": {
|
||||
"sync": "src/sync.js",
|
||||
"default": "src/async.js"
|
||||
},
|
||||
"module": "dist/index.mjs",
|
||||
"name": "totalist",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lukeed/totalist.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "bundt",
|
||||
"postbuild": "cp sync.d.ts sync/index.d.ts",
|
||||
"test": "uvu -r esm test -i fixtures"
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"version": "1.1.0"
|
||||
}
|
109
node_modules/totalist/readme.md
generated
vendored
Normal file
109
node_modules/totalist/readme.md
generated
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
# totalist [](https://github.com/lukeed/totalist/actions) [](https://codecov.io/gh/lukeed/totalist)
|
||||
|
||||
> A tiny (195B to 224B) utility to recursively list all (total) files in a directory
|
||||
|
||||
Traverse a directory recursively, running a function for **every file** found.
|
||||
|
||||
With this module, you easily apply custom logic to decide which file(s) to process without worrying about accidentally accessing a directory or making repeat `fs.Stats` requests.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save totalist
|
||||
```
|
||||
|
||||
|
||||
## Modes
|
||||
|
||||
There are two "versions" of `totalist` available:
|
||||
|
||||
#### "async"
|
||||
> **Node.js:** >= 8.x<br>
|
||||
> **Size (gzip):** 224 bytes<br>
|
||||
> **Availability:** [CommonJS](https://unpkg.com/totalist/dist/index.js), [ES Module](https://unpkg.com/totalist/dist/index.mjs)
|
||||
|
||||
This is the primary/default mode. It makes use of `async`/`await` and [`util.promisify`](https://nodejs.org/api/util.html#util_util_promisify_original).
|
||||
|
||||
#### "sync"
|
||||
> **Node.js:** >= 6.x<br>
|
||||
> **Size (gzip):** 195 bytes<br>
|
||||
> **Availability:** [CommonJS](https://unpkg.com/totalist/sync/index.js), [ES Module](https://unpkg.com/totalist/sync/index.mjs)
|
||||
|
||||
This is the opt-in mode, ideal for scenarios where `async` usage cannot be supported.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
***Selecting a Mode***
|
||||
|
||||
```js
|
||||
// import via npm module
|
||||
import totalist from 'totalist';
|
||||
import totalist from 'totalist/sync';
|
||||
```
|
||||
|
||||
***Example Usage***
|
||||
|
||||
```js
|
||||
import totalist from 'totalist/sync';
|
||||
|
||||
const styles = new Set();
|
||||
const scripts = new Set();
|
||||
|
||||
totalist('src', (name, abs, stats) => {
|
||||
if (/\.js$/.test(name)) {
|
||||
scripts.add(abs);
|
||||
if (stats.size >= 100e3) {
|
||||
console.warn(`[WARN] "${name}" might cause performance issues (${stats.size})`);
|
||||
}
|
||||
} else if (/\.css$/.test(name)) {
|
||||
styles.add(abs);
|
||||
}
|
||||
});
|
||||
|
||||
console.log([...scripts]);
|
||||
//=> [..., '/Users/lukeed/.../src/path/to/example.css', ...]
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### totalist(dir, callback)
|
||||
Returns: `void`
|
||||
|
||||
> **Important:** The "async" usage must be `await`ed or included within a Promise chain.
|
||||
|
||||
#### dir
|
||||
Type: `string`<br>
|
||||
Required: `true`
|
||||
|
||||
The directory to traverse.
|
||||
|
||||
This may be a relative _or_ an absolute path.
|
||||
|
||||
> **Note**: Node.js will assume a relative path is meant to be resolved from the current location (`process.cwd()`).
|
||||
|
||||
#### callback
|
||||
Type: `Function`<br>
|
||||
Required: `true`
|
||||
|
||||
The callback function to run for _every_ file.
|
||||
|
||||
The function receives three parameters:
|
||||
|
||||
##### relPath
|
||||
Type: `String`<br>
|
||||
The path _relative to_ the initial `dir` value you provided.
|
||||
|
||||
##### absPath
|
||||
Type: `String`<br>
|
||||
The absolute path of the file.
|
||||
|
||||
##### stats
|
||||
Type: `fs.Stats`<br>
|
||||
The [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object for the file.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Luke Edwards](https://lukeed.com)
|
4
node_modules/totalist/sync/index.d.ts
generated
vendored
Normal file
4
node_modules/totalist/sync/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import { Stats } from 'fs';
|
||||
export type Caller = (relPath: string, absPath: string, stats: Stats) => any;
|
||||
declare function totalist(dir: string, callback: Caller, prefix?: string): void;
|
||||
export default totalist;
|
15
node_modules/totalist/sync/index.js
generated
vendored
Normal file
15
node_modules/totalist/sync/index.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
const { join, resolve } = require('path');
|
||||
const { readdirSync, statSync } = require('fs');
|
||||
|
||||
module.exports = function list(dir, callback, pre='') {
|
||||
dir = resolve('.', dir);
|
||||
let arr = readdirSync(dir);
|
||||
let i=0, abs, stats;
|
||||
for (; i < arr.length; i++) {
|
||||
abs = join(dir, arr[i]);
|
||||
stats = statSync(abs);
|
||||
stats.isDirectory()
|
||||
? list(abs, callback, join(pre, arr[i]))
|
||||
: callback(join(pre, arr[i]), abs, stats);
|
||||
}
|
||||
}
|
15
node_modules/totalist/sync/index.mjs
generated
vendored
Normal file
15
node_modules/totalist/sync/index.mjs
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
import { join, resolve } from 'path';
|
||||
import { readdirSync, statSync } from 'fs';
|
||||
|
||||
export default function list(dir, callback, pre='') {
|
||||
dir = resolve('.', dir);
|
||||
let arr = readdirSync(dir);
|
||||
let i=0, abs, stats;
|
||||
for (; i < arr.length; i++) {
|
||||
abs = join(dir, arr[i]);
|
||||
stats = statSync(abs);
|
||||
stats.isDirectory()
|
||||
? list(abs, callback, join(pre, arr[i]))
|
||||
: callback(join(pre, arr[i]), abs, stats);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user