Skip to content

Commit

Permalink
build(deps-dev): replace standard with neostandard (#73)
Browse files Browse the repository at this point in the history
* build(deps-dev): replace standard with neostandard

* chore: add eslint.config.js

* chore: ignore no-new eslint rule

* build: bump neostandard
  • Loading branch information
Fdawgs authored Dec 13, 2024
1 parent 426c393 commit 1fe54ad
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/fastify/csrf/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/csrf/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/csrf.svg?style=flat)](https://www.npmjs.com/package/@fastify/csrf)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Logic behind CSRF token creation and verification.

Expand Down
6 changes: 6 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

module.exports = require('neostandard')({
ignores: require('neostandard').resolveIgnoresFromGitignore(),
ts: true
})
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"homepage": "https://github.com/fastify/csrf#readme",
"scripts": {
"bench": "node benchmark/index.js",
"lint": "standard",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "tap",
"test:typescript": "tsd"
Expand All @@ -30,7 +31,7 @@
"@types/node": "^22.0.0",
"beautify-benchmark": "^0.2.4",
"benchmark": "^2.1.4",
"standard": "^17.1.0",
"neostandard": "^0.12.0",
"tap": "^18.7.1",
"tsd": "^0.31.0"
},
Expand Down
14 changes: 7 additions & 7 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
interface TokensConstructor {
(options?: Tokens.Options & { userInfo: true}): Tokens.TokensUserinfo;
(options?: Tokens.Options & { userInfo: true }): Tokens.TokensUserinfo;
(options?: Tokens.Options): Tokens.TokensSimple;

new(options?: Tokens.Options & { userInfo: true}): Tokens.TokensUserinfo;
new(options?: Tokens.Options & { userInfo: true }): Tokens.TokensUserinfo;
new(options?: Tokens.Options): Tokens.TokensSimple;
}

Expand All @@ -11,8 +11,8 @@ declare namespace Tokens {
/**
* Create a new secret key.
*/
secret(callback: SecretCallback): void;
secret(): Promise<string>;
secret(callback: SecretCallback): void;
secret(): Promise<string>;

/**
* Create a new secret key synchronously.
Expand Down Expand Up @@ -44,7 +44,7 @@ declare namespace Tokens {
verify(secret: string, token: string, userInfo: string): boolean;
}

export type SecretCallback = (err: Error | null, secret: string) => void;
export type SecretCallback = (err: Error | null, secret: string) => void

export interface Options {
/**
Expand Down Expand Up @@ -100,7 +100,7 @@ type TypedArray =
| Int32Array
| Uint32Array
| Float32Array
| Float64Array;
| Float64Array

declare function Tokens(...params: Parameters<TokensConstructor>): ReturnType<TokensConstructor>
declare function Tokens (...params: Parameters<TokensConstructor>): ReturnType<TokensConstructor>
export = Tokens
67 changes: 34 additions & 33 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
import { expectError, expectType } from "tsd";
import { Tokens } from "..";

Tokens();
new Tokens();
Tokens({});
new Tokens({});
Tokens({ algorithm: 'sha1' });
Tokens({ algorithm: 'sha256' });
Tokens({ saltLength: 10 });
Tokens({ secretLength: 10 });
Tokens({ userInfo: true });
Tokens({ validity: 10000 });
Tokens({ hmacKey: 'foo' });
new Tokens({ saltLength: 10 });
new Tokens({ secretLength: 10 });
new Tokens({ userInfo: true });
new Tokens({ validity: 10000 });
/* eslint-disable no-new -- Testing constructor types, so no need to assign */
import { expectError, expectType } from 'tsd'
import { Tokens } from '..'

Tokens()
new Tokens()
Tokens({})
new Tokens({})
Tokens({ algorithm: 'sha1' })
Tokens({ algorithm: 'sha256' })
Tokens({ saltLength: 10 })
Tokens({ secretLength: 10 })
Tokens({ userInfo: true })
Tokens({ validity: 10000 })
Tokens({ hmacKey: 'foo' })
new Tokens({ saltLength: 10 })
new Tokens({ secretLength: 10 })
new Tokens({ userInfo: true })
new Tokens({ validity: 10000 })

expectError(Tokens('secret'))
expectError(new Tokens('secret'))

expectError(new Tokens({}).create('secret', 'userInfo'));
expectError(new Tokens({ userInfo: false}).create('secret', 'userInfo'));
expectError(new Tokens({ userInfo: true }).create('secret'));
expectError(new Tokens({}).create('secret', 'userInfo'))
expectError(new Tokens({ userInfo: false }).create('secret', 'userInfo'))
expectError(new Tokens({ userInfo: true }).create('secret'))

expectError(new Tokens({}).verify('secret', 'token', 'userinfo'));
expectError(new Tokens({ userInfo: false}).verify('secret', 'token', 'userInfo'));
expectError(new Tokens({ userInfo: true }).verify('secret', 'token'));
expectError(new Tokens({}).verify('secret', 'token', 'userinfo'))
expectError(new Tokens({ userInfo: false }).verify('secret', 'token', 'userInfo'))
expectError(new Tokens({ userInfo: true }).verify('secret', 'token'))

expectError(new Tokens({ hmacKey: 123 }));
expectError(new Tokens({ hmacKey: 123 }))

expectType<Promise<string>>(Tokens().secret());
expectType<Promise<string>>(new Tokens().secret());
expectType<Promise<string>>(Tokens().secret())
expectType<Promise<string>>(new Tokens().secret())

expectType<void>(Tokens().secret((err, secret ) => {
expectType<Error| null>(err)
expectType<void>(Tokens().secret((err, secret) => {
expectType<Error | null>(err)
expectType<string>(secret)
}));
expectType<void>(new Tokens().secret((err, secret ) => {
expectType<Error| null>(err)
}))
expectType<void>(new Tokens().secret((err, secret) => {
expectType<Error | null>(err)
expectType<string>(secret)
}));
}))

expectType<string>(Tokens().secretSync())
expectType<string>(new Tokens().secretSync())

0 comments on commit 1fe54ad

Please sign in to comment.