Skip to content

Commit e746547

Browse files
committed
Format with prettier
1 parent 548559d commit e746547

File tree

19 files changed

+1181
-1128
lines changed

19 files changed

+1181
-1128
lines changed

.github/workflows/lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
workflow_dispatch:
8+
jobs:
9+
test:
10+
name: Test
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node_version: ["current"]
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: ${{ matrix.node_version }}
20+
- name: Install dependencies
21+
run: npm ci --no-audit
22+
- name: Lint
23+
run: npm run lint

.github/workflows/publish.yml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ jobs:
77
if: github.repository == 'dcodeIO/bcrypt.js'
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v4
11-
with:
12-
ref: main
13-
- uses: actions/setup-node@v4
14-
with:
15-
node-version: current
16-
- name: Install dependencies
17-
run: npm ci
18-
- name: Build
19-
run: npm run build
20-
- name: Run tests
21-
run: npm test
22-
- name: Publish
23-
env:
24-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
26-
run: |
27-
VERSION=$(npx aspublish --version)
28-
if [ -z "$VERSION" ]; then
29-
echo "Changes do not trigger a release"
30-
else
31-
echo "Publishing new version: $VERSION"
32-
npx aspublish
33-
fi
10+
- uses: actions/checkout@v4
11+
with:
12+
ref: main
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: current
16+
- name: Install dependencies
17+
run: npm ci
18+
- name: Build
19+
run: npm run build
20+
- name: Run tests
21+
run: npm test
22+
- name: Publish
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
26+
run: |
27+
VERSION=$(npx aspublish --version)
28+
if [ -z "$VERSION" ]; then
29+
echo "Changes do not trigger a release"
30+
else
31+
echo "Publishing new version: $VERSION"
32+
npx aspublish
33+
fi

.github/workflows/stale.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
name: Stale
22
on:
33
schedule:
4-
- cron: '0 0 * * *'
4+
- cron: "0 0 * * *"
55
jobs:
66
stale:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/stale@v9
10-
with:
11-
stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!'
12-
stale-issue-label: 'stale'
13-
stale-pr-message: 'This PR has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!'
14-
close-pr-message: 'This PR has been automatically closed due to lack of recent activity, but feel free to reopen it as long as you merge in the main branch afterwards.'
15-
exempt-issue-labels: 'bug,enhancement,compatibility'
16-
exempt-pr-labels: 'breaking change'
17-
exempt-draft-pr: true
18-
exempt-all-milestones: true
19-
exempt-all-assignees: true
20-
days-before-issue-stale: 30
21-
days-before-pr-stale: 60
22-
days-before-close: 7
9+
- uses: actions/stale@v9
10+
with:
11+
stale-issue-message: "This issue has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!"
12+
stale-issue-label: "stale"
13+
stale-pr-message: "This PR has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!"
14+
close-pr-message: "This PR has been automatically closed due to lack of recent activity, but feel free to reopen it as long as you merge in the main branch afterwards."
15+
exempt-issue-labels: "bug,enhancement,compatibility"
16+
exempt-pr-labels: "breaking change"
17+
exempt-draft-pr: true
18+
exempt-all-milestones: true
19+
exempt-all-assignees: true
20+
days-before-issue-stale: 30
21+
days-before-pr-stale: 60
22+
days-before-close: 7

.github/workflows/test.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Test
22
on:
33
push:
44
branches:
5-
- main
5+
- main
66
pull_request:
77
workflow_dispatch:
88
jobs:
@@ -13,13 +13,13 @@ jobs:
1313
matrix:
1414
node_version: ["current", "lts/*"]
1515
steps:
16-
- uses: actions/checkout@v4
17-
- uses: actions/setup-node@v4
18-
with:
19-
node-version: ${{ matrix.node_version }}
20-
- name: Install dependencies
21-
run: npm ci --no-audit
22-
- name: Build
23-
run: npm run build
24-
- name: Run tests
25-
run: npm test
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: ${{ matrix.node_version }}
20+
- name: Install dependencies
21+
run: npm ci --no-audit
22+
- name: Build
23+
run: npm run build
24+
- name: Run tests
25+
run: npm test

.prettierrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};

README.md

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
bcrypt.js
2-
=========
1+
# bcrypt.js
32

