Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
it.js
it.d.ts
de.js
de.d.ts
en.js
en.d.ts
36 changes: 36 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"parser": "@typescript-eslint/parser",
"env": {
"node": true,
"browser": true,
"es6": true,
"commonjs": true
},
"plugins": [
"@typescript-eslint",
"import",
"prettier"
],
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:jest/recommended"
],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2018
},
"rules": {
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/member-delimiter-style": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"import/order": [
"error",
{
"groups": ["builtin", "external", "unknown", "parent", "sibling", "index"]
}
]
}
}
6 changes: 6 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -e
set -o pipefail

npm run lint
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Create Relase & Publish Package
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- uses: actions/setup-node@v1
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Basic
.DS_Store

# IDE
/.idea
/.vscode

# Project
/package-lock.json
/node_modules
/dist

it.js
it.d.ts
de.js
de.d.ts
en.js
en.d.ts
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"semi": false
}
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
transform: {
'^.+\\.tsx?$': 'babel-jest',
},
moduleNameMapper: {
'\\.(css)$': 'identity-obj-proxy',
},
}
67 changes: 67 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "@aboutbits/yup-locales",
"version": "0.0.0",
"description": "Custom yup locales",
"keywords": [
"yup",
"internationalization",
"language",
"languages"
],
"author": "AboutBits",
"license": "MIT",
"private": false,
"main": "en.js",
"typings": "en.d.ts",
"scripts": {
"build": "tsc",
"lint": "eslint --ext js,ts,tsx src",
"lint:fix": "npm run lint -- --fix",
"test": "jest --config jest.config.js --passWithNoTests",
"prepare": "npm run build",
"prepublishOnly": "npm run test && npm run lint",
"version": "npm run test && npm run lint && git add -A src",
"postversion": "git push && git push --tags"
},
"repository": {
"type": "git",
"url": "git+https://github.com/aboutbits/yup-locales.git"
},
"files": [
"readme.md",
"it.js",
"it.d.ts",
"de.js",
"de.d.ts",
"en.js",
"en.d.ts"
],
"publishConfig": {
"access": "public"
},
"bugs": {
"url": "https://github.com/aboutbits/yup-locales/issues"
},
"homepage": "https://github.com/aboutbits/yup-locales#readme",
"engines": {
"npm": "^8",
"node": "^16"
},
"devDependencies": {
"@types/jest": "^28.1.3",
"@types/node": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.29.0",
"babel-jest": "^28.1.1",
"babel-loader": "^8.2.5",
"eslint": "^8.18.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.5.3",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^28.1.1",
"prettier": "^2.7.1",
"typescript": "^4.7.4",
"yup": "^0.32.11"
}
}
56 changes: 56 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Custom Yup Locales
====================

[![npm version](https://badge.fury.io/js/%40aboutbits%2Fyup-locales.svg)](https://badge.fury.io/js/%40aboutbits%2Fyup-locales)

This package includes simplified translations for yup error messages. The main difference lies in the exclusion of the field path.

## Table of content

- [Usage](#usage)
- [Build & Publish](#build--publish)
- [Information](#information)

## Usage

First, you have to install the package:

```bash
npm install @aboutbits/yup-locales
```

Second, you add the custom language packages to your project.

```js
import { setLocale } from 'yup'
import { en, it, de } from '@aboutbits/yup-locales'

// If you want that your app returns Italian error messages.
setLocale(it)
```

## Build & Publish

To build and publish the package, simply commit all changes and push them to master. Then run one of the following commands locally:

```bash
npm version patch
npm version minor
npm version major
```

## Information

About Bits is a company based in South Tyrol, Italy. You can find more information about us on [our website](https://aboutbits.it).

### Support

For support, please contact [info@aboutbits.it](mailto:info@aboutbits.it).

### Credits

- [All Contributors](../../contributors)

### License

The MIT License (MIT). Please see the [license file](LICENSE.md) for more information.
71 changes: 71 additions & 0 deletions src/de.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
MixedLocale,
StringLocale,
NumberLocale,
DateLocale,
BooleanLocale,
ObjectLocale,
ArrayLocale,
LocaleObject,
} from 'yup/es/locale'

export const mixed: Required<MixedLocale> = {
default: 'Ungültiger Wert',
required: 'Pflichtfeld',
defined: 'Pflichtfeld',
oneOf: 'Gültige Werte: ${values}',
notOneOf: 'Ungültige Werte: ${values}',
notType: 'Ungültiger Typ',
}

export const string: Required<StringLocale> = {
length: 'Genau ${length} Zeichen',
min: 'Min ${min} Zeichen',
max: 'Max ${max} Zeichen',
matches: 'Format ungültig: "${regex}"',
email: 'Ungültige E-Mail',
url: 'Ungültige URL',
uuid: 'Ungültige UUID',
trim: 'Keine Leerzeichen am Anfang und Ende',
lowercase: 'Nur Kleinschreibung',
uppercase: 'Nur Großschreibung',
}

export const number: Required<NumberLocale> = {
min: 'Min: ${min}',
max: 'Max: ${max}',
lessThan: 'Kleiner als ${less}',
moreThan: 'Größer als ${more}',
positive: 'Nur positive Zahlen',
negative: 'Nur negative Zahlen',
integer: 'Nur Zahlen erlaubt',
}

export const date: Required<DateLocale> = {
min: 'Datum nach ${min}',
max: 'Datum vor ${max}',
}

export const boolean: BooleanLocale = {
isValue: 'Muss ${value} sein',
}

export const object: Required<ObjectLocale> = {
noUnknown: 'Unbekannter Wert',
}

export const array: Required<ArrayLocale> = {
min: 'Mindestens ${min} Einträge',
max: 'Maximal ${max} Einträge',
length: 'Genau ${length} Einträge',
}

export default {
mixed,
string,
number,
date,
object,
array,
boolean,
} as LocaleObject
71 changes: 71 additions & 0 deletions src/en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
MixedLocale,
StringLocale,
NumberLocale,
DateLocale,
BooleanLocale,
ObjectLocale,
ArrayLocale,
LocaleObject,
} from 'yup/es/locale'

export const mixed: Required<MixedLocale> = {
default: 'Invalid value',
required: 'Required',
defined: 'Required',
oneOf: 'One of: ${values}',
notOneOf: 'Not one of: ${values}',
notType: 'Invalid type',
}

export const string: Required<StringLocale> = {
length: 'Must be exactly ${length} characters',
min: 'Min ${min} characters',
max: 'Max ${max} characters',
matches: 'Must match: "${regex}"',
email: 'Invalid email',
url: 'Invalid URL',
uuid: 'Invalid UUID',
trim: 'Not trimmed',
lowercase: 'Lowercase only',
uppercase: 'Uppercase only',
}

export const number: Required<NumberLocale> = {
min: 'Min: ${min}',
max: 'Max: ${max}',
lessThan: 'Less than ${less}',
moreThan: 'Greater than ${more}',
positive: 'Positive number',
negative: 'Negative number',
integer: 'Numbers only',
}

export const date: Required<DateLocale> = {
min: 'Later than ${min}',
max: 'Earlier than ${max}',
}

export const boolean: BooleanLocale = {
isValue: 'Must be ${value}',
}

export const object: Required<ObjectLocale> = {
noUnknown: 'Unknown value',
}

export const array: Required<ArrayLocale> = {
min: 'At least ${min} items',
max: 'Not more than ${max} items',
length: 'Exactly ${length} items',
}

export default {
mixed,
string,
number,
date,
object,
array,
boolean,
} as LocaleObject
Loading