Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Mar 4, 2021
0 parents commit de0f61b
Show file tree
Hide file tree
Showing 14 changed files with 3,123 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release
on:
push:
branches: [ master, next, next-major, beta, alpha ]
jobs:
release:
name: Release
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Install dependencies
run: npx ci
- name: Lint
run: npm run lint
- name: Test
run: npm run test --if-present
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test
on:
push:
branches: [ develop ]
pull_request:
branches: [ develop, master, next, next-major, beta, alpha ]
jobs:
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
node-version: [ 12.x, 15.x ]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npx ci
- name: Lint
run: npm run lint
- name: Test
run: npm run test --if-present
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# macOS
.DS_Store

# Logs
logs
*.log

# Node dependency directory
node_modules

# Output of 'npm pack'
*.tgz
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v14.16.0
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Hiroki Osame <[email protected]>

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.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# fs.promises.exists [![Latest version](https://badgen.net/npm/v/fs.promises.exists)](https://npm.im/fs.promises.exists) [![Monthly downloads](https://badgen.net/npm/dm/fs.promises.exists)](https://npm.im/fs.promises.exists) [![Install size](https://packagephobia.now.sh/badge?p=fs.promises.exists)](https://packagephobia.now.sh/result?p=fs.promises.exists)

The missing `fs.promises.exists()`

<sub>If you like this project, please star it & [follow me](https://github.com/privatenumber) to see what other cool projects I'm working on! ❤️</sub>

## 🙋‍♂️ Why?
Because the [fs Promises API](https://nodejs.org/docs/latest/api/fs.html#fs_promises_api) doesn't have an `exists()` method that replaces [`existsSync()`](https://nodejs.org/docs/latest/api/fs.html#fs_fs_existssync_path).

## 🚀 Install
```sh
npm i fs.promises.exists
```

## 👨🏻‍🏫 Examples
```
import fsExists from 'fs.promises.exists';
await fsExists('./file-that-exists')
// > true
await fsExists('./file-that-doesnt-exist')
// > false
```
14 changes: 14 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
Returns a promise that resolves to a boolean indicating whether the file exists.
@example
```
import fsExists from 'fs.promises.exists';
await fsExists('./file-that-exists')
// > true
```
*/
declare const fsExists: (filePath: string) => Promise<boolean>;

export default fsExists;
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as fs from 'fs';

const fsExists = async filePath => fs.promises.access(
filePath,
fs.constants.F_OK,
).then(() => true, () => false);

export default fsExists;
15 changes: 15 additions & 0 deletions index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert'; // eslint-disable-line node/file-extension-in-import
import fsExists from './index.js';

test('exists', async () => {
const exists = await fsExists('./package.json');
assert.is(exists, true);
});

test('doesn\'t exist', async () => {
const exists = await fsExists('./random-non-existent-file');
assert.is(exists, false);
});

test.run();
4 changes: 4 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { expectType } from 'tsd';
import fsExists from './index.js';

expectType<Promise<boolean>>(fsExists('./'));
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "fs.promises.exists",
"version": "0.0.0-semantic-release",
"description": "The missing fs.promises.exists()",
"keywords": [
"fs",
"promise",
"promises",
"exists"
],
"license": "MIT",
"repository": "privatenumber/fs.promises.exists",
"funding": "https://github.com/privatenumber/fs.promises.exists?sponsor=1",
"author": {
"name": "Hiroki Osame",
"email": "[email protected]"
},
"type": "module",
"files": [
"index.js",
"index.d.ts"
],
"exports": "./index.js",
"scripts": {
"build": "tsc",
"lint": "eslint .",
"test": "uvu && tsd"
},
"husky": {
"hooks": {
"pre-commit": "eslint . && uvu && tsd"
}
},
"devDependencies": {
"@pvtnbr/eslint-config-base": "^0.1.11",
"eslint": "^7.21.0",
"husky": "^4.3.8",
"tsd": "^0.14.0",
"uvu": "^0.5.1"
},
"eslintConfig": {
"extends": "@pvtnbr/eslint-config-base"
}
}
Loading

0 comments on commit de0f61b

Please sign in to comment.