43
Optimized bcrypt in JavaScript with zero dependencies, with TypeScript support. Compatible to the C++
54
[bcrypt](https://npmjs.org/package/bcrypt) binding on Node.js and also working in the browser.
65

76
[![Build Status](https://img.shields.io/github/actions/workflow/status/dcodeIO/bcrypt.js/test.yml?branch=main&label=test&logo=github)](https://github.com/dcodeIO/bcrypt.js/actions/workflows/test.yml) [![Publish Status](https://img.shields.io/github/actions/workflow/status/dcodeIO/bcrypt.js/publish.yml?branch=main&label=publish&logo=github)](https://github.com/dcodeIO/bcrypt.js/actions/workflows/publish.yml) [![npm](https://img.shields.io/npm/v/bcryptjs.svg?label=npm&color=007acc&logo=npm)](https://www.npmjs.com/package/bcryptjs)
87

9-
Security considerations
10-
-----------------------
8+
## Security considerations
119

1210
Besides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive function: over time, the
1311
iteration count can be increased to make it slower, so it remains resistant to brute-force search attacks even with
@@ -19,8 +17,7 @@ processed in an equal time span.
1917
The maximum input length is 72 bytes (note that UTF8 encoded characters use up to 4 bytes) and the length of generated
2018
hashes is 60 characters.
2119

22-
Usage
23-
-----
20+
## Usage
2421

2522
The package exports an ECMAScript module with an UMD fallback.
2623

@@ -29,93 +26,93 @@ $> npm install bcryptjs
2926
```
3027

3128
```ts
32-
import bcrypt from 'bcryptjs'
29+
import bcrypt from "bcryptjs";
3330
```
3431

3532
### Usage with a CDN
3633

37-
* From GitHub via [jsDelivr](https://www.jsdelivr.com):<br />
34+
- From GitHub via [jsDelivr](https://www.jsdelivr.com):<br />
3835
`https://cdn.jsdelivr.net/gh/dcodeIO/bcrypt.js@TAG/index.js` (ESM)
39-
* From npm via [jsDelivr](https://www.jsdelivr.com):<br />
36+
- From npm via [jsDelivr](https://www.jsdelivr.com):<br />
4037
`https://cdn.jsdelivr.net/npm/bcryptjs@VERSION/index.js` (ESM)<br />
4138
`https://cdn.jsdelivr.net/npm/bcryptjs@VERSION/umd/index.js` (UMD)
42-
* From npm via [unpkg](https://unpkg.com):<br />
39+
- From npm via [unpkg](https://unpkg.com):<br />
4340
`https://unpkg.com/bcryptjs@VERSION/index.js` (ESM)<br />
4441
`https://unpkg.com/bcryptjs@VERSION/umd/index.js` (UMD)
4542

4643
Replace `TAG` respectively `VERSION` with a [specific version](https://github.com/dcodeIO/bcrypt.js/releases) or omit it (not recommended in production) to use latest.
4744

4845
### Usage - Sync
4946

50-
To hash a password:
47+
To hash a password:
5148

5249
```ts
53-
const salt = bcrypt.genSaltSync(10)
54-
const hash = bcrypt.hashSync('B4c0/\/', salt)
50+
const salt = bcrypt.genSaltSync(10);
51+
const hash = bcrypt.hashSync("B4c0/\/", salt);
5552
// Store hash in your password DB
5653
```
5754

5855
To check a password:
5956

6057
```ts
6158
// Load hash from your password DB
62-
bcrypt.compareSync('B4c0/\/', hash) // true
63-
bcrypt.compareSync('not_bacon', hash) // false
59+
bcrypt.compareSync("B4c0/\/", hash); // true
60+
bcrypt.compareSync("not_bacon", hash); // false
6461
```
6562

6663
Auto-gen a salt and hash:
6764

6865
```ts
69-
const hash = bcrypt.hashSync('bacon', 10)
66+
const hash = bcrypt.hashSync("bacon", 10);
7067
```
7168

7269
### Usage - Async
7370

7471
To hash a password:
7572

7673
```ts
77-
const salt = await bcrypt.genSalt(10)
78-
const hash = await bcrypt.hash('B4c0/\/', salt)
74+
const salt = await bcrypt.genSalt(10);
75+
const hash = await bcrypt.hash("B4c0/\/", salt);
7976
// Store hash in your password DB
8077
```
8178

8279
```ts
8380
bcrypt.genSalt(10, (err, salt) => {
84-
bcrypt.hash('B4c0/\/', salt, function(err, hash) {
85-
// Store hash in your password DB
86-
})
87-
})
81+
bcrypt.hash("B4c0/\/", salt, function (err, hash) {
82+
// Store hash in your password DB
83+
});
84+
});
8885
```
8986

90-
To check a password:
87+
To check a password:
9188

9289
```ts
9390
// Load hash from your password DB
94-
await bcrypt.compare('B4c0/\/', hash) // true
95-
await bcrypt.compare('not_bacon', hash) // false
91+
await bcrypt.compare("B4c0/\/", hash); // true
92+
await bcrypt.compare("not_bacon", hash); // false
9693
```
9794

9895
```ts
9996
// Load hash from your password DB
100-
bcrypt.compare('B4c0/\/', hash, (err, res) => {
101-
// res === true
102-
})
103-
bcrypt.compare('not_bacon', hash, (err, res) => {
104-
// res === false
105-
})
97+
bcrypt.compare("B4c0/\/", hash, (err, res) => {
98+
// res === true
99+
});
100+
bcrypt.compare("not_bacon", hash, (err, res) => {
101+
// res === false
102+
});
106103
```
107104

108105
Auto-gen a salt and hash:
109106

110107
```ts
111-
await bcrypt.hash('B4c0/\/', 10)
108+
await bcrypt.hash("B4c0/\/", 10);
112109
// Store hash in your password DB
113110
```
114111

115112
```ts
116-
bcrypt.hash('B4c0/\/', 10, (err, hash) => {
117-
// Store hash in your password DB
118-
})
113+
bcrypt.hash("B4c0/\/", 10, (err, hash) => {
114+
// Store hash in your password DB
115+
});
119116
```
120117

121118
**Note:** Under the hood, asynchronous APIs split an operation into small chunks. After the completion of a chunk, the execution of the next chunk is placed on the back of the [JS event queue](https://developer.mozilla.org/en/docs/Web/JavaScript/EventLoop), efficiently yielding for other computation to execute.
@@ -126,50 +123,62 @@ bcrypt.hash('B4c0/\/', 10, (err, hash) => {
126123
Usage: bcrypt <input> [rounds|salt]
127124
```
128125

129-
API
130-
---
126+
## API
131127

132128
### Callback types
133129

134-
* type **Callback<`T`>**: `(err: Error | null, result?: T) => void`
130+
- type **Callback<`T`>**: `(err: Error | null, result?: T) => void`
135131

136-
* type **ProgressCallback**: `(percentage: number) => void`
132+
- type **ProgressCallback**: `(percentage: number) => void`
137133

138134
### Functions
139135

140-
* bcrypt.**setRandomFallback**(random: `(length: number) => number[]`): `void`<br />
136+
- bcrypt.**setRandomFallback**(random: `(length: number) => number[]`): `void`<br />
141137
Sets the pseudo random number generator to use as a fallback if neither Node's [crypto](http://nodejs.org/api/crypto.html) module nor the [Web Crypto API](http://www.w3.org/TR/WebCryptoAPI/) is available. Please note: It is highly important that the PRNG used is cryptographically secure and that it is seeded properly!
142138

143-
* bcrypt.**genSaltSync**(rounds?: `number`): `string`<br />
139+
- bcrypt.**genSaltSync**(rounds?: `number`): `string`<br />
144140
Synchronously generates a salt. Number of rounds defaults to 10 when omitted.
145141

146-
* bcrypt.**genSalt**(rounds?: `number`): `Promise<string>`<br />
142+
- bcrypt.**genSalt**(rounds?: `number`): `Promise<string>`<br />
147143
bcrypt.**genSalt**(rounds: `number`, callback: `Callback<string>`): `void`<br />
148144
bcrypt.**genSalt**(callback: `Callback<string>`): `void`<br />
149145
Asynchronously generates a salt. Number of rounds defaults to 10 when omitted.
150146

151-
* bcrypt.**hashSync**(s: `string`, salt?: `number | string`): `string`
147+
- bcrypt.**hashSync**(s: `string`, salt?: `number | string`): `string`
152148
Synchronously generates a hash for the given string. Number of rounds defaults to 10 when omitted.
153149

154-
* bcrypt.**hash**(s: `string`, salt: `number | string`): `Promise<string>`<br />
150+
- bcrypt.**hash**(s: `string`, salt: `number | string`): `Promise<string>`<br />
155151
bcrypt.**hash**(s: `string`, salt: `number | string`, callback: `Callback<string>`, progressCallback?: `ProgressCallback`): `void`<br />
156152
Asynchronously generates a hash for the given string. Optionally calls a progress callback with the percentage of rounds completed (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms.
157153

158-
* bcrypt.**compareSync**(s: `string`, hash: `string`): `boolean`<br />
154+
- bcrypt.**compareSync**(s: `string`, hash: `string`): `boolean`<br />
159155
Synchronously tests a string against a hash.
160156

161-
* bcrypt.**compare**(s: `string`, hash: `string`): `Promise<boolean>`<br />
157+
- bcrypt.**compare**(s: `string`, hash: `string`): `Promise<boolean>`<br />
162158
bcrypt.**compare**(s: `string`, hash: `string`, callback: `Callback<boolean>`, progressCallback?: `ProgressCallback`)<br />
163159
Asynchronously compares a string against a hash. Optionally calls a progress callback with the percentage of rounds completed (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms.
164160

165-
* bcrypt.**getRounds**(hash: `string`): `number`<br />
161+
- bcrypt.**getRounds**(hash: `string`): `number`<br />
166162
Gets the number of rounds used to encrypt the specified hash.
167163

168-
* bcrypt.**getSalt**(hash: `string`): `string`<br />
164+
- bcrypt.**getSalt**(hash: `string`): `string`<br />
169165
Gets the salt portion from a hash. Does not validate the hash.
170166

171-
Credits
172-
-------
167+
## Building
168+
169+
Building the UMD fallback:
170+
171+
```
172+
$> npm run build
173+
```
174+
175+
Running the [tests](./tests):
176+
177+
```
178+
$> npm test
179+
```
180+
181+
## Credits
173182

174183
Based on work started by Shane Girish at [bcrypt-nodejs](https://github.com/shaneGirish/bcrypt-nodejs), which is itself
175184
based on [javascript-bcrypt](http://code.google.com/p/javascript-bcrypt/) (New BSD-licensed).

0 commit comments

Comments
 (0)