Skip to content

Commit

Permalink
switch to typescript (#15)
Browse files Browse the repository at this point in the history
* switch to typescript

* refactor

* add cjs, mjs & ts examples

* add codeql ts support

is codeql even necessary for this?

* drop node 15 and add node 20

* update readme

* remove path aliases

* update changelog

---------

Co-authored-by: Kyriakos Nicola <knicola@users.noreply.github.com>
  • Loading branch information
knicola and knicola authored Mar 7, 2024
1 parent 8b2967c commit f9b0061
Show file tree
Hide file tree
Showing 20 changed files with 2,556 additions and 217 deletions.
29 changes: 0 additions & 29 deletions .eslintrc

This file was deleted.

11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require('@knicola/dev-config/eslint/patch')

module.exports = {
extends: ['./node_modules/@knicola/dev-config/eslint/node'],
parserOptions: { tsconfigRootDir: __dirname },
settings: {
'import/resolver': {
typescript: { project: __dirname },
},
},
}
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
language: [ 'javascript-typescript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [15.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"eslint.format.enable": true
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [next-version] - next-release-date
### Changed
* Switched to Typescript.

### Removed
* Deprecated method `.minRepeating()`.

## [0.3.0] - 2024-03-02
### Changed
* Bump `@types/jest` from 27.0.1 to 29.5.12
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ $ yarn add yup-password
## Usage
Plug and play:
```js
// ES6
// MJS / TS
import * as yup from 'yup'
import YupPassword from 'yup-password'
YupPassword(yup) // extend yup
```
```js
// CommonJs
// CJS
const yup = require('yup')
require('yup-password')(yup) // extend yup
```
Expand Down Expand Up @@ -62,7 +62,7 @@ const schema = yup.string().password()
.minWords(2) // add an additional rule

try {
const res = await schema.validate('secret')
const res = await schema.validate('secret', { abortEarly: false })
// ...
} catch(e) {
console.log(e.errors) // => [
Expand All @@ -76,7 +76,7 @@ try {
```
Pick and choose your password rules:
```js
const schema = yup.string().min(6).minUppercase(3).minRepeating(2).minWords(2)
const schema = yup.string().min(6).minUppercase(3).maxRepeating(2).minWords(2)

await schema.isValid('Now, THIS is some password.') // => true
await schema.isValid('But thiiis is not.') // => false
Expand Down
16 changes: 16 additions & 0 deletions examples/javascript.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable no-console */
'use strict'

const yup = require('yup')
require('../dist/index.js')(yup)

const schema = yup.object({
password: yup.string().password(),
})

const input = {
password: 'weak',
}

schema.validate(input, { abortEarly: false })
.catch(e => console.error(e.errors))
17 changes: 17 additions & 0 deletions examples/javascript.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable no-console */
'use strict'

import * as yup from 'yup'
import YupPassword from '../dist/index.js'
YupPassword(yup)

const schema = yup.object({
password: yup.string().password(),
})

const input = {
password: 'weak',
}

schema.validate(input, { abortEarly: false })
.catch(e => console.error(e.errors))
15 changes: 15 additions & 0 deletions examples/typescript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable no-console */
import * as yup from 'yup'
import YupPassword from '../src'
YupPassword(yup)

const schema = yup.object({
password: yup.string().password(),
})

const input = {
password: 'weak',
}

schema.validate(input, { abortEarly: false })
.catch(e => console.error(e.errors))
21 changes: 0 additions & 21 deletions index.d.ts

This file was deleted.

112 changes: 0 additions & 112 deletions index.js

This file was deleted.

24 changes: 24 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { JestConfigWithTsJest } from 'ts-jest'

const config: JestConfigWithTsJest = {
preset: 'ts-jest',
testEnvironment: 'node',
bail: true,
testMatch: [
'<rootDir>/tests/**/*.spec.ts',
'<rootDir>/tests/**/*.test.ts',
],
collectCoverageFrom: [
'<rootDir>/src/**/*.ts',
],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 0,
},
},
}

export default config
11 changes: 0 additions & 11 deletions jsconfig.json

This file was deleted.

Loading

0 comments on commit f9b0061

Please sign in to comment.