├── src ├── validation-engine │ └── index.ts ├── helpers │ └── index.ts ├── mappers │ └── index.ts ├── validation-dispatcher │ └── index.ts ├── model │ └── index.ts ├── validators │ ├── pattern-helpers.ts │ ├── index.ts │ └── length.ts └── index.ts ├── examples ├── react-final-form │ ├── ts │ │ ├── nested-field │ │ │ ├── .env │ │ │ ├── src │ │ │ │ └── form-validation.ts │ │ │ └── tsconfig.json │ │ ├── validate-field │ │ │ ├── .env │ │ │ ├── src │ │ │ │ └── custom-validators │ │ │ │ │ ├── index.ts │ │ │ │ │ └── min-number.validator.ts │ │ │ └── tsconfig.json │ │ ├── validate-form │ │ │ ├── .env │ │ │ ├── src │ │ │ │ └── custom-validators │ │ │ │ │ ├── index.ts │ │ │ │ │ └── match-field.validator.ts │ │ │ └── tsconfig.json │ │ ├── async-validator │ │ │ ├── .env │ │ │ ├── src │ │ │ │ ├── custom-validators │ │ │ │ │ └── index.ts │ │ │ │ └── form-validation.ts │ │ │ └── tsconfig.json │ │ ├── custom-validators │ │ │ ├── .env │ │ │ ├── src │ │ │ │ └── custom-validators │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── is-number.validator.ts │ │ │ │ │ └── min-number.validator.ts │ │ │ └── tsconfig.json │ │ ├── validate-record │ │ │ ├── .env │ │ │ ├── src │ │ │ │ ├── custom-validators │ │ │ │ │ ├── index.ts │ │ │ │ │ └── free-shipping.record-validator.ts │ │ │ │ └── form-validation.ts │ │ │ └── tsconfig.json │ │ ├── custom-error-message │ │ │ ├── .env │ │ │ ├── src │ │ │ │ └── form-validation.ts │ │ │ └── tsconfig.json │ │ ├── shopping-cart-array-validator │ │ │ ├── .env │ │ │ ├── tsconfig.json │ │ │ └── src │ │ │ │ └── form-validation.ts │ │ ├── validate-field-record-and-form │ │ │ ├── .env │ │ │ ├── src │ │ │ │ ├── custom-validators │ │ │ │ │ ├── index.ts │ │ │ │ │ └── free-shipping.record-validator.ts │ │ │ │ └── form-validation.ts │ │ │ └── tsconfig.json │ │ └── multiple-user-creation-array-validator │ │ │ ├── .env │ │ │ └── tsconfig.json │ └── js │ │ ├── validate-field │ │ ├── custom-validators │ │ │ ├── index.js │ │ │ └── min-number.validator.js │ │ └── package.json │ │ ├── validate-form │ │ ├── custom-validators │ │ │ ├── index.js │ │ │ └── match-field.validator.js │ │ └── package.json │ │ ├── async-validator │ │ ├── custom-validators │ │ │ ├── index.js │ │ │ └── user-exists-on-github.validator.js │ │ ├── form-validation.js │ │ └── package.json │ │ ├── validate-record │ │ ├── custom-validators │ │ │ ├── index.js │ │ │ └── free-shipping.record-validator.js │ │ ├── form-validation.js │ │ └── package.json │ │ ├── validate-field-record-and-form │ │ ├── custom-validators │ │ │ ├── index.js │ │ │ └── free-shipping.record-validator.js │ │ └── form-validation.js │ │ ├── custom-validators │ │ ├── custom-validators │ │ │ ├── index.js │ │ │ ├── is-number.validator.js │ │ │ └── min-number.validator.js │ │ └── package.json │ │ ├── nested-field │ │ ├── form-validation.js │ │ └── package.json │ │ ├── custom-error-message │ │ ├── form-validation.js │ │ └── package.json │ │ └── shopping-cart-array-validator │ │ └── form-validation.js ├── docs │ ├── messages │ │ ├── ts │ │ │ ├── react-final-form │ │ │ │ ├── global-error-message │ │ │ │ │ ├── .env │ │ │ │ │ ├── src │ │ │ │ │ │ └── form-validation.ts │ │ │ │ │ └── tsconfig.json │ │ │ │ ├── i18n-full-example │ │ │ │ │ ├── .env │ │ │ │ │ ├── src │ │ │ │ │ │ ├── components │ │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ │ ├── images │ │ │ │ │ │ │ │ ├── english-flag.png │ │ │ │ │ │ │ │ └── spain-flag.png │ │ │ │ │ │ │ ├── flag-container.styles.tsx │ │ │ │ │ │ │ ├── flag.styles.tsx │ │ │ │ │ │ │ └── flag.tsx │ │ │ │ │ │ ├── validation │ │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ │ └── use-validation.ts │ │ │ │ │ │ ├── i18n │ │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ │ ├── languages.ts │ │ │ │ │ │ │ └── i18n.ts │ │ │ │ │ │ └── translations │ │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ │ ├── keys.ts │ │ │ │ │ │ │ ├── en.ts │ │ │ │ │ │ │ └── es.ts │ │ │ │ │ └── tsconfig.json │ │ │ │ ├── i18n-global-message │ │ │ │ │ ├── .env │ │ │ │ │ ├── src │ │ │ │ │ │ ├── components │ │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ │ ├── images │ │ │ │ │ │ │ │ ├── spain-flag.png │ │ │ │ │ │ │ │ └── english-flag.png │ │ │ │ │ │ │ ├── flag-container.styles.tsx │ │ │ │ │ │ │ ├── flag.styles.tsx │ │ │ │ │ │ │ └── flag.tsx │ │ │ │ │ │ ├── i18n │ │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ │ ├── languages.ts │ │ │ │ │ │ │ └── i18n.ts │ │ │ │ │ │ ├── translations │ │ │ │ │ │ │ ├── keys.ts │ │ │ │ │ │ │ ├── en.ts │ │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ │ └── es.ts │ │ │ │ │ │ └── form-validation.ts │ │ │ │ │ └── tsconfig.json │ │ │ │ ├── i18n-local-message │ │ │ │ │ ├── .env │ │ │ │ │ ├── src │ │ │ │ │ │ ├── components │ │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ │ ├── images │ │ │ │ │ │ │ │ ├── spain-flag.png │ │ │ │ │ │ │ │ └── english-flag.png │ │ │ │ │ │ │ ├── flag-container.styles.tsx │ │ │ │ │ │ │ ├── flag.styles.tsx │ │ │ │ │ │ │ └── flag.tsx │ │ │ │ │ │ ├── validation │ │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ │ └── use-validation.ts │ │ │ │ │ │ ├── i18n │ │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ │ ├── languages.ts │ │ │ │ │ │ │ └── i18n.ts │ │ │ │ │ │ └── translations │ │ │ │ │ │ │ ├── en.ts │ │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ │ ├── keys.ts │ │ │ │ │ │ │ └── es.ts │ │ │ │ │ └── tsconfig.json │ │ │ │ └── local-error-message │ │ │ │ │ ├── .env │ │ │ │ │ ├── tsconfig.json │ │ │ │ │ └── src │ │ │ │ │ └── form-validation.ts │ │ │ └── vanilla │ │ │ │ ├── global-error-message │ │ │ │ ├── tsconfig.json │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ │ └── form-validation.ts │ │ │ │ └── local-error-message │ │ │ │ ├── tsconfig.json │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ └── form-validation.ts │ │ └── js │ │ │ ├── react-final-form │ │ │ ├── i18n-full-example │ │ │ │ └── src │ │ │ │ │ ├── components │ │ │ │ │ ├── index.js │ │ │ │ │ ├── images │ │ │ │ │ │ ├── english-flag.png │ │ │ │ │ │ └── spain-flag.png │ │ │ │ │ ├── flag-container.styles.jsx │ │ │ │ │ ├── flag.jsx │ │ │ │ │ └── flag.styles.jsx │ │ │ │ │ ├── validation │ │ │ │ │ ├── index.js │ │ │ │ │ └── use-validation.js │ │ │ │ │ ├── i18n │ │ │ │ │ ├── index.js │ │ │ │ │ ├── languages.js │ │ │ │ │ └── i18n.js │ │ │ │ │ └── translations │ │ │ │ │ ├── index.js │ │ │ │ │ ├── keys.js │ │ │ │ │ ├── en.js │ │ │ │ │ └── es.js │ │ │ ├── i18n-local-message │ │ │ │ └── src │ │ │ │ │ ├── components │ │ │ │ │ ├── index.js │ │ │ │ │ ├── images │ │ │ │ │ │ ├── spain-flag.png │ │ │ │ │ │ └── english-flag.png │ │ │ │ │ ├── flag-container.styles.jsx │ │ │ │ │ ├── flag.jsx │ │ │ │ │ └── flag.styles.jsx │ │ │ │ │ ├── validation │ │ │ │ │ ├── index.js │ │ │ │ │ ├── use-validation.js │ │ │ │ │ └── form-validation.js │ │ │ │ │ ├── i18n │ │ │ │ │ ├── index.js │ │ │ │ │ ├── languages.js │ │ │ │ │ └── i18n.js │ │ │ │ │ └── translations │ │ │ │ │ ├── en.js │ │ │ │ │ ├── index.js │ │ │ │ │ ├── keys.js │ │ │ │ │ └── es.js │ │ │ ├── i18n-global-message │ │ │ │ └── src │ │ │ │ │ ├── components │ │ │ │ │ ├── index.js │ │ │ │ │ ├── images │ │ │ │ │ │ ├── spain-flag.png │ │ │ │ │ │ └── english-flag.png │ │ │ │ │ ├── flag-container.styles.jsx │ │ │ │ │ ├── flag.jsx │ │ │ │ │ └── flag.styles.jsx │ │ │ │ │ ├── i18n │ │ │ │ │ ├── index.js │ │ │ │ │ ├── languages.js │ │ │ │ │ └── i18n.js │ │ │ │ │ ├── translations │ │ │ │ │ ├── keys.js │ │ │ │ │ ├── en.js │ │ │ │ │ ├── index.js │ │ │ │ │ └── es.js │ │ │ │ │ └── form-validation.js │ │ │ ├── global-error-message │ │ │ │ ├── form-validation.js │ │ │ │ └── package.json │ │ │ └── local-error-message │ │ │ │ ├── form-validation.js │ │ │ │ └── package.json │ │ │ └── vanilla │ │ │ ├── global-error-message │ │ │ ├── src │ │ │ │ └── form-validation.js │ │ │ └── package.json │ │ │ └── local-error-message │ │ │ ├── package.json │ │ │ └── src │ │ │ └── form-validation.js │ ├── validators │ │ ├── ts │ │ │ ├── react-final-form │ │ │ │ ├── async-record-validator │ │ │ │ │ ├── .env │ │ │ │ │ ├── src │ │ │ │ │ │ ├── api.ts │ │ │ │ │ │ ├── form-validation.ts │ │ │ │ │ │ └── custom-validator.ts │ │ │ │ │ └── tsconfig.json │ │ │ │ └── iban-custom-sync-validator │ │ │ │ │ ├── .env │ │ │ │ │ ├── src │ │ │ │ │ ├── custom-validators │ │ │ │ │ │ └── index.ts │ │ │ │ │ └── form-validation.ts │ │ │ │ │ └── tsconfig.json │ │ │ └── vanilla │ │ │ │ ├── async-record-validator │ │ │ │ ├── src │ │ │ │ │ ├── model.ts │ │ │ │ │ ├── form-validation.ts │ │ │ │ │ ├── api.ts │ │ │ │ │ ├── custom-validator.ts │ │ │ │ │ └── helpers.ts │ │ │ │ ├── tsconfig.json │ │ │ │ ├── package.json │ │ │ │ └── index.html │ │ │ │ └── iban-custom-sync-validator │ │ │ │ ├── tsconfig.json │ │ │ │ ├── src │ │ │ │ └── form-validation.ts │ │ │ │ └── package.json │ │ └── js │ │ │ ├── react-final-form │ │ │ ├── iban-custom-sync-validator │ │ │ │ ├── custom-validators │ │ │ │ │ └── index.js │ │ │ │ ├── form-validation.js │ │ │ │ └── package.json │ │ │ └── async-record-validator │ │ │ │ ├── form-validation.js │ │ │ │ ├── api.js │ │ │ │ └── custom-validator.js │ │ │ └── vanilla │ │ │ ├── async-record-validator │ │ │ ├── src │ │ │ │ ├── form-validation.js │ │ │ │ ├── api.js │ │ │ │ ├── custom-validator.js │ │ │ │ └── helpers.js │ │ │ ├── package.json │ │ │ └── index.html │ │ │ └── iban-custom-sync-validator │ │ │ ├── src │ │ │ └── form-validation.js │ │ │ └── package.json │ ├── api │ │ ├── js │ │ │ ├── email │ │ │ │ ├── src │ │ │ │ │ └── form-validation.js │ │ │ │ ├── package.json │ │ │ │ └── readme.md │ │ │ ├── required │ │ │ │ ├── src │ │ │ │ │ └── form-validation.js │ │ │ │ ├── package.json │ │ │ │ └── readme.md │ │ │ ├── max-length │ │ │ │ ├── src │ │ │ │ │ └── form-validation.js │ │ │ │ └── package.json │ │ │ ├── min-length │ │ │ │ ├── src │ │ │ │ │ └── form-validation.js │ │ │ │ └── package.json │ │ │ ├── field-validator │ │ │ │ ├── src │ │ │ │ │ └── form-validation.js │ │ │ │ └── package.json │ │ │ ├── pattern │ │ │ │ ├── package.json │ │ │ │ └── readme.md │ │ │ └── record-validator │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ └── form-validation.js │ │ └── ts │ │ │ ├── email │ │ │ ├── tsconfig.json │ │ │ ├── src │ │ │ │ └── form-validation.ts │ │ │ ├── package.json │ │ │ └── readme.md │ │ │ ├── pattern │ │ │ ├── tsconfig.json │ │ │ ├── package.json │ │ │ └── readme.md │ │ │ ├── required │ │ │ ├── tsconfig.json │ │ │ ├── src │ │ │ │ └── form-validation.ts │ │ │ ├── package.json │ │ │ └── readme.md │ │ │ ├── max-length │ │ │ ├── tsconfig.json │ │ │ ├── src │ │ │ │ └── form-validation.ts │ │ │ └── package.json │ │ │ ├── min-length │ │ │ ├── tsconfig.json │ │ │ ├── src │ │ │ │ └── form-validation.ts │ │ │ └── package.json │ │ │ ├── field-validator │ │ │ ├── tsconfig.json │ │ │ ├── src │ │ │ │ └── form-validation.ts │ │ │ └── package.json │ │ │ └── record-validator │ │ │ ├── tsconfig.json │ │ │ ├── package.json │ │ │ └── src │ │ │ └── form-validation.ts │ └── general │ │ ├── ts │ │ └── validating-field │ │ │ ├── tsconfig.json │ │ │ ├── src │ │ │ └── form-validation.ts │ │ │ └── package.json │ │ └── js │ │ └── validating-field │ │ ├── src │ │ └── form-validation.js │ │ └── package.json ├── vue │ └── js │ │ ├── validate-field │ │ ├── src │ │ │ ├── custom-validators │ │ │ │ ├── index.js │ │ │ │ └── min-number.validator.js │ │ │ └── main.js │ │ ├── .gitignore │ │ └── public │ │ │ └── index.html │ │ ├── validate-form │ │ ├── src │ │ │ ├── custom-validators │ │ │ │ ├── index.js │ │ │ │ └── match-field.validator.js │ │ │ └── main.js │ │ ├── .gitignore │ │ └── public │ │ │ └── index.html │ │ ├── validate-record │ │ ├── src │ │ │ ├── custom-validators │ │ │ │ ├── index.js │ │ │ │ └── free-shipping.record-validator.js │ │ │ ├── main.js │ │ │ └── form-validation.js │ │ ├── .gitignore │ │ └── public │ │ │ └── index.html │ │ ├── validate-field-record-and-form │ │ ├── src │ │ │ ├── custom-validators │ │ │ │ ├── index.js │ │ │ │ └── free-shipping.record-validator.js │ │ │ ├── main.js │ │ │ └── form-validation.js │ │ ├── .gitignore │ │ └── public │ │ │ └── index.html │ │ └── nested-field │ │ ├── src │ │ ├── main.js │ │ └── form-validation.js │ │ ├── .gitignore │ │ └── public │ │ └── index.html ├── vanilla │ ├── js │ │ ├── validate-field │ │ │ ├── src │ │ │ │ └── custom-validators │ │ │ │ │ ├── index.js │ │ │ │ │ └── min-number.validator.js │ │ │ └── package.json │ │ ├── validate-form │ │ │ ├── src │ │ │ │ └── custom-validators │ │ │ │ │ ├── index.js │ │ │ │ │ └── match-field.validator.js │ │ │ └── package.json │ │ ├── async-validator │ │ │ ├── src │ │ │ │ ├── custom-validators │ │ │ │ │ ├── index.js │ │ │ │ │ └── user-exists-on-github.validator.js │ │ │ │ └── form-validation.js │ │ │ └── package.json │ │ ├── validate-record │ │ │ ├── src │ │ │ │ ├── custom-validators │ │ │ │ │ ├── index.js │ │ │ │ │ └── free-shipping.record-validator.js │ │ │ │ └── form-validation.js │ │ │ └── package.json │ │ ├── validate-field-record-and-form │ │ │ ├── src │ │ │ │ ├── custom-validators │ │ │ │ │ ├── index.js │ │ │ │ │ └── free-shipping.record-validator.js │ │ │ │ └── form-validation.js │ │ │ └── package.json │ │ ├── custom-validators │ │ │ ├── src │ │ │ │ └── custom-validators │ │ │ │ │ ├── index.js │ │ │ │ │ ├── is-number.validator.js │ │ │ │ │ └── min-number.validator.js │ │ │ └── package.json │ │ ├── nested-field │ │ │ ├── src │ │ │ │ ├── form-validation.js │ │ │ │ └── helpers.js │ │ │ └── package.json │ │ ├── custom-error-message │ │ │ ├── src │ │ │ │ └── form-validation.js │ │ │ └── package.json │ │ ├── shopping-cart-array-validator │ │ │ ├── index.html │ │ │ ├── src │ │ │ │ └── form-validation.js │ │ │ └── package.json │ │ └── multiple-user-creation-array-validator │ │ │ ├── index.html │ │ │ └── package.json │ └── ts │ │ ├── validate-field │ │ ├── src │ │ │ └── custom-validators │ │ │ │ ├── index.ts │ │ │ │ └── min-number.validator.ts │ │ ├── tsconfig.json │ │ └── package.json │ │ ├── validate-form │ │ ├── src │ │ │ └── custom-validators │ │ │ │ ├── index.ts │ │ │ │ └── match-field.validator.ts │ │ ├── tsconfig.json │ │ └── package.json │ │ ├── async-validator │ │ ├── src │ │ │ ├── custom-validators │ │ │ │ └── index.ts │ │ │ └── form-validation.ts │ │ ├── tsconfig.json │ │ └── package.json │ │ ├── validate-record │ │ ├── src │ │ │ ├── custom-validators │ │ │ │ ├── index.ts │ │ │ │ └── free-shipping.record-validator.ts │ │ │ └── form-validation.ts │ │ ├── tsconfig.json │ │ └── package.json │ │ ├── validate-field-record-and-form │ │ ├── src │ │ │ ├── custom-validators │ │ │ │ ├── index.ts │ │ │ │ └── free-shipping.record-validator.ts │ │ │ └── form-validation.ts │ │ ├── tsconfig.json │ │ └── package.json │ │ ├── custom-validators │ │ ├── src │ │ │ └── custom-validators │ │ │ │ ├── index.ts │ │ │ │ ├── is-number.validator.ts │ │ │ │ └── min-number.validator.ts │ │ ├── tsconfig.json │ │ └── package.json │ │ ├── nested-field │ │ ├── tsconfig.json │ │ ├── src │ │ │ ├── form-validation.ts │ │ │ └── helpers.ts │ │ └── package.json │ │ ├── custom-error-message │ │ ├── tsconfig.json │ │ ├── src │ │ │ └── form-validation.ts │ │ └── package.json │ │ ├── shopping-cart-array-validator │ │ ├── tsconfig.json │ │ ├── index.html │ │ ├── package.json │ │ └── src │ │ │ └── form-validation.ts │ │ └── multiple-user-creation-array-validator │ │ ├── tsconfig.json │ │ ├── index.html │ │ └── package.json └── formik │ └── js │ ├── async-validator │ ├── custom-validators │ │ ├── index.js │ │ └── user-exists-on-github.validator.js │ ├── form-validation.js │ └── package.json │ ├── record-validation │ ├── custom-validators │ │ ├── index.js │ │ └── free-shipping.record-validator.js │ ├── form-validation.js │ └── package.json │ ├── custom-validators │ ├── custom-validators │ │ ├── index.js │ │ ├── is-number.validator.js │ │ └── min-number.validator.js │ └── package.json │ ├── nested-field │ ├── form-validation.js │ └── package.json │ ├── basic │ ├── form-validation.js │ └── package.json │ ├── custom-error-message-global │ ├── form-validation.js │ └── package.json │ ├── custom-error-message-local │ ├── form-validation.js │ └── package.json │ ├── formik-components │ ├── form-validation.js │ └── package.json │ ├── field-level-validation │ ├── form-validation.js │ └── package.json │ ├── shopping-cart-array-validator │ ├── package.json │ └── form-validation.js │ └── multiple-user-creation-array-validator │ └── package.json ├── content ├── fonky.jpg └── validate-field.gif ├── .prettierrc ├── config └── test │ └── jest.json ├── .gitignore ├── typings └── model │ └── index.ts ├── .editorconfig ├── .babelrc ├── .github └── workflows │ └── ci.workflow.yml ├── tsconfig.json └── .vscode └── launch.json /src/validation-engine/index.ts: -------------------------------------------------------------------------------- 1 | export * from './validation-engine'; 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/nested-field/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-field/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-form/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=false 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/async-validator/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/custom-validators/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-record/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=false 2 | -------------------------------------------------------------------------------- /content/fonky.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/content/fonky.jpg -------------------------------------------------------------------------------- /examples/react-final-form/ts/custom-error-message/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/shopping-cart-array-validator/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/global-error-message/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/local-error-message/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-field-record-and-form/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=false 2 | -------------------------------------------------------------------------------- /content/validate-field.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/content/validate-field.gif -------------------------------------------------------------------------------- /examples/docs/validators/ts/react-final-form/async-record-validator/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/multiple-user-creation-array-validator/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /src/helpers/index.ts: -------------------------------------------------------------------------------- 1 | export * from './helpers'; 2 | import get from './get'; 3 | export { get }; 4 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "es5", 4 | "endOfLine": "lf" 5 | } 6 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/react-final-form/iban-custom-sync-validator/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true 2 | -------------------------------------------------------------------------------- /examples/vue/js/validate-field/src/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './min-number.validator'; 2 | -------------------------------------------------------------------------------- /examples/vue/js/validate-form/src/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './match-field.validator'; 2 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-field/src/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './min-number.validator'; 2 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-form/src/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './match-field.validator'; 2 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-field/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './min-number.validator'; 2 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-form/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './match-field.validator'; 2 | -------------------------------------------------------------------------------- /examples/formik/js/async-validator/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './user-exists-on-github.validator'; 2 | -------------------------------------------------------------------------------- /examples/formik/js/record-validation/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './free-shipping.record-validator'; 2 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-field/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './min-number.validator'; 2 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-form/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './match-field.validator'; 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-field/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './min-number.validator'; 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-form/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './match-field.validator'; 2 | -------------------------------------------------------------------------------- /examples/vue/js/validate-record/src/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './free-shipping.record-validator'; 2 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/components/index.js: -------------------------------------------------------------------------------- 1 | export * from './flag-container'; 2 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/validation/index.js: -------------------------------------------------------------------------------- 1 | export * from './use-validation'; 2 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/components/index.js: -------------------------------------------------------------------------------- 1 | export * from './flag-container'; 2 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/validation/index.js: -------------------------------------------------------------------------------- 1 | export * from './use-validation'; 2 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from './flag-container'; 2 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/validation/index.ts: -------------------------------------------------------------------------------- 1 | export * from './use-validation'; 2 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from './flag-container'; 2 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/validation/index.ts: -------------------------------------------------------------------------------- 1 | export * from './use-validation'; 2 | -------------------------------------------------------------------------------- /examples/vanilla/js/async-validator/src/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from "./user-exists-on-github.validator"; 2 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-record/src/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './free-shipping.record-validator'; 2 | -------------------------------------------------------------------------------- /examples/vanilla/ts/async-validator/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './user-exists-on-github.validator'; 2 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-record/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './free-shipping.record-validator'; 2 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/components/index.js: -------------------------------------------------------------------------------- 1 | export * from './flag-container'; 2 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from './flag-container'; 2 | -------------------------------------------------------------------------------- /examples/react-final-form/js/async-validator/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from "./user-exists-on-github.validator"; 2 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-record/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './free-shipping.record-validator'; 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/async-validator/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./user-exists-on-github.validator"; 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-record/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './free-shipping.record-validator'; 2 | -------------------------------------------------------------------------------- /examples/vue/js/validate-field-record-and-form/src/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './free-shipping.record-validator'; 2 | -------------------------------------------------------------------------------- /examples/docs/validators/js/react-final-form/iban-custom-sync-validator/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './iban.validator'; 2 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-field-record-and-form/src/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './free-shipping.record-validator'; 2 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-field-record-and-form/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './free-shipping.record-validator'; 2 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/react-final-form/iban-custom-sync-validator/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './iban.validator'; 2 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-field-record-and-form/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './free-shipping.record-validator'; 2 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-field-record-and-form/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './free-shipping.record-validator'; 2 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/i18n/index.js: -------------------------------------------------------------------------------- 1 | export * from "./language.context"; 2 | export * from './languages' 3 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/i18n/index.js: -------------------------------------------------------------------------------- 1 | export * from "./language.context"; 2 | export * from './languages' 3 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/i18n/index.js: -------------------------------------------------------------------------------- 1 | export * from "./language.context"; 2 | export * from './languages' 3 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/i18n/index.ts: -------------------------------------------------------------------------------- 1 | export * from './language.context'; 2 | export * from './languages' 3 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/i18n/index.ts: -------------------------------------------------------------------------------- 1 | export * from './language.context'; 2 | export * from './languages' 3 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/i18n/index.ts: -------------------------------------------------------------------------------- 1 | export * from './language.context'; 2 | export * from './languages' 3 | -------------------------------------------------------------------------------- /examples/formik/js/custom-validators/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './is-number.validator'; 2 | export * from './min-number.validator'; 3 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/vanilla/async-record-validator/src/model.ts: -------------------------------------------------------------------------------- 1 | export interface Process { 2 | name: string; 3 | cachedResult: string; 4 | } 5 | -------------------------------------------------------------------------------- /examples/vanilla/js/custom-validators/src/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './is-number.validator'; 2 | export * from './min-number.validator'; 3 | -------------------------------------------------------------------------------- /examples/vanilla/ts/custom-validators/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './is-number.validator'; 2 | export * from './min-number.validator'; 3 | -------------------------------------------------------------------------------- /src/mappers/index.ts: -------------------------------------------------------------------------------- 1 | export * from './field-schema.mapper'; 2 | export * from './record-schema.mapper'; 3 | export * from './validation-result.mappers'; 4 | -------------------------------------------------------------------------------- /examples/react-final-form/js/custom-validators/custom-validators/index.js: -------------------------------------------------------------------------------- 1 | export * from './is-number.validator'; 2 | export * from './min-number.validator'; 3 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/custom-validators/src/custom-validators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './is-number.validator'; 2 | export * from './min-number.validator'; 3 | -------------------------------------------------------------------------------- /src/validation-dispatcher/index.ts: -------------------------------------------------------------------------------- 1 | export * from './all-validations-dispatcher'; 2 | export * from './single-record-dispatcher'; 3 | export * from './single-field-dispatcher'; 4 | -------------------------------------------------------------------------------- /config/test/jest.json: -------------------------------------------------------------------------------- 1 | { 2 | "rootDir": "../../", 3 | "preset": "ts-jest", 4 | "restoreMocks": true, 5 | "modulePathIgnorePatterns": ["/examples", "/dist"] 6 | } 7 | -------------------------------------------------------------------------------- /src/model/index.ts: -------------------------------------------------------------------------------- 1 | export * from './validation-schema.model'; 2 | export * from './field-validator.model'; 3 | export * from './record-validator.model'; 4 | export * from './result.model'; 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist/ 4 | *.orig 5 | .idea/ 6 | */src/**/*.js.map 7 | *.log 8 | coverage/ 9 | .awcache/ 10 | .rpt2_cache 11 | react-app-env.d.ts 12 | .cache 13 | -------------------------------------------------------------------------------- /typings/model/index.ts: -------------------------------------------------------------------------------- 1 | export * from './validation-schema.model'; 2 | export * from './field-validator.model'; 3 | export * from './record-validator.model'; 4 | export * from './result.model'; 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /examples/vue/js/nested-field/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(App), 8 | }).$mount('#app') 9 | -------------------------------------------------------------------------------- /examples/vue/js/validate-field/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(App), 8 | }).$mount('#app') 9 | -------------------------------------------------------------------------------- /examples/vue/js/validate-form/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(App), 8 | }).$mount('#app') 9 | -------------------------------------------------------------------------------- /examples/vue/js/validate-record/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(App), 8 | }).$mount('#app') 9 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/i18n/languages.js: -------------------------------------------------------------------------------- 1 | export const languages = { 2 | en: 'en', 3 | es: 'es', 4 | }; 5 | 6 | export const languageList = [languages.en, languages.es]; 7 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/i18n/languages.js: -------------------------------------------------------------------------------- 1 | export const languages = { 2 | en: 'en', 3 | es: 'es', 4 | }; 5 | 6 | export const languageList = [languages.en, languages.es]; 7 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/i18n/languages.js: -------------------------------------------------------------------------------- 1 | export const languages = { 2 | en: 'en', 3 | es: 'es', 4 | }; 5 | 6 | export const languageList = [languages.en, languages.es]; 7 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/i18n/languages.ts: -------------------------------------------------------------------------------- 1 | export const languages = { 2 | en: 'en', 3 | es: 'es', 4 | }; 5 | 6 | export const languageList = [languages.en, languages.es]; 7 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/i18n/languages.ts: -------------------------------------------------------------------------------- 1 | export const languages = { 2 | en: 'en', 3 | es: 'es', 4 | }; 5 | 6 | export const languageList = [languages.en, languages.es]; 7 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/i18n/languages.ts: -------------------------------------------------------------------------------- 1 | export const languages = { 2 | en: 'en', 3 | es: 'es', 4 | }; 5 | 6 | export const languageList = [languages.en, languages.es]; 7 | -------------------------------------------------------------------------------- /examples/vue/js/validate-field-record-and-form/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(App), 8 | }).$mount('#app') 9 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/translations/index.js: -------------------------------------------------------------------------------- 1 | import { en } from './en'; 2 | import { es } from './es'; 3 | 4 | export const translations = { 5 | en, 6 | es, 7 | }; 8 | export * from './keys'; 9 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/translations/keys.js: -------------------------------------------------------------------------------- 1 | export const keys = { 2 | user: 'user', 3 | password: 'password', 4 | submit: 'submit', 5 | reset: 'reset', 6 | required: 'required', 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/translations/en.js: -------------------------------------------------------------------------------- 1 | export const en = { 2 | user: 'User', 3 | password: 'Password', 4 | submit: 'Submit', 5 | reset: 'Reset', 6 | required: 'Required field', 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/translations/index.js: -------------------------------------------------------------------------------- 1 | import { en } from './en'; 2 | import { es } from './es'; 3 | 4 | export const translations = { 5 | en, 6 | es, 7 | }; 8 | export * from './keys'; 9 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/translations/keys.js: -------------------------------------------------------------------------------- 1 | export const keys = { 2 | user: 'user', 3 | password: 'password', 4 | submit: 'submit', 5 | reset: 'reset', 6 | required: 'required', 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/translations/index.ts: -------------------------------------------------------------------------------- 1 | import { en } from './en'; 2 | import { es } from './es'; 3 | 4 | export const translations = { 5 | en, 6 | es, 7 | }; 8 | export * from './keys'; 9 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/translations/keys.ts: -------------------------------------------------------------------------------- 1 | export const keys = { 2 | user: 'user', 3 | password: 'password', 4 | submit: 'submit', 5 | reset: 'reset', 6 | required: 'required', 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/translations/en.ts: -------------------------------------------------------------------------------- 1 | export const en = { 2 | user: 'User', 3 | password: 'Password', 4 | submit: 'Submit', 5 | reset: 'Reset', 6 | required: 'Required field', 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/translations/index.ts: -------------------------------------------------------------------------------- 1 | import { en } from './en'; 2 | import { es } from './es'; 3 | 4 | export const translations = { 5 | en, 6 | es, 7 | }; 8 | export * from './keys'; 9 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/translations/keys.ts: -------------------------------------------------------------------------------- 1 | export const keys = { 2 | user: 'user', 3 | password: 'password', 4 | submit: 'submit', 5 | reset: 'reset', 6 | required: 'required', 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/components/images/english-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/examples/docs/messages/js/react-final-form/i18n-full-example/src/components/images/english-flag.png -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/components/images/spain-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/examples/docs/messages/js/react-final-form/i18n-full-example/src/components/images/spain-flag.png -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/components/images/spain-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/examples/docs/messages/js/react-final-form/i18n-global-message/src/components/images/spain-flag.png -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/translations/en.js: -------------------------------------------------------------------------------- 1 | export const en = { 2 | user: 'User', 3 | password: 'Password', 4 | submit: 'Submit', 5 | reset: 'Reset', 6 | required: 'Required field', 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/translations/index.js: -------------------------------------------------------------------------------- 1 | import { en } from './en'; 2 | import { es } from './es'; 3 | 4 | export const translations = { 5 | en, 6 | es, 7 | }; 8 | export * from './keys'; 9 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/components/images/spain-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/examples/docs/messages/js/react-final-form/i18n-local-message/src/components/images/spain-flag.png -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/components/images/english-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/examples/docs/messages/ts/react-final-form/i18n-full-example/src/components/images/english-flag.png -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/components/images/spain-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/examples/docs/messages/ts/react-final-form/i18n-full-example/src/components/images/spain-flag.png -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/components/images/spain-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/examples/docs/messages/ts/react-final-form/i18n-global-message/src/components/images/spain-flag.png -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/translations/en.ts: -------------------------------------------------------------------------------- 1 | export const en = { 2 | user: 'User', 3 | password: 'Password', 4 | submit: 'Submit', 5 | reset: 'Reset', 6 | required: 'Required field', 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/translations/index.ts: -------------------------------------------------------------------------------- 1 | import { en } from './en'; 2 | import { es } from './es'; 3 | 4 | export const translations = { 5 | en, 6 | es, 7 | }; 8 | export * from './keys'; 9 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/components/images/spain-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/examples/docs/messages/ts/react-final-form/i18n-local-message/src/components/images/spain-flag.png -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/components/images/english-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/examples/docs/messages/js/react-final-form/i18n-global-message/src/components/images/english-flag.png -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/components/images/english-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/examples/docs/messages/js/react-final-form/i18n-local-message/src/components/images/english-flag.png -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/components/images/english-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/examples/docs/messages/ts/react-final-form/i18n-global-message/src/components/images/english-flag.png -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/components/images/english-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lemoncode/fonk/HEAD/examples/docs/messages/ts/react-final-form/i18n-local-message/src/components/images/english-flag.png -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/translations/es.js: -------------------------------------------------------------------------------- 1 | export const es = { 2 | user: 'Usuario', 3 | password: 'Contraseña', 4 | submit: 'Enviar', 5 | reset: 'Reiniciar', 6 | required: 'Debe informar el campo', 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/translations/es.js: -------------------------------------------------------------------------------- 1 | export const es = { 2 | user: 'Usuario', 3 | password: 'Contraseña', 4 | submit: 'Enviar', 5 | reset: 'Reiniciar', 6 | required: 'Debe informar el campo', 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/translations/es.ts: -------------------------------------------------------------------------------- 1 | export const es = { 2 | user: 'Usuario', 3 | password: 'Contraseña', 4 | submit: 'Enviar', 5 | reset: 'Reiniciar', 6 | required: 'Debe informar el campo', 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/translations/es.ts: -------------------------------------------------------------------------------- 1 | export const es = { 2 | user: 'Usuario', 3 | password: 'Contraseña', 4 | submit: 'Enviar', 5 | reset: 'Reiniciar', 6 | required: 'Debe informar el campo', 7 | }; 8 | -------------------------------------------------------------------------------- /src/validators/pattern-helpers.ts: -------------------------------------------------------------------------------- 1 | const isEmptyValue = value => 2 | value === null || value === undefined || value === ''; 3 | 4 | export const isValidPattern = (value, pattern: RegExp): boolean => 5 | isEmptyValue(value) ? true : pattern.test(value); 6 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/components/flag-container.styles.jsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Container = styled.div` 4 | display: flex; 5 | justify-content: flex-end; 6 | padding: 1rem; 7 | `; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/components/flag-container.styles.tsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Container = styled.div` 4 | display: flex; 5 | justify-content: flex-end; 6 | padding: 1rem; 7 | `; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/components/flag-container.styles.jsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Container = styled.div` 4 | display: flex; 5 | justify-content: flex-end; 6 | padding: 1rem; 7 | `; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/components/flag-container.styles.jsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Container = styled.div` 4 | display: flex; 5 | justify-content: flex-end; 6 | padding: 1rem; 7 | `; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/components/flag-container.styles.tsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Container = styled.div` 4 | display: flex; 5 | justify-content: flex-end; 6 | padding: 1rem; 7 | `; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/components/flag-container.styles.tsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Container = styled.div` 4 | display: flex; 5 | justify-content: flex-end; 6 | padding: 1rem; 7 | `; 8 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env", 4 | [ 5 | { 6 | "env": { 7 | "development": { 8 | "sourceMaps": true, 9 | "retainLines": true 10 | } 11 | } 12 | } 13 | ] 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /examples/formik/js/custom-validators/custom-validators/is-number.validator.js: -------------------------------------------------------------------------------- 1 | export const isNumberValidator = ({ value }) => { 2 | const succeeded = !isNaN(value); 3 | return { 4 | succeeded, 5 | message: succeeded ? '' : 'Must be a number', 6 | type: 'IS_NUMBER', 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /examples/vanilla/js/custom-validators/src/custom-validators/is-number.validator.js: -------------------------------------------------------------------------------- 1 | export const isNumberValidator = ({ value }) => { 2 | const succeeded = !isNaN(value); 3 | return { 4 | succeeded, 5 | message: succeeded ? '' : 'Must be a number', 6 | type: 'IS_NUMBER', 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /examples/docs/api/js/email/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const validationSchema = { 4 | field: { 5 | email: [Validators.email], 6 | }, 7 | }; 8 | 9 | export const formValidation = createFormValidation(validationSchema); 10 | -------------------------------------------------------------------------------- /examples/react-final-form/js/custom-validators/custom-validators/is-number.validator.js: -------------------------------------------------------------------------------- 1 | export const isNumberValidator = ({ value }) => { 2 | const succeeded = !isNaN(value); 3 | return { 4 | succeeded, 5 | message: succeeded ? '' : 'Must be a number', 6 | type: 'IS_NUMBER', 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/components/flag.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import * as s from './flag.styles'; 3 | 4 | export const Flag = props => { 5 | const { icon, selected, onClick } = props; 6 | return ; 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/components/flag.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import * as s from './flag.styles'; 3 | 4 | export const Flag = props => { 5 | const { icon, selected, onClick } = props; 6 | return ; 7 | }; 8 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/components/flag.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import * as s from './flag.styles'; 3 | 4 | export const Flag = props => { 5 | const { icon, selected, onClick } = props; 6 | return ; 7 | }; 8 | -------------------------------------------------------------------------------- /examples/vue/js/nested-field/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const validationSchema = { 4 | field: { 5 | 'product.name': [Validators.required], 6 | }, 7 | }; 8 | 9 | export const formValidation = createFormValidation(validationSchema); 10 | -------------------------------------------------------------------------------- /examples/vanilla/js/nested-field/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const validationSchema = { 4 | field: { 5 | 'product.name': [Validators.required], 6 | }, 7 | }; 8 | 9 | export const formValidation = createFormValidation(validationSchema); 10 | -------------------------------------------------------------------------------- /examples/docs/api/ts/email/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/docs/api/ts/pattern/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/docs/api/ts/required/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/docs/api/ts/max-length/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/docs/api/ts/min-length/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/vanilla/ts/async-validator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/vanilla/ts/nested-field/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-field/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-form/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-record/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/vue/js/validate-form/src/custom-validators/match-field.validator.js: -------------------------------------------------------------------------------- 1 | export const matchFieldValidator = ({ value, values, customArgs }) => { 2 | const succeeded = value === values[customArgs.fieldId]; 3 | return { 4 | succeeded, 5 | message: succeeded ? '' : 'Must match', 6 | type: 'MATCH_FIELD', 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /examples/docs/api/ts/field-validator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/docs/api/ts/record-validator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-form/src/custom-validators/match-field.validator.js: -------------------------------------------------------------------------------- 1 | export const matchFieldValidator = ({ value, values, customArgs }) => { 2 | const succeeded = value === values[customArgs.fieldId]; 3 | return { 4 | succeeded, 5 | message: succeeded ? '' : 'Must match', 6 | type: 'MATCH_FIELD', 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /examples/vanilla/ts/custom-error-message/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/vanilla/ts/custom-validators/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/docs/general/ts/validating-field/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-form/custom-validators/match-field.validator.js: -------------------------------------------------------------------------------- 1 | export const matchFieldValidator = ({ value, values, customArgs }) => { 2 | const succeeded = value === values[customArgs.fieldId]; 3 | return { 4 | succeeded, 5 | message: succeeded ? '' : 'Must match', 6 | type: 'MATCH_FIELD', 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /examples/vanilla/ts/shopping-cart-array-validator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-field-record-and-form/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/vanilla/global-error-message/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/vanilla/local-error-message/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/vue/js/nested-field/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /examples/vue/js/validate-field/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /examples/vue/js/validate-form/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /examples/vue/js/validate-record/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/vanilla/async-record-validator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/formik/js/custom-validators/custom-validators/min-number.validator.js: -------------------------------------------------------------------------------- 1 | export const minNumberValidator = ({ value, customArgs }) => { 2 | const succeeded = isNaN(value) || value >= customArgs.min; 3 | return { 4 | succeeded, 5 | message: succeeded ? '' : `Should be greater than ${customArgs.min}`, 6 | type: 'MIN_NUMBER', 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-field/src/custom-validators/min-number.validator.js: -------------------------------------------------------------------------------- 1 | export const minNumberValidator = ({ value, customArgs }) => { 2 | const succeeded = isNaN(value) || value >= customArgs.min; 3 | return { 4 | succeeded, 5 | message: succeeded ? '' : `Should be greater than ${customArgs.min}`, 6 | type: 'MIN_NUMBER', 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /examples/vanilla/ts/multiple-user-creation-array-validator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/vue/js/validate-field/src/custom-validators/min-number.validator.js: -------------------------------------------------------------------------------- 1 | export const minNumberValidator = ({ value, customArgs }) => { 2 | const succeeded = isNaN(value) || value >= customArgs.min; 3 | return { 4 | succeeded, 5 | message: succeeded ? '' : `Should be greater than ${customArgs.min}`, 6 | type: 'MIN_NUMBER', 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /.github/workflows/ci.workflow.yml: -------------------------------------------------------------------------------- 1 | name: Continuos Integration 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | ci: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - name: Install 11 | run: npm ci 12 | - name: Build 13 | run: npm run build 14 | - name: Tests 15 | run: npm test 16 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/vanilla/iban-custom-sync-validator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "jsx": "preserve", 5 | "esModuleInterop": true, 6 | "sourceMap": true, 7 | "allowJs": true, 8 | "lib": ["es6", "dom"], 9 | "rootDir": "src", 10 | "moduleResolution": "node" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-field/custom-validators/min-number.validator.js: -------------------------------------------------------------------------------- 1 | export const minNumberValidator = ({ value, customArgs }) => { 2 | const succeeded = isNaN(value) || value >= customArgs.min; 3 | return { 4 | succeeded, 5 | message: succeeded ? '' : `Should be greater than ${customArgs.min}`, 6 | type: 'MIN_NUMBER', 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /examples/vanilla/js/custom-validators/src/custom-validators/min-number.validator.js: -------------------------------------------------------------------------------- 1 | export const minNumberValidator = ({ value, customArgs }) => { 2 | const succeeded = isNaN(value) || value >= customArgs.min; 3 | return { 4 | succeeded, 5 | message: succeeded ? '' : `Should be greater than ${customArgs.min}`, 6 | type: 'MIN_NUMBER', 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /examples/docs/api/ts/email/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | createFormValidation, 4 | ValidationSchema, 5 | } from '@lemoncode/fonk'; 6 | 7 | const validationSchema: ValidationSchema = { 8 | field: { 9 | email: [Validators.email], 10 | }, 11 | }; 12 | 13 | export const formValidation = createFormValidation(validationSchema); 14 | -------------------------------------------------------------------------------- /examples/formik/js/nested-field/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFormikValidation } from '@lemoncode/fonk-formik'; 3 | 4 | const validationSchema = { 5 | field: { 6 | 'product.name': [Validators.required], 7 | }, 8 | }; 9 | 10 | export const formValidation = createFormikValidation(validationSchema); 11 | -------------------------------------------------------------------------------- /examples/react-final-form/js/custom-validators/custom-validators/min-number.validator.js: -------------------------------------------------------------------------------- 1 | export const minNumberValidator = ({ value, customArgs }) => { 2 | const succeeded = isNaN(value) || value >= customArgs.min; 3 | return { 4 | succeeded, 5 | message: succeeded ? '' : `Should be greater than ${customArgs.min}`, 6 | type: 'MIN_NUMBER', 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /examples/vue/js/validate-field-record-and-form/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /examples/vanilla/ts/nested-field/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | ValidationSchema, 4 | createFormValidation, 5 | } from '@lemoncode/fonk'; 6 | 7 | const validationSchema: ValidationSchema = { 8 | field: { 9 | 'product.name': [Validators.required], 10 | }, 11 | }; 12 | 13 | export const formValidation = createFormValidation(validationSchema); 14 | -------------------------------------------------------------------------------- /examples/docs/validators/js/vanilla/async-record-validator/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { createFormValidation } from '@lemoncode/fonk'; 2 | import { processValidator } from './custom-validator'; 3 | 4 | const validationSchema = { 5 | record: { 6 | process: [processValidator], 7 | }, 8 | }; 9 | 10 | export const formValidation = createFormValidation(validationSchema); 11 | -------------------------------------------------------------------------------- /examples/react-final-form/js/nested-field/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | 4 | const validationSchema = { 5 | field: { 6 | 'product.name': [Validators.required], 7 | }, 8 | }; 9 | 10 | export const formValidation = createFinalFormValidation(validationSchema); 11 | -------------------------------------------------------------------------------- /examples/vue/js/validate-record/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { createFormValidation } from '@lemoncode/fonk'; 2 | import { freeShippingRecordValidator } from './custom-validators'; 3 | 4 | const validationSchema = { 5 | record: { 6 | freeShipping: [freeShippingRecordValidator], 7 | }, 8 | }; 9 | 10 | export const formValidation = createFormValidation(validationSchema); 11 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/components/flag.styles.jsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Flag = styled.img` 4 | cursor: pointer; 5 | border-radius: 50%; 6 | border: ${({ selected }) => (selected ? '1px solid #1976d2' : '')}; 7 | 8 | &:hover { 9 | box-shadow: 0 0 11px rgba(33, 33, 33, 0.2); 10 | } 11 | `; 12 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/components/flag.styles.jsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Flag = styled.img` 4 | cursor: pointer; 5 | border-radius: 50%; 6 | border: ${({ selected }) => (selected ? '1px solid #1976d2' : '')}; 7 | 8 | &:hover { 9 | box-shadow: 0 0 11px rgba(33, 33, 33, 0.2); 10 | } 11 | `; 12 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/components/flag.styles.jsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Flag = styled.img` 4 | cursor: pointer; 5 | border-radius: 50%; 6 | border: ${({ selected }) => (selected ? '1px solid #1976d2' : '')}; 7 | 8 | &:hover { 9 | box-shadow: 0 0 11px rgba(33, 33, 33, 0.2); 10 | } 11 | `; 12 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/components/flag.styles.tsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Flag = styled.img` 4 | cursor: pointer; 5 | border-radius: 50%; 6 | border: ${({ selected }) => (selected ? '1px solid #1976d2' : '')}; 7 | 8 | &:hover { 9 | box-shadow: 0 0 11px rgba(33, 33, 33, 0.2); 10 | } 11 | `; 12 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/components/flag.styles.tsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Flag = styled.img` 4 | cursor: pointer; 5 | border-radius: 50%; 6 | border: ${({ selected }) => (selected ? '1px solid #1976d2' : '')}; 7 | 8 | &:hover { 9 | box-shadow: 0 0 11px rgba(33, 33, 33, 0.2); 10 | } 11 | `; 12 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/components/flag.styles.tsx: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | export const Flag = styled.img` 4 | cursor: pointer; 5 | border-radius: 50%; 6 | border: ${({ selected }) => (selected ? '1px solid #1976d2' : '')}; 7 | 8 | &:hover { 9 | box-shadow: 0 0 11px rgba(33, 33, 33, 0.2); 10 | } 11 | `; 12 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-record/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { createFormValidation } from '@lemoncode/fonk'; 2 | import { freeShippingRecordValidator } from './custom-validators'; 3 | 4 | const validationSchema = { 5 | record: { 6 | freeShipping: [freeShippingRecordValidator], 7 | }, 8 | }; 9 | 10 | export const formValidation = createFormValidation(validationSchema); 11 | -------------------------------------------------------------------------------- /examples/formik/js/record-validation/form-validation.js: -------------------------------------------------------------------------------- 1 | import { createFormikValidation } from "@lemoncode/fonk-formik"; 2 | import { freeShippingRecordValidator } from "./custom-validators"; 3 | 4 | const validationSchema = { 5 | record: { 6 | freeShipping: [freeShippingRecordValidator] 7 | } 8 | }; 9 | 10 | export const formValidation = createFormikValidation(validationSchema); 11 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/translations/keys.js: -------------------------------------------------------------------------------- 1 | export const keys = { 2 | name: 'name', 3 | email: 'email', 4 | landline: 'landline', 5 | mobile: 'mobile', 6 | submit: 'submit', 7 | reset: 'reset', 8 | validations: { 9 | required: 'validations.required', 10 | email: 'validations.email', 11 | phone: 'validations.phone', 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/translations/keys.ts: -------------------------------------------------------------------------------- 1 | export const keys = { 2 | name: 'name', 3 | email: 'email', 4 | landline: 'landline', 5 | mobile: 'mobile', 6 | submit: 'submit', 7 | reset: 'reset', 8 | validations: { 9 | required: 'validations.required', 10 | email: 'validations.email', 11 | phone: 'validations.phone', 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /examples/vanilla/ts/custom-validators/src/custom-validators/is-number.validator.ts: -------------------------------------------------------------------------------- 1 | import { FieldValidationFunctionSync } from '@lemoncode/fonk'; 2 | 3 | export const isNumberValidator: FieldValidationFunctionSync = ({ value }) => { 4 | const succeeded = !isNaN(value); 5 | return { 6 | succeeded, 7 | message: succeeded ? '' : 'Must be a number', 8 | type: 'IS_NUMBER', 9 | }; 10 | }; 11 | -------------------------------------------------------------------------------- /examples/docs/validators/js/react-final-form/async-record-validator/form-validation.js: -------------------------------------------------------------------------------- 1 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 2 | import { processValidator } from './custom-validator'; 3 | 4 | const validationSchema = { 5 | record: { 6 | process: [processValidator], 7 | }, 8 | }; 9 | 10 | export const formValidation = createFinalFormValidation(validationSchema); 11 | -------------------------------------------------------------------------------- /examples/formik/js/basic/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFormikValidation } from '@lemoncode/fonk-formik'; 3 | 4 | const validationSchema = { 5 | field: { 6 | email: [ 7 | { 8 | validator: Validators.email, 9 | }, 10 | ], 11 | }, 12 | }; 13 | 14 | export const formValidation = createFormikValidation(validationSchema); 15 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-record/form-validation.js: -------------------------------------------------------------------------------- 1 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 2 | import { freeShippingRecordValidator } from './custom-validators'; 3 | 4 | const validationSchema = { 5 | record: { 6 | freeShipping: [freeShippingRecordValidator], 7 | }, 8 | }; 9 | 10 | export const formValidation = createFinalFormValidation(validationSchema); 11 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/custom-validators/src/custom-validators/is-number.validator.ts: -------------------------------------------------------------------------------- 1 | import { FieldValidationFunctionSync } from '@lemoncode/fonk'; 2 | 3 | export const isNumberValidator: FieldValidationFunctionSync = ({ value }) => { 4 | const succeeded = !isNaN(value); 5 | return { 6 | succeeded, 7 | message: succeeded ? '' : 'Must be a number', 8 | type: 'IS_NUMBER', 9 | }; 10 | }; 11 | -------------------------------------------------------------------------------- /examples/vanilla/js/async-validator/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | import { userExistsOnGithubValidator } from './custom-validators'; 3 | 4 | const validationSchema = { 5 | field: { 6 | user: [Validators.required, userExistsOnGithubValidator], 7 | }, 8 | }; 9 | 10 | export const formValidation = createFormValidation(validationSchema); 11 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/vanilla/async-record-validator/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { ValidationSchema, createFormValidation } from '@lemoncode/fonk'; 2 | import { processValidator } from './custom-validator'; 3 | 4 | const validationSchema: ValidationSchema = { 5 | record: { 6 | process: [processValidator], 7 | }, 8 | }; 9 | 10 | export const formValidation = createFormValidation(validationSchema); 11 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-record/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { ValidationSchema, createFormValidation } from '@lemoncode/fonk'; 2 | import { freeShippingRecordValidator } from './custom-validators'; 3 | 4 | const validationSchema: ValidationSchema = { 5 | record: { 6 | freeShipping: [freeShippingRecordValidator], 7 | }, 8 | }; 9 | 10 | export const formValidation = createFormValidation(validationSchema); 11 | -------------------------------------------------------------------------------- /examples/vanilla/js/custom-error-message/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const validationSchema = { 4 | field: { 5 | product: [ 6 | { 7 | validator: Validators.required, 8 | message: 'My custom error message', 9 | }, 10 | ], 11 | }, 12 | }; 13 | 14 | export const formValidation = createFormValidation(validationSchema); 15 | -------------------------------------------------------------------------------- /examples/docs/validators/js/vanilla/async-record-validator/src/api.js: -------------------------------------------------------------------------------- 1 | export const resolveProcessFromBackend = () => 2 | new Promise(resolve => { 3 | const time = Math.random() * 1000; 4 | setTimeout(() => { 5 | resolve(time <= 900 ? '✅' : '❌'); 6 | }, time); 7 | }); 8 | 9 | export const resolveProcessFromCache = () => { 10 | const time = Math.random() * 1000; 11 | return time <= 900 ? '✅' : '❌'; 12 | }; 13 | -------------------------------------------------------------------------------- /examples/formik/js/custom-error-message-global/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFormikValidation } from '@lemoncode/fonk-formik'; 3 | 4 | const validationSchema = { 5 | field: { 6 | product: [ 7 | { 8 | validator: Validators.required, 9 | }, 10 | ], 11 | }, 12 | }; 13 | 14 | export const formValidation = createFormikValidation(validationSchema); 15 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/translations/en.js: -------------------------------------------------------------------------------- 1 | export const en = { 2 | name: 'Name', 3 | email: 'Email', 4 | landline: 'Landline phone', 5 | mobile: 'Mobile phone', 6 | submit: 'Submit', 7 | reset: 'Reset', 8 | validations: { 9 | required: 'Required field', 10 | email: 'Not valid email address', 11 | phone: 'It has invalid format. Example: {{example}}', 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/translations/en.ts: -------------------------------------------------------------------------------- 1 | export const en = { 2 | name: 'Name', 3 | email: 'Email', 4 | landline: 'Landline phone', 5 | mobile: 'Mobile phone', 6 | submit: 'Submit', 7 | reset: 'Reset', 8 | validations: { 9 | required: 'Required field', 10 | email: 'Not valid email address', 11 | phone: 'It has invalid format. Example: {{example}}', 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /examples/docs/validators/js/react-final-form/async-record-validator/api.js: -------------------------------------------------------------------------------- 1 | export const resolveProcessFromBackend = () => 2 | new Promise(resolve => { 3 | const time = Math.random() * 1000; 4 | setTimeout(() => { 5 | resolve(time <= 900 ? '✅' : '❌'); 6 | }, time); 7 | }); 8 | 9 | export const resolveProcessFromCache = () => { 10 | const time = Math.random() * 1000; 11 | return time <= 900 ? '✅' : '❌'; 12 | }; 13 | -------------------------------------------------------------------------------- /examples/formik/js/record-validation/custom-validators/free-shipping.record-validator.js: -------------------------------------------------------------------------------- 1 | export const freeShippingRecordValidator = ({ values }) => { 2 | const succeeded = values.isPrime || values.price - values.discount > 20; 3 | 4 | return { 5 | succeeded, 6 | message: succeeded 7 | ? '' 8 | : 'Subscribe to prime service or total must be greater than 20USD', 9 | type: 'RECORD_FREE_SHIPPING', 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/nested-field/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | ValidationSchema, 4 | } from '@lemoncode/fonk'; 5 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 6 | 7 | const validationSchema: ValidationSchema = { 8 | field: { 9 | 'product.name': [Validators.required], 10 | }, 11 | }; 12 | 13 | export const formValidation = createFinalFormValidation(validationSchema); 14 | -------------------------------------------------------------------------------- /examples/vue/js/validate-record/src/custom-validators/free-shipping.record-validator.js: -------------------------------------------------------------------------------- 1 | export const freeShippingRecordValidator = ({ values }) => { 2 | const succeeded = values.isPrime || values.price - values.discount > 20; 3 | 4 | return { 5 | succeeded, 6 | message: succeeded 7 | ? '' 8 | : 'Subscribe to prime service or total must be greater than 20USD', 9 | type: 'RECORD_FREE_SHIPPING', 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-record/src/custom-validators/free-shipping.record-validator.js: -------------------------------------------------------------------------------- 1 | export const freeShippingRecordValidator = ({ values }) => { 2 | const succeeded = values.isPrime || values.price - values.discount > 20; 3 | 4 | return { 5 | succeeded, 6 | message: succeeded 7 | ? '' 8 | : 'Subscribe to prime service or total must be greater than 20USD', 9 | type: 'RECORD_FREE_SHIPPING', 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /examples/docs/api/js/required/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const validationSchema = { 4 | field: { 5 | login: [Validators.required], 6 | password: [ 7 | { 8 | validator: Validators.required, 9 | customArgs: { trim: false }, 10 | }, 11 | ], 12 | }, 13 | }; 14 | 15 | export const formValidation = createFormValidation(validationSchema); 16 | -------------------------------------------------------------------------------- /examples/docs/general/js/validating-field/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const validationSchema = { 4 | field: { 5 | user: [ 6 | Validators.required, 7 | { 8 | validator: Validators.minLength, 9 | customArgs: { length: 3 }, 10 | }, 11 | ], 12 | }, 13 | }; 14 | 15 | export const formValidation = createFormValidation(validationSchema); 16 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-record/custom-validators/free-shipping.record-validator.js: -------------------------------------------------------------------------------- 1 | export const freeShippingRecordValidator = ({ values }) => { 2 | const succeeded = values.isPrime || values.price - values.discount > 20; 3 | 4 | return { 5 | succeeded, 6 | message: succeeded 7 | ? '' 8 | : 'Subscribe to prime service or total must be greater than 20USD', 9 | type: 'RECORD_FREE_SHIPPING', 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/translations/es.js: -------------------------------------------------------------------------------- 1 | export const es = { 2 | name: 'Nombre', 3 | email: 'Email', 4 | landline: 'Teléfono fijo', 5 | mobile: 'Teléfono móvil', 6 | submit: 'Enviar', 7 | reset: 'Reiniciar', 8 | validations: { 9 | required: 'Debe informar el campo', 10 | email: 'La dirección de email no es válida', 11 | phone: 'Formato inválido. Ejemplo: {{example}}', 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/translations/es.ts: -------------------------------------------------------------------------------- 1 | export const es = { 2 | name: 'Nombre', 3 | email: 'Email', 4 | landline: 'Teléfono fijo', 5 | mobile: 'Teléfono móvil', 6 | submit: 'Enviar', 7 | reset: 'Reiniciar', 8 | validations: { 9 | required: 'Debe informar el campo', 10 | email: 'La dirección de email no es válida', 11 | phone: 'Formato inválido. Ejemplo: {{example}}', 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/vanilla/async-record-validator/src/api.ts: -------------------------------------------------------------------------------- 1 | export const resolveProcessFromBackend = (): Promise => 2 | new Promise(resolve => { 3 | const time = Math.random() * 1000; 4 | setTimeout(() => { 5 | resolve(time <= 900 ? '✅' : '❌'); 6 | }, time); 7 | }); 8 | 9 | export const resolveProcessFromCache = (): string => { 10 | const time = Math.random() * 1000; 11 | return time <= 900 ? '✅' : '❌'; 12 | }; 13 | -------------------------------------------------------------------------------- /examples/formik/js/async-validator/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFormikValidation } from '@lemoncode/fonk-formik'; 3 | import { userExistsOnGithubValidator } from './custom-validators'; 4 | 5 | const validationSchema = { 6 | field: { 7 | user: [Validators.required, userExistsOnGithubValidator], 8 | }, 9 | }; 10 | 11 | export const formValidation = createFormikValidation(validationSchema); 12 | -------------------------------------------------------------------------------- /examples/vue/js/validate-field-record-and-form/src/custom-validators/free-shipping.record-validator.js: -------------------------------------------------------------------------------- 1 | export const freeShippingRecordValidator = ({ values }) => { 2 | const succeeded = values.isPrime || values.price - values.discount > 20; 3 | 4 | return { 5 | succeeded, 6 | message: succeeded 7 | ? '' 8 | : 'Subscribe to prime service or total must be greater than 20USD', 9 | type: 'RECORD_FREE_SHIPPING', 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "es6", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true 15 | }, 16 | "include": ["./src/**/*"] 17 | } 18 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/components/flag.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import * as s from './flag.styles'; 3 | 4 | interface Props { 5 | icon: string; 6 | selected: boolean; 7 | onClick: () => void; 8 | } 9 | 10 | export const Flag: React.FunctionComponent = props => { 11 | const { icon, selected, onClick } = props; 12 | return ; 13 | }; 14 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/components/flag.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import * as s from './flag.styles'; 3 | 4 | interface Props { 5 | icon: string; 6 | selected: boolean; 7 | onClick: () => void; 8 | } 9 | 10 | export const Flag: React.FunctionComponent = props => { 11 | const { icon, selected, onClick } = props; 12 | return ; 13 | }; 14 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/components/flag.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import * as s from './flag.styles'; 3 | 4 | interface Props { 5 | icon: string; 6 | selected: boolean; 7 | onClick: () => void; 8 | } 9 | 10 | export const Flag: React.FunctionComponent = props => { 11 | const { icon, selected, onClick } = props; 12 | return ; 13 | }; 14 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-field-record-and-form/src/custom-validators/free-shipping.record-validator.js: -------------------------------------------------------------------------------- 1 | export const freeShippingRecordValidator = ({ values }) => { 2 | const succeeded = values.isPrime || values.price - values.discount > 20; 3 | 4 | return { 5 | succeeded, 6 | message: succeeded 7 | ? '' 8 | : 'Subscribe to prime service or total must be greater than 20USD', 9 | type: 'RECORD_FREE_SHIPPING', 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/react-final-form/async-record-validator/src/api.ts: -------------------------------------------------------------------------------- 1 | export const resolveProcessFromBackend = (): Promise => 2 | new Promise(resolve => { 3 | const time = Math.random() * 1000; 4 | setTimeout(() => { 5 | resolve(time <= 900 ? "✅" : "❌"); 6 | }, time); 7 | }); 8 | 9 | export const resolveProcessFromCache = (): string => { 10 | const time = Math.random() * 1000; 11 | return time <= 900 ? "✅" : "❌"; 12 | }; 13 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-field-record-and-form/custom-validators/free-shipping.record-validator.js: -------------------------------------------------------------------------------- 1 | export const freeShippingRecordValidator = ({ values }) => { 2 | const succeeded = values.isPrime || values.price - values.discount > 20; 3 | 4 | return { 5 | succeeded, 6 | message: succeeded 7 | ? '' 8 | : 'Subscribe to prime service or total must be greater than 20USD', 9 | type: 'RECORD_FREE_SHIPPING', 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /examples/docs/api/js/max-length/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const validationSchema = { 4 | field: { 5 | description: [ 6 | { 7 | validator: Validators.maxLength, 8 | customArgs: { length: 20 }, 9 | message: 'The max length is {{length}}', 10 | }, 11 | ], 12 | }, 13 | }; 14 | 15 | export const formValidation = createFormValidation(validationSchema); 16 | -------------------------------------------------------------------------------- /examples/docs/api/js/min-length/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const validationSchema = { 4 | field: { 5 | description: [ 6 | { 7 | validator: Validators.minLength, 8 | customArgs: { length: 10 }, 9 | message: 'The min length is {{length}}', 10 | }, 11 | ], 12 | }, 13 | }; 14 | 15 | export const formValidation = createFormValidation(validationSchema); 16 | -------------------------------------------------------------------------------- /examples/docs/api/ts/max-length/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const validationSchema = { 4 | field: { 5 | description: [ 6 | { 7 | validator: Validators.maxLength, 8 | customArgs: { length: 20 }, 9 | message: 'The max length is {{length}}', 10 | }, 11 | ], 12 | }, 13 | }; 14 | 15 | export const formValidation = createFormValidation(validationSchema); 16 | -------------------------------------------------------------------------------- /examples/vanilla/ts/async-validator/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | ValidationSchema, 4 | createFormValidation, 5 | } from '@lemoncode/fonk'; 6 | import { userExistsOnGithubValidator } from './custom-validators'; 7 | 8 | const validationSchema: ValidationSchema = { 9 | field: { 10 | user: [Validators.required, userExistsOnGithubValidator], 11 | }, 12 | }; 13 | 14 | export const formValidation = createFormValidation(validationSchema); 15 | -------------------------------------------------------------------------------- /examples/react-final-form/js/async-validator/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | import { userExistsOnGithubValidator } from './custom-validators'; 4 | 5 | const validationSchema = { 6 | field: { 7 | user: [Validators.required, userExistsOnGithubValidator], 8 | }, 9 | }; 10 | 11 | export const formValidation = createFinalFormValidation(validationSchema); 12 | -------------------------------------------------------------------------------- /src/validators/index.ts: -------------------------------------------------------------------------------- 1 | import * as required from './required'; 2 | import * as email from './email'; 3 | import * as pattern from './pattern'; 4 | import * as minLength from './min-length'; 5 | import * as maxLength from './max-length'; 6 | import * as array from './array'; 7 | import { parseMessageWithCustomArgs } from './validators.helpers'; 8 | 9 | export default { required, email, pattern, minLength, maxLength, array }; 10 | 11 | export { parseMessageWithCustomArgs }; 12 | -------------------------------------------------------------------------------- /examples/formik/js/custom-error-message-local/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFormikValidation } from '@lemoncode/fonk-formik'; 3 | 4 | const validationSchema = { 5 | field: { 6 | product: [ 7 | { 8 | validator: Validators.required, 9 | message: 'My custom error message', 10 | }, 11 | ], 12 | }, 13 | }; 14 | 15 | export const formValidation = createFormikValidation(validationSchema); 16 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/react-final-form/async-record-validator/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { ValidationSchema } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | import { processValidator } from './custom-validator'; 4 | 5 | const validationSchema: ValidationSchema = { 6 | record: { 7 | process: [processValidator], 8 | }, 9 | }; 10 | 11 | export const formValidation = createFinalFormValidation(validationSchema); 12 | -------------------------------------------------------------------------------- /examples/react-final-form/js/custom-error-message/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | 4 | const validationSchema = { 5 | field: { 6 | product: [ 7 | { 8 | validator: Validators.required, 9 | message: 'My custom error message', 10 | }, 11 | ], 12 | }, 13 | }; 14 | 15 | export const formValidation = createFinalFormValidation(validationSchema); 16 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-record/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { ValidationSchema } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | import { freeShippingRecordValidator } from './custom-validators'; 4 | 5 | const validationSchema: ValidationSchema = { 6 | record: { 7 | freeShipping: [freeShippingRecordValidator], 8 | }, 9 | }; 10 | 11 | export const formValidation = createFinalFormValidation(validationSchema); 12 | -------------------------------------------------------------------------------- /examples/vanilla/ts/custom-error-message/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | ValidationSchema, 4 | createFormValidation, 5 | } from '@lemoncode/fonk'; 6 | 7 | const validationSchema: ValidationSchema = { 8 | field: { 9 | product: [ 10 | { 11 | validator: Validators.required, 12 | message: 'My custom error message', 13 | }, 14 | ], 15 | }, 16 | }; 17 | 18 | export const formValidation = createFormValidation(validationSchema); 19 | -------------------------------------------------------------------------------- /examples/docs/api/js/field-validator/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const validationSchema = { 4 | field: { 5 | user: [Validators.required, Validators.email], 6 | password: [ 7 | Validators.required, 8 | { 9 | validator: Validators.minLength, 10 | customArgs: { length: 3 }, 11 | }, 12 | ], 13 | }, 14 | }; 15 | 16 | export const formValidation = createFormValidation(validationSchema); 17 | -------------------------------------------------------------------------------- /examples/docs/api/ts/required/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | createFormValidation, 4 | ValidationSchema, 5 | } from '@lemoncode/fonk'; 6 | 7 | const validationSchema: ValidationSchema = { 8 | field: { 9 | login: [Validators.required], 10 | password: [ 11 | { 12 | validator: Validators.required, 13 | customArgs: { trim: false }, 14 | }, 15 | ], 16 | }, 17 | }; 18 | 19 | export const formValidation = createFormValidation(validationSchema); 20 | -------------------------------------------------------------------------------- /examples/docs/general/ts/validating-field/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | createFormValidation, 4 | ValidationSchema, 5 | } from '@lemoncode/fonk'; 6 | 7 | const validationSchema: ValidationSchema = { 8 | field: { 9 | user: [ 10 | Validators.required, 11 | { 12 | validator: Validators.minLength, 13 | customArgs: { length: 3 }, 14 | }, 15 | ], 16 | }, 17 | }; 18 | 19 | export const formValidation = createFormValidation(validationSchema); 20 | -------------------------------------------------------------------------------- /examples/docs/validators/js/vanilla/async-record-validator/src/custom-validator.js: -------------------------------------------------------------------------------- 1 | import { resolveProcessFromBackend } from './api'; 2 | 3 | export const processValidator = ({ values }) => 4 | resolveProcessFromBackend().then(data => { 5 | const succeeded = values.cachedResult === data; 6 | return { 7 | succeeded, 8 | message: succeeded 9 | ? '' 10 | : `Please, review the process. The real result was ${data}`, 11 | type: 'RECORD_PROCESS', 12 | }; 13 | }); 14 | -------------------------------------------------------------------------------- /examples/docs/validators/js/react-final-form/async-record-validator/custom-validator.js: -------------------------------------------------------------------------------- 1 | import { resolveProcessFromBackend } from './api'; 2 | 3 | export const processValidator = ({ values }) => 4 | resolveProcessFromBackend().then(data => { 5 | const succeeded = values.cachedResult === data; 6 | return { 7 | succeeded, 8 | message: succeeded 9 | ? '' 10 | : `Please, review the process. The real result was ${data}`, 11 | type: 'RECORD_PROCESS', 12 | }; 13 | }); 14 | -------------------------------------------------------------------------------- /examples/docs/validators/js/vanilla/iban-custom-sync-validator/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { createFormValidation } from '@lemoncode/fonk'; 2 | import { ibanValidator } from './custom-validator'; 3 | 4 | const validationSchema = { 5 | field: { 6 | account: [ 7 | { 8 | validator: ibanValidator, 9 | customArgs: { 10 | countryCode: 'ES', 11 | }, 12 | }, 13 | ], 14 | }, 15 | }; 16 | 17 | export const formValidation = createFormValidation(validationSchema); 18 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/async-validator/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { Validators, ValidationSchema } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | import { userExistsOnGithubValidator } from './custom-validators'; 4 | 5 | const validationSchema: ValidationSchema = { 6 | field: { 7 | user: [Validators.required, userExistsOnGithubValidator], 8 | }, 9 | }; 10 | 11 | export const formValidation = createFinalFormValidation(validationSchema); 12 | -------------------------------------------------------------------------------- /examples/docs/api/ts/min-length/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | createFormValidation, 4 | ValidationSchema, 5 | } from '@lemoncode/fonk'; 6 | 7 | const validationSchema: ValidationSchema = { 8 | field: { 9 | description: [ 10 | { 11 | validator: Validators.minLength, 12 | customArgs: { length: 10 }, 13 | message: 'The min length is {{length}}', 14 | }, 15 | ], 16 | }, 17 | }; 18 | 19 | export const formValidation = createFormValidation(validationSchema); 20 | -------------------------------------------------------------------------------- /examples/docs/api/ts/field-validator/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation, ValidationSchema } from '@lemoncode/fonk'; 2 | 3 | const validationSchema: ValidationSchema = { 4 | field: { 5 | user: [Validators.required, Validators.email], 6 | password: [ 7 | Validators.required, 8 | { 9 | validator: Validators.minLength, 10 | customArgs: { length: 3 }, 11 | }, 12 | ], 13 | }, 14 | }; 15 | 16 | export const formValidation = createFormValidation(validationSchema); 17 | -------------------------------------------------------------------------------- /examples/docs/validators/js/react-final-form/iban-custom-sync-validator/form-validation.js: -------------------------------------------------------------------------------- 1 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 2 | import { ibanValidator} from './custom-validators'; 3 | 4 | const validationSchema = { 5 | field: { 6 | account: [ 7 | { 8 | validator: ibanValidator, 9 | customArgs: { 10 | countryCode: 'ES', 11 | }, 12 | }, 13 | ], 14 | }, 15 | }; 16 | 17 | export const formValidation = createFinalFormValidation(validationSchema); 18 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-form/src/custom-validators/match-field.validator.ts: -------------------------------------------------------------------------------- 1 | import { FieldValidationFunctionSync } from '@lemoncode/fonk'; 2 | 3 | interface MatchFieldArgs { 4 | fieldId: string; 5 | } 6 | 7 | export const matchFieldValidator: FieldValidationFunctionSync< 8 | MatchFieldArgs 9 | > = ({ value, values, customArgs }) => { 10 | const succeeded = value === values[customArgs.fieldId]; 11 | return { 12 | succeeded, 13 | message: succeeded ? '' : 'Must match', 14 | type: 'MATCH_FIELD', 15 | }; 16 | }; 17 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/custom-error-message/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | ValidationSchema 4 | } from "@lemoncode/fonk"; 5 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 6 | 7 | const validationSchema: ValidationSchema = { 8 | field: { 9 | product: [ 10 | { 11 | validator: Validators.required, 12 | message: "My custom error message" 13 | } 14 | ] 15 | } 16 | }; 17 | 18 | export const formValidation = createFinalFormValidation(validationSchema); 19 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/vanilla/iban-custom-sync-validator/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { createFormValidation, ValidationSchema } from '@lemoncode/fonk'; 2 | import { ibanValidator } from './custom-validator'; 3 | 4 | const validationSchema: ValidationSchema = { 5 | field: { 6 | account: [ 7 | { 8 | validator: ibanValidator, 9 | customArgs: { 10 | countryCode: 'ES', 11 | }, 12 | }, 13 | ], 14 | }, 15 | }; 16 | 17 | export const formValidation = createFormValidation(validationSchema); 18 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-form/src/custom-validators/match-field.validator.ts: -------------------------------------------------------------------------------- 1 | import { FieldValidationFunctionSync } from '@lemoncode/fonk'; 2 | 3 | interface MatchFieldArgs { 4 | fieldId: string; 5 | } 6 | 7 | export const matchFieldValidator: FieldValidationFunctionSync< 8 | MatchFieldArgs 9 | > = ({ value, values, customArgs }) => { 10 | const succeeded = value === values[customArgs.fieldId]; 11 | return { 12 | succeeded, 13 | message: succeeded ? '' : 'Must match', 14 | type: 'MATCH_FIELD', 15 | }; 16 | }; 17 | -------------------------------------------------------------------------------- /examples/vue/js/validate-field-record-and-form/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | import { freeShippingRecordValidator } from './custom-validators'; 3 | 4 | const validationSchema = { 5 | field: { 6 | product: [Validators.required], 7 | discount: [Validators.required], 8 | price: [Validators.required], 9 | }, 10 | record: { 11 | freeShipping: [freeShippingRecordValidator], 12 | }, 13 | }; 14 | 15 | export const formValidation = createFormValidation(validationSchema); 16 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | 4 | const validationSchema = { 5 | field: { 6 | user: [ 7 | { 8 | validator: Validators.required, 9 | }, 10 | ], 11 | password: [ 12 | { 13 | validator: Validators.required, 14 | }, 15 | ], 16 | }, 17 | }; 18 | 19 | export const formValidation = createFinalFormValidation(validationSchema); 20 | -------------------------------------------------------------------------------- /examples/docs/validators/js/vanilla/async-record-validator/src/helpers.js: -------------------------------------------------------------------------------- 1 | export const renderProcess = (process, index) => { 2 | const li = document.createElement('li'); 3 | li.textContent = `${process.name}: -> Result from cache: ${process.cachedResult}`; 4 | li.id = `process-${index}`; 5 | 6 | document.getElementById('processList').appendChild(li); 7 | }; 8 | 9 | export const updateContent = (text, index) => { 10 | const process = document.getElementById(`process-${index}`); 11 | process.textContent = `${process.textContent} ${text}`; 12 | }; 13 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-field-record-and-form/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | import { freeShippingRecordValidator } from './custom-validators'; 3 | 4 | const validationSchema = { 5 | field: { 6 | product: [Validators.required], 7 | discount: [Validators.required], 8 | price: [Validators.required], 9 | }, 10 | record: { 11 | freeShipping: [freeShippingRecordValidator], 12 | }, 13 | }; 14 | 15 | export const formValidation = createFormValidation(validationSchema); 16 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-record/src/custom-validators/free-shipping.record-validator.ts: -------------------------------------------------------------------------------- 1 | import { RecordValidationFunctionSync } from '@lemoncode/fonk'; 2 | 3 | export const freeShippingRecordValidator: RecordValidationFunctionSync = ({ 4 | values, 5 | }) => { 6 | const succeeded = values.isPrime || values.price - values.discount > 20; 7 | 8 | return { 9 | succeeded, 10 | message: succeeded 11 | ? '' 12 | : 'Subscribe to prime service or total must be greater than 20USD', 13 | type: 'RECORD_FREE_SHIPPING', 14 | }; 15 | }; 16 | -------------------------------------------------------------------------------- /examples/docs/api/js/email/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "email-js-example", 3 | "version": "1.0.0", 4 | "description": "email, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/api/ts/email/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "email-ts-example", 3 | "version": "1.0.0", 4 | "description": "email, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/vanilla/ts/custom-validators/src/custom-validators/min-number.validator.ts: -------------------------------------------------------------------------------- 1 | import { FieldValidationFunctionSync } from '@lemoncode/fonk'; 2 | 3 | interface MinNumberArgs { 4 | min: number; 5 | } 6 | 7 | export const minNumberValidator: FieldValidationFunctionSync = ({ 8 | value, 9 | customArgs, 10 | }) => { 11 | const succeeded = isNaN(value) || value >= customArgs.min; 12 | return { 13 | succeeded, 14 | message: succeeded ? '' : `Should be greater than ${customArgs.min}`, 15 | type: 'MIN_NUMBER', 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-field/src/custom-validators/min-number.validator.ts: -------------------------------------------------------------------------------- 1 | import { FieldValidationFunctionSync } from '@lemoncode/fonk'; 2 | 3 | interface MinNumberArgs { 4 | min: number; 5 | } 6 | 7 | export const minNumberValidator: FieldValidationFunctionSync = ({ 8 | value, 9 | customArgs, 10 | }) => { 11 | const succeeded = isNaN(value) || value >= customArgs.min; 12 | return { 13 | succeeded, 14 | message: succeeded ? '' : `Should be greater than ${customArgs.min}`, 15 | type: 'MIN_NUMBER', 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /examples/docs/api/js/pattern/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pattern-js-example", 3 | "version": "1.0.0", 4 | "description": "pattern, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/api/ts/pattern/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pattern-ts-example", 3 | "version": "1.0.0", 4 | "description": "pattern, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/messages/js/vanilla/global-error-message/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | // Spanish message 4 | Validators.required.setErrorMessage('Debe informar el campo'); 5 | 6 | const validationSchema = { 7 | field: { 8 | user: [Validators.required], 9 | password: [ 10 | { 11 | validator: Validators.required, 12 | customArgs: { trim: false }, 13 | }, 14 | ], 15 | }, 16 | }; 17 | 18 | export const formValidation = createFormValidation(validationSchema); 19 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-field/src/custom-validators/min-number.validator.ts: -------------------------------------------------------------------------------- 1 | import { FieldValidationFunctionSync } from '@lemoncode/fonk'; 2 | 3 | interface MinNumberArgs { 4 | min: number; 5 | } 6 | 7 | export const minNumberValidator: FieldValidationFunctionSync = ({ 8 | value, 9 | customArgs, 10 | }) => { 11 | const succeeded = isNaN(value) || value >= customArgs.min; 12 | return { 13 | succeeded, 14 | message: succeeded ? '' : `Should be greater than ${customArgs.min}`, 15 | type: 'MIN_NUMBER', 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-record/src/custom-validators/free-shipping.record-validator.ts: -------------------------------------------------------------------------------- 1 | import { RecordValidationFunctionSync } from '@lemoncode/fonk'; 2 | 3 | export const freeShippingRecordValidator: RecordValidationFunctionSync = ({ 4 | values, 5 | }) => { 6 | const succeeded = values.isPrime || values.price - values.discount > 20; 7 | 8 | return { 9 | succeeded, 10 | message: succeeded 11 | ? '' 12 | : 'Subscribe to prime service or total must be greater than 20USD', 13 | type: 'RECORD_FREE_SHIPPING', 14 | }; 15 | }; 16 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { createFormValidation, FormValidation } from './form-validation'; 2 | import Validators, { parseMessageWithCustomArgs } from './validators'; 3 | import { 4 | createDefaultValidationResult, 5 | createDefaultRecordValidationResult, 6 | createDefaultFormValidationResult, 7 | } from './model'; 8 | 9 | export { 10 | createFormValidation, 11 | Validators, 12 | parseMessageWithCustomArgs, 13 | createDefaultValidationResult, 14 | createDefaultRecordValidationResult, 15 | createDefaultFormValidationResult, 16 | FormValidation, 17 | }; 18 | -------------------------------------------------------------------------------- /examples/docs/api/js/required/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "required-js-example", 3 | "version": "1.0.0", 4 | "description": "required, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/api/ts/required/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "required-ts-example", 3 | "version": "1.0.0", 4 | "description": "required, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/custom-validators/src/custom-validators/min-number.validator.ts: -------------------------------------------------------------------------------- 1 | import { FieldValidationFunctionSync } from '@lemoncode/fonk'; 2 | 3 | interface MinNumberArgs { 4 | min: number; 5 | } 6 | 7 | export const minNumberValidator: FieldValidationFunctionSync = ({ 8 | value, 9 | customArgs, 10 | }) => { 11 | const succeeded = isNaN(value) || value >= customArgs.min; 12 | return { 13 | succeeded, 14 | message: succeeded ? '' : `Should be greater than ${customArgs.min}`, 15 | type: 'MIN_NUMBER', 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-field-record-and-form/src/custom-validators/free-shipping.record-validator.ts: -------------------------------------------------------------------------------- 1 | import { RecordValidationFunctionSync } from "@lemoncode/fonk"; 2 | 3 | export const freeShippingRecordValidator: RecordValidationFunctionSync = ({ 4 | values 5 | }) => { 6 | const succeeded = values.isPrime || values.price - values.discount > 20; 7 | 8 | return { 9 | succeeded, 10 | message: succeeded 11 | ? "" 12 | : "Subscribe to prime service or total must be greater than 20USD", 13 | type: "RECORD_FREE_SHIPPING" 14 | }; 15 | }; 16 | -------------------------------------------------------------------------------- /examples/docs/api/js/max-length/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "max-length-js-example", 3 | "version": "1.0.0", 4 | "description": "max-length, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/api/js/min-length/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "min-length-js-example", 3 | "version": "1.0.0", 4 | "description": "min-length, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/api/ts/max-length/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "max-length-ts-example", 3 | "version": "1.0.0", 4 | "description": "max-length, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/api/ts/min-length/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "min-length-ts-example", 3 | "version": "1.0.0", 4 | "description": "min-length, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-field-record-and-form/src/custom-validators/free-shipping.record-validator.ts: -------------------------------------------------------------------------------- 1 | import { RecordValidationFunctionSync } from "@lemoncode/fonk"; 2 | 3 | export const freeShippingRecordValidator: RecordValidationFunctionSync = ({ 4 | values 5 | }) => { 6 | const succeeded = values.isPrime || values.price - values.discount > 20; 7 | 8 | return { 9 | succeeded, 10 | message: succeeded 11 | ? "" 12 | : "Subscribe to prime service or total must be greater than 20USD", 13 | type: "RECORD_FREE_SHIPPING" 14 | }; 15 | }; 16 | -------------------------------------------------------------------------------- /examples/vanilla/js/nested-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nested-field-js-example", 3 | "version": "1.0.0", 4 | "description": "nested-field, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/vanilla/ts/nested-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nested-field-ts-example", 3 | "version": "1.0.0", 4 | "description": "nested-field, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/formik/js/formik-components/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFormikValidation } from '@lemoncode/fonk-formik'; 3 | 4 | const validationSchema = { 5 | field: { 6 | email: [ 7 | { 8 | validator: Validators.required, 9 | }, 10 | { 11 | validator: Validators.email, 12 | }, 13 | ], 14 | password: [ 15 | { 16 | validator: Validators.required, 17 | }, 18 | ], 19 | }, 20 | }; 21 | 22 | export const formValidation = createFormikValidation(validationSchema); 23 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-form/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-form-js-example", 3 | "version": "1.0.0", 4 | "description": "validate-form, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-form/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-form-ts-example", 3 | "version": "1.0.0", 4 | "description": "validate-form, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/api/js/field-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "field-validator-js-example", 3 | "version": "1.0.0", 4 | "description": "field-validator, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/api/ts/field-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "field-validator-ts-example", 3 | "version": "1.0.0", 4 | "description": "field-validator, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/validation/use-validation.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { useTranslation } from 'react-i18next'; 3 | import { LanguageContext } from '../i18n'; 4 | import { createFormValidation } from './form-validation'; 5 | 6 | export const useValidation = () => { 7 | const { language } = React.useContext(LanguageContext); 8 | const { t } = useTranslation(); 9 | 10 | const formValidation = React.useMemo(() => { 11 | return createFormValidation(t); 12 | }, [language]); 13 | 14 | return { formValidation }; 15 | }; 16 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/validation/use-validation.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { useTranslation } from 'react-i18next'; 3 | import { LanguageContext } from '../i18n'; 4 | import { createLoginValidation } from './form-validation'; 5 | 6 | export const useValidation = () => { 7 | const { language } = React.useContext(LanguageContext); 8 | const { t } = useTranslation(); 9 | 10 | const formValidation = React.useMemo(() => { 11 | return createLoginValidation(t); 12 | }, [language]); 13 | 14 | return { formValidation }; 15 | }; 16 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/validation/use-validation.ts: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { useTranslation } from 'react-i18next'; 3 | import { LanguageContext } from '../i18n'; 4 | import { createFormValidation } from './form-validation'; 5 | 6 | export const useValidation = () => { 7 | const { language } = React.useContext(LanguageContext); 8 | const { t } = useTranslation(); 9 | 10 | const formValidation = React.useMemo(() => { 11 | return createFormValidation(t); 12 | }, [language]); 13 | 14 | return { formValidation }; 15 | }; 16 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/validation/use-validation.ts: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { useTranslation } from 'react-i18next'; 3 | import { LanguageContext } from '../i18n'; 4 | import { createLoginValidation } from './form-validation'; 5 | 6 | export const useValidation = () => { 7 | const { language } = React.useContext(LanguageContext); 8 | const { t } = useTranslation(); 9 | 10 | const formValidation = React.useMemo(() => { 11 | return createLoginValidation(t); 12 | }, [language]); 13 | 14 | return { formValidation }; 15 | }; 16 | -------------------------------------------------------------------------------- /examples/formik/js/field-level-validation/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFormikValidation } from '@lemoncode/fonk-formik'; 3 | 4 | const validationSchema = { 5 | field: { 6 | email: [ 7 | { 8 | validator: Validators.required, 9 | }, 10 | { 11 | validator: Validators.email, 12 | }, 13 | ], 14 | password: [ 15 | { 16 | validator: Validators.required, 17 | }, 18 | ], 19 | }, 20 | }; 21 | 22 | export const formValidation = createFormikValidation(validationSchema); 23 | -------------------------------------------------------------------------------- /examples/vanilla/js/async-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "async-validator-js-example", 3 | "version": "1.0.0", 4 | "description": "async-validator, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-record/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-record-js-example", 3 | "version": "1.0.0", 4 | "description": "validate-record, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/vanilla/ts/async-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "async-validator-ts-example", 3 | "version": "1.0.0", 4 | "description": "async-validator, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-record/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-record-ts-example", 3 | "version": "1.0.0", 4 | "description": "validate-record, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/api/js/record-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "record-validator-js-example", 3 | "version": "1.0.0", 4 | "description": "record-validator, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/api/ts/record-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "record-validator-ts-example", 3 | "version": "1.0.0", 4 | "description": "record-validator, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/general/js/validating-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validating-field-js-example", 3 | "version": "1.0.0", 4 | "description": "validating-field, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/general/ts/validating-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validating-field-ts-example", 3 | "version": "1.0.0", 4 | "description": "validating-field, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { ValidationSchema, Validators } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | 4 | const validationSchema: ValidationSchema = { 5 | field: { 6 | user: [ 7 | { 8 | validator: Validators.required, 9 | }, 10 | ], 11 | password: [ 12 | { 13 | validator: Validators.required, 14 | }, 15 | ], 16 | }, 17 | }; 18 | 19 | export const formValidation = createFinalFormValidation(validationSchema); 20 | -------------------------------------------------------------------------------- /examples/vanilla/js/custom-validators/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-validators-js-example", 3 | "version": "1.0.0", 4 | "description": "custom-validators, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/vanilla/ts/custom-validators/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-validators-ts-example", 3 | "version": "1.0.0", 4 | "description": "custom-validators, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "node", 6 | "request": "launch", 7 | "name": "Jest selected file", 8 | "program": "${workspaceRoot}/node_modules/jest/bin/jest.js", 9 | "args": [ 10 | "${fileBasenameNoExtension}", 11 | "-c", 12 | "./config/test/jest.json", 13 | "--verbose", 14 | "-i", 15 | "--no-cache", 16 | "--watchAll" 17 | ], 18 | "console": "integratedTerminal", 19 | "internalConsoleOptions": "neverOpen" 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/vanilla/async-record-validator/src/custom-validator.ts: -------------------------------------------------------------------------------- 1 | import { RecordValidationFunctionAsync } from '@lemoncode/fonk'; 2 | import { resolveProcessFromBackend } from './api'; 3 | 4 | export const processValidator: RecordValidationFunctionAsync = ({ values }) => 5 | resolveProcessFromBackend().then(data => { 6 | const succeeded = values.cachedResult === data; 7 | return { 8 | succeeded, 9 | message: succeeded 10 | ? '' 11 | : `Please, review the process. The real result was ${data}`, 12 | type: 'RECORD_PROCESS', 13 | }; 14 | }); 15 | -------------------------------------------------------------------------------- /examples/vanilla/js/custom-error-message/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-error-message-js-example", 3 | "version": "1.0.0", 4 | "description": "custom-error-message, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/vanilla/ts/custom-error-message/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-error-message-ts-example", 3 | "version": "1.0.0", 4 | "description": "custom-error-message, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/vue/js/nested-field/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Fonk with Vue 8 | 9 | 10 | 13 |
14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/vue/js/validate-field/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Fonk with Vue 8 | 9 | 10 | 13 |
14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/vue/js/validate-form/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Fonk with Vue 8 | 9 | 10 | 13 |
14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/vue/js/validate-record/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Fonk with Vue 8 | 9 | 10 | 13 |
14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/formik/js/basic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with formik at form level.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "formik integration", 9 | "state management", 10 | "formik", 11 | "form", 12 | "fonk-formik", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-formik": "4.0.1", 19 | "formik": "2.0.3", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/docs/messages/js/vanilla/local-error-message/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "local-error-message-js-example", 3 | "version": "1.0.0", 4 | "description": "local-error-message, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/vanilla/local-error-message/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "local-error-message-ts-example", 3 | "version": "1.0.0", 4 | "description": "local-error-message, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/react-final-form/async-record-validator/src/custom-validator.ts: -------------------------------------------------------------------------------- 1 | import { RecordValidationFunctionAsync } from "@lemoncode/fonk"; 2 | import { resolveProcessFromBackend } from "./api"; 3 | 4 | export const processValidator: RecordValidationFunctionAsync = ({ values }) => 5 | resolveProcessFromBackend().then(data => { 6 | const succeeded = values.cachedResult === data; 7 | return { 8 | succeeded, 9 | message: succeeded 10 | ? "" 11 | : `Please, review the process. The real result was ${data}`, 12 | type: "RECORD_PROCESS" 13 | }; 14 | }); 15 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/react-final-form/iban-custom-sync-validator/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { ValidationSchema } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | import { ibanValidator } from './custom-validators'; 4 | 5 | const validationSchema: ValidationSchema = { 6 | field: { 7 | account: [ 8 | { 9 | validator: ibanValidator, 10 | customArgs: { 11 | countryCode: 'ES', 12 | }, 13 | }, 14 | ], 15 | }, 16 | }; 17 | 18 | export const formValidation = createFinalFormValidation(validationSchema); 19 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-field-record-and-form/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | ValidationSchema, 4 | createFormValidation, 5 | } from '@lemoncode/fonk'; 6 | import { freeShippingRecordValidator } from './custom-validators'; 7 | 8 | const validationSchema: ValidationSchema = { 9 | field: { 10 | product: [Validators.required], 11 | discount: [Validators.required], 12 | price: [Validators.required], 13 | }, 14 | record: { 15 | freeShipping: [freeShippingRecordValidator], 16 | }, 17 | }; 18 | 19 | export const formValidation = createFormValidation(validationSchema); 20 | -------------------------------------------------------------------------------- /examples/docs/messages/js/vanilla/global-error-message/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "global-error-message-js-example", 3 | "version": "1.0.0", 4 | "description": "global-error-message, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/vanilla/global-error-message/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "global-error-message-ts-example", 3 | "version": "1.0.0", 4 | "description": "global-error-message, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/formik/js/async-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with formik at form level.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "formik integration", 9 | "state management", 10 | "formik", 11 | "form", 12 | "fonk-formik", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-formik": "4.0.1", 19 | "formik": "2.0.3", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/formik/js/nested-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with formik at form level.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "formik integration", 9 | "state management", 10 | "formik", 11 | "form", 12 | "fonk-formik", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-formik": "4.0.1", 19 | "formik": "2.0.3", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-field-record-and-form/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | import { freeShippingRecordValidator } from './custom-validators'; 4 | 5 | const validationSchema = { 6 | field: { 7 | product: [Validators.required], 8 | discount: [Validators.required], 9 | price: [Validators.required], 10 | }, 11 | record: { 12 | freeShipping: [freeShippingRecordValidator], 13 | }, 14 | }; 15 | 16 | export const formValidation = createFinalFormValidation(validationSchema); 17 | -------------------------------------------------------------------------------- /examples/vue/js/validate-field-record-and-form/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Fonk with Vue 8 | 9 | 10 | 13 |
14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/docs/validators/js/vanilla/async-record-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "async-record-validator-js-example", 3 | "version": "1.0.0", 4 | "description": "async-record-validator, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/vanilla/async-record-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "async-record-validator-ts-example", 3 | "version": "1.0.0", 4 | "description": "async-record-validator, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/formik/js/custom-validators/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with formik at form level.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "formik integration", 9 | "state management", 10 | "formik", 11 | "form", 12 | "fonk-formik", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-formik": "4.0.1", 19 | "formik": "2.0.3", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/formik/js/formik-components/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with formik at form level.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "formik integration", 9 | "state management", 10 | "formik", 11 | "form", 12 | "fonk-formik", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-formik": "4.0.1", 19 | "formik": "2.0.3", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/global-error-message/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | 4 | // Spanish message 5 | Validators.required.setErrorMessage("Debe informar el campo"); 6 | 7 | const validationSchema = { 8 | field: { 9 | user: [Validators.required], 10 | password: [ 11 | { 12 | validator: Validators.required, 13 | customArgs: { trim: false }, 14 | }, 15 | ], 16 | }, 17 | }; 18 | 19 | export const formValidation = createFinalFormValidation(validationSchema); 20 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/vanilla/global-error-message/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | createFormValidation, 4 | ValidationSchema, 5 | } from '@lemoncode/fonk'; 6 | 7 | // Spanish message 8 | Validators.required.setErrorMessage('Debe informar el campo'); 9 | 10 | const validationSchema: ValidationSchema = { 11 | field: { 12 | user: [Validators.required], 13 | password: [ 14 | { 15 | validator: Validators.required, 16 | customArgs: { trim: false }, 17 | }, 18 | ], 19 | }, 20 | }; 21 | 22 | export const formValidation = createFormValidation(validationSchema); 23 | -------------------------------------------------------------------------------- /examples/formik/js/field-level-validation/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with formik at form level.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "formik integration", 9 | "state management", 10 | "formik", 11 | "form", 12 | "fonk-formik", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-formik": "4.0.1", 19 | "formik": "2.0.3", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/vanilla/async-record-validator/src/helpers.ts: -------------------------------------------------------------------------------- 1 | import { Process } from './model'; 2 | 3 | export const renderProcess = (process: Process, index: number) => { 4 | const li = document.createElement('li'); 5 | li.textContent = `${process.name}: -> Result from cache: ${process.cachedResult}`; 6 | li.id = `process-${index}`; 7 | 8 | document.getElementById('processList').appendChild(li); 9 | }; 10 | 11 | export const updateContent = (text: string, index: number) => { 12 | const process = document.getElementById(`process-${index}`); 13 | process.textContent = `${process.textContent} ${text}`; 14 | }; 15 | -------------------------------------------------------------------------------- /examples/formik/js/custom-error-message-global/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with formik at form level.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "formik integration", 9 | "state management", 10 | "formik", 11 | "form", 12 | "fonk-formik", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-formik": "4.0.1", 19 | "formik": "2.0.3", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/formik/js/custom-error-message-local/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with formik at form level.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "formik integration", 9 | "state management", 10 | "formik", 11 | "form", 12 | "fonk-formik", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-formik": "4.0.1", 19 | "formik": "2.0.3", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-field-record-and-form/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field-record-and-form-js-example", 3 | "version": "1.0.0", 4 | "description": "validate-field-record-and-form, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-field-record-and-form/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field-record-and-form-ts-example", 3 | "version": "1.0.0", 4 | "description": "validate-field-record-and-form, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/validators/js/vanilla/iban-custom-sync-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "iban-custom-sync-validator-js-example", 3 | "version": "1.0.0", 4 | "description": "iban-custom-sync-validator, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/vanilla/iban-custom-sync-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "iban-custom-sync-validator-ts-example", 3 | "version": "1.0.0", 4 | "description": "iban-custom-sync-validator, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "7.7.2", 19 | "parcel-bundler": "1.12.4", 20 | "sass": "1.23.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/vanilla/js/validate-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field-js-example", 3 | "version": "1.0.0", 4 | "description": "validate-field, javascript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0", 16 | "@lemoncode/fonk-is-number-validator": "1.1.2" 17 | }, 18 | "devDependencies": { 19 | "@babel/core": "7.7.2", 20 | "parcel-bundler": "1.12.4", 21 | "sass": "1.23.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/vanilla/ts/validate-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field-ts-example", 3 | "version": "1.0.0", 4 | "description": "validate-field, typescript example", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0", 16 | "@lemoncode/fonk-is-number-validator": "1.1.2" 17 | }, 18 | "devDependencies": { 19 | "@babel/core": "7.7.2", 20 | "parcel-bundler": "1.12.4", 21 | "sass": "1.23.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/docs/api/js/record-validator/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const freeShippingAllowed = ({ values }) => { 4 | const succeeded = values.subtotal - values.discount >= 30; 5 | return { 6 | type: 'RECORD_FREE_SHIPPING', 7 | succeeded, 8 | message: succeeded 9 | ? '' 10 | : 'Total must be greater than 30USD to get cost free shippings', 11 | }; 12 | }; 13 | 14 | const validationSchema = { 15 | record: { 16 | freeShippingValidation: [freeShippingAllowed], 17 | }, 18 | }; 19 | 20 | export const formValidation = createFormValidation(validationSchema); 21 | -------------------------------------------------------------------------------- /examples/docs/api/ts/record-validator/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const freeShippingAllowed = ({ values }) => { 4 | const succeeded = values.subtotal - values.discount >= 30; 5 | return { 6 | type: 'RECORD_FREE_SHIPPING', 7 | succeeded, 8 | message: succeeded 9 | ? '' 10 | : 'Total must be greater than 30USD to get cost free shippings', 11 | }; 12 | }; 13 | 14 | const validationSchema = { 15 | record: { 16 | freeShippingValidation: [freeShippingAllowed], 17 | }, 18 | }; 19 | 20 | export const formValidation = createFormValidation(validationSchema); 21 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/global-error-message/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { ValidationSchema, Validators } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | 4 | // Spanish message 5 | Validators.required.setErrorMessage('Debe informar el campo'); 6 | 7 | const validationSchema: ValidationSchema = { 8 | field: { 9 | user: [Validators.required], 10 | password: [ 11 | { 12 | validator: Validators.required, 13 | customArgs: { trim: false }, 14 | }, 15 | ], 16 | }, 17 | }; 18 | 19 | export const formValidation = createFinalFormValidation(validationSchema); 20 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-field-record-and-form/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | ValidationSchema 4 | } from "@lemoncode/fonk"; 5 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 6 | import { freeShippingRecordValidator } from "./custom-validators"; 7 | 8 | const validationSchema: ValidationSchema = { 9 | field: { 10 | product: [Validators.required], 11 | discount: [Validators.required], 12 | price: [Validators.required] 13 | }, 14 | record: { 15 | freeShipping: [freeShippingRecordValidator] 16 | } 17 | }; 18 | 19 | export const formValidation = createFinalFormValidation(validationSchema); 20 | -------------------------------------------------------------------------------- /examples/vanilla/js/shopping-cart-array-validator/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Javascript example 4 | 5 | 6 | 7 | 8 |
9 |

Validating a product list in shopping cart

10 | Add new products and check validations: 11 |
12 | 13 |
14 | 15 |

16 |       
17 |
18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/docs/messages/js/vanilla/local-error-message/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | 3 | const validationSchema = { 4 | field: { 5 | ibanAccount: [ 6 | { 7 | validator: Validators.pattern, 8 | customArgs: { pattern: /^ES\d*$/ }, 9 | message: 'Invalid IBAN number', 10 | }, 11 | ], 12 | bicAccount: [ 13 | { 14 | validator: Validators.pattern, 15 | customArgs: { pattern: /^BIC\d*$/ }, 16 | message: 'Invalid BIC number', 17 | }, 18 | ], 19 | }, 20 | }; 21 | 22 | export const formValidation = createFormValidation(validationSchema); 23 | -------------------------------------------------------------------------------- /examples/formik/js/record-validation/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with react-final-form at field level.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "react-final-form integration", 9 | "state management", 10 | "react-final-form", 11 | "form", 12 | "final-form", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-formik": "4.0.1", 19 | "formik": "2.0.3", 20 | "final-form": "4.20.1", 21 | "react": "16.13.1", 22 | "react-dom": "16.13.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/vanilla/js/multiple-user-creation-array-validator/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Javascript example 4 | 5 | 6 | 7 | 8 |
9 |

Validating a user list when it creates multiple users

10 | Add new user and check validations: 11 |
12 | 13 |
14 | 15 |

16 |       
17 |
18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/vanilla/js/nested-field/src/helpers.js: -------------------------------------------------------------------------------- 1 | export const setErrorsByIds = ids => newErrors => { 2 | ids.forEach(id => { 3 | const element = document.getElementById(`${id}-error`); 4 | element.textContent = newErrors[id].message; 5 | }); 6 | }; 7 | 8 | export const onValidateForm = (id, callback) => { 9 | const element = document.getElementById(id); 10 | element.onsubmit = e => { 11 | e.preventDefault(); 12 | callback(); 13 | }; 14 | }; 15 | 16 | export const onValidateField = (id, callback) => { 17 | const element = document.getElementById(id); 18 | element.oninput = event => callback(event); 19 | element.onblur = event => callback(event); 20 | }; 21 | -------------------------------------------------------------------------------- /examples/vanilla/ts/shopping-cart-array-validator/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | nested-field, typescript example 4 | 5 | 6 | 7 | 8 |
9 |

Validating a product list in shopping cart

10 | Add new products and check validations: 11 |
12 | 13 |
14 | 15 |

16 |       
17 |
18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/vanilla/js/shopping-cart-array-validator/src/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators, createFormValidation } from '@lemoncode/fonk'; 2 | import { isNumber } from '@lemoncode/fonk-is-number-validator'; 3 | 4 | const validationSchema = { 5 | field: { 6 | products: [ 7 | { 8 | validator: Validators.array, 9 | customArgs: { 10 | field: { 11 | name: [Validators.required], 12 | quantity: [Validators.required, isNumber], 13 | price: [Validators.required, isNumber], 14 | }, 15 | }, 16 | }, 17 | ], 18 | }, 19 | }; 20 | 21 | export const formValidation = createFormValidation(validationSchema); 22 | -------------------------------------------------------------------------------- /src/validators/length.ts: -------------------------------------------------------------------------------- 1 | export interface LengthArgs { 2 | length: number; 3 | } 4 | 5 | export function parseLengthParams( 6 | customParams: LengthArgs, 7 | errorMessage: string 8 | ) { 9 | const length = 10 | customParams.length === null ? NaN : Number(customParams.length); 11 | if (isNaN(length)) { 12 | throw new Error(errorMessage); 13 | } 14 | 15 | return length; 16 | } 17 | 18 | export function isLengthValid( 19 | value: any, 20 | length: number, 21 | validatorFn: (value: string, length: number) => boolean 22 | ): boolean { 23 | // Don't try to validate non string values 24 | return typeof value === 'string' ? validatorFn(value, length) : true; 25 | } 26 | -------------------------------------------------------------------------------- /examples/vanilla/ts/multiple-user-creation-array-validator/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | nested-field, typescript example 4 | 5 | 6 | 7 | 8 |
9 |

Validating a user list when it creates multiple users

10 | Add new user and check validations: 11 |
12 | 13 |
14 | 15 |

16 |       
17 |
18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/vanilla/js/shopping-cart-array-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "array-validator", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk in vanilla Javascript. How to validate a products list in shopping cart.", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0", 16 | "@lemoncode/fonk-is-number-validator": "1.1.2" 17 | }, 18 | "devDependencies": { 19 | "@babel/core": "7.7.2", 20 | "parcel-bundler": "1.12.4", 21 | "sass": "1.23.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/vanilla/ts/shopping-cart-array-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "array-validator", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk in vanilla Typescript. How to validate a products list in shopping cart.", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0", 16 | "@lemoncode/fonk-is-number-validator": "1.1.2" 17 | }, 18 | "devDependencies": { 19 | "@babel/core": "7.7.2", 20 | "parcel-bundler": "1.12.4", 21 | "sass": "1.23.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/formik/js/shopping-cart-array-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "array-validator", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with formik. How to validate a products list in shopping cart.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "formik integration", 9 | "state management", 10 | "formik", 11 | "form", 12 | "fonk-formik", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-formik": "4.0.1", 19 | "@lemoncode/fonk-is-number-validator": "1.1.2", 20 | "formik": "2.1.5", 21 | "react": "16.13.1", 22 | "react-dom": "16.13.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/vanilla/js/multiple-user-creation-array-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "array-validator", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk in vanilla Javascript. How to validate a user list when it creates multiple users.", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla javascript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0", 16 | "@lemoncode/fonk-match-field-validator": "1.0.1" 17 | }, 18 | "devDependencies": { 19 | "@babel/core": "7.7.2", 20 | "parcel-bundler": "1.12.4", 21 | "sass": "1.23.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/vanilla/ts/multiple-user-creation-array-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "array-validator", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk in vanilla Typescript. How to validate a user list when it creates multiple users.", 5 | "main": "index.html", 6 | "scripts": { 7 | "start": "parcel index.html --open" 8 | }, 9 | "keywords": [ 10 | "fonk", 11 | "form-validation", 12 | "vanilla typescript" 13 | ], 14 | "dependencies": { 15 | "@lemoncode/fonk": "1.4.0", 16 | "@lemoncode/fonk-match-field-validator": "1.0.1" 17 | }, 18 | "devDependencies": { 19 | "@babel/core": "7.7.2", 20 | "parcel-bundler": "1.12.4", 21 | "sass": "1.23.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/formik/js/async-validator/custom-validators/user-exists-on-github.validator.js: -------------------------------------------------------------------------------- 1 | export const userExistsOnGithubValidator = ({ value }) => { 2 | const validationResult = { 3 | type: 'GITHUB_USER_EXISTS', 4 | succeeded: false, 5 | message: 'The username exists on Github', 6 | }; 7 | 8 | return fetch(`https://api.github.com/users/${value}`).then(response => { 9 | // Status 404, User does not exists, so the given user is valid 10 | // Status 200, meaning user exists, so the given user is not valid 11 | return response.status === 404 12 | ? { 13 | ...validationResult, 14 | succeeded: true, 15 | message: '', 16 | } 17 | : validationResult; 18 | }); 19 | }; 20 | -------------------------------------------------------------------------------- /examples/formik/js/shopping-cart-array-validator/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFormikValidation } from '@lemoncode/fonk-formik'; 3 | import { isNumber } from '@lemoncode/fonk-is-number-validator'; 4 | 5 | const validationSchema = { 6 | field: { 7 | products: [ 8 | { 9 | validator: Validators.array, 10 | customArgs: { 11 | field: { 12 | name: [Validators.required], 13 | quantity: [Validators.required, isNumber], 14 | price: [Validators.required, isNumber], 15 | }, 16 | }, 17 | }, 18 | ], 19 | }, 20 | }; 21 | 22 | export const formValidation = createFormikValidation(validationSchema); 23 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/vanilla/local-error-message/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | createFormValidation, 4 | ValidationSchema, 5 | } from '@lemoncode/fonk'; 6 | 7 | const validationSchema: ValidationSchema = { 8 | field: { 9 | ibanAccount: [ 10 | { 11 | validator: Validators.pattern, 12 | customArgs: { pattern: /^ES\d*$/ }, 13 | message: 'Invalid IBAN number', 14 | }, 15 | ], 16 | bicAccount: [ 17 | { 18 | validator: Validators.pattern, 19 | customArgs: { pattern: /^BIC\d*$/ }, 20 | message: 'Invalid BIC number', 21 | }, 22 | ], 23 | }, 24 | }; 25 | 26 | export const formValidation = createFormValidation(validationSchema); 27 | -------------------------------------------------------------------------------- /examples/react-final-form/js/nested-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nested-field", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with react-final-form using nested field.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "react-final-form integration", 9 | "state management", 10 | "react-final-form", 11 | "form", 12 | "final-form", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-final-form": "2.3.4", 19 | "final-form": "4.20.1", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1", 22 | "react-final-form": "6.5.1", 23 | "styled-components": "4.4.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-form/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-form", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with react-final-form at form level.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "react-final-form integration", 9 | "state management", 10 | "react-final-form", 11 | "form", 12 | "final-form", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-final-form": "2.3.4", 19 | "final-form": "4.20.1", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1", 22 | "react-final-form": "6.5.1", 23 | "styled-components": "4.4.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/vanilla/js/async-validator/src/custom-validators/user-exists-on-github.validator.js: -------------------------------------------------------------------------------- 1 | export const userExistsOnGithubValidator = ({ value }) => { 2 | const validationResult = { 3 | type: "GITHUB_USER_EXISTS", 4 | succeeded: false, 5 | message: "The username exists on Github" 6 | }; 7 | 8 | return fetch(`https://api.github.com/users/${value}`).then(response => { 9 | // Status 404, User does not exists, so the given user is valid 10 | // Status 200, meaning user exists, so the given user is not valid 11 | return response.status === 404 12 | ? { 13 | ...validationResult, 14 | succeeded: true, 15 | message: "" 16 | } 17 | : validationResult; 18 | }); 19 | }; 20 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/local-error-message/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | 4 | const validationSchema = { 5 | field: { 6 | ibanAccount: [ 7 | { 8 | validator: Validators.pattern, 9 | customArgs: { pattern: /^ES\d*$/ }, 10 | message: 'Invalid IBAN number', 11 | }, 12 | ], 13 | bicAccount: [ 14 | { 15 | validator: Validators.pattern, 16 | customArgs: { pattern: /^BIC\d*$/ }, 17 | message: 'Invalid BIC number', 18 | }, 19 | ], 20 | }, 21 | }; 22 | 23 | export const formValidation = createFinalFormValidation(validationSchema); 24 | -------------------------------------------------------------------------------- /examples/formik/js/multiple-user-creation-array-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "array-validator", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with formik. How to validate a user list when it creates multiple users.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "formik integration", 9 | "state management", 10 | "formik", 11 | "form", 12 | "fonk-formik", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-formik": "4.0.1", 19 | "@lemoncode/fonk-match-field-validator": "1.0.1", 20 | "formik": "2.1.5", 21 | "react": "16.13.1", 22 | "react-dom": "16.13.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/react-final-form/js/async-validator/custom-validators/user-exists-on-github.validator.js: -------------------------------------------------------------------------------- 1 | export const userExistsOnGithubValidator = ({ value }) => { 2 | const validationResult = { 3 | type: "GITHUB_USER_EXISTS", 4 | succeeded: false, 5 | message: "The username exists on Github" 6 | }; 7 | 8 | return fetch(`https://api.github.com/users/${value}`).then(response => { 9 | // Status 404, User does not exists, so the given user is valid 10 | // Status 200, meaning user exists, so the given user is not valid 11 | return response.status === 404 12 | ? { 13 | ...validationResult, 14 | succeeded: true, 15 | message: "" 16 | } 17 | : validationResult; 18 | }); 19 | }; 20 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/validation/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | import { keys } from '../translations'; 4 | 5 | export const createLoginValidation = t => { 6 | const validationSchema = { 7 | field: { 8 | user: [ 9 | { 10 | validator: Validators.required, 11 | message: t(keys.required), 12 | }, 13 | ], 14 | password: [ 15 | { 16 | validator: Validators.required, 17 | message: t(keys.required), 18 | }, 19 | ], 20 | }, 21 | }; 22 | return createFinalFormValidation(validationSchema); 23 | }; 24 | -------------------------------------------------------------------------------- /examples/react-final-form/js/async-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "async-validator", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with react-final-form using async validator.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "react-final-form integration", 9 | "state management", 10 | "react-final-form", 11 | "form", 12 | "final-form", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-final-form": "2.3.4", 19 | "final-form": "4.20.1", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1", 22 | "react-final-form": "6.5.1", 23 | "styled-components": "4.4.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-record/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-record", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with react-final-form using validateRecord.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "react-final-form integration", 9 | "state management", 10 | "react-final-form", 11 | "form", 12 | "final-form", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-final-form": "2.3.4", 19 | "final-form": "4.20.1", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1", 22 | "react-final-form": "6.5.1", 23 | "styled-components": "4.4.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/react-final-form/js/custom-validators/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-validators", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with react-final-form using custom validators.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "react-final-form integration", 9 | "state management", 10 | "react-final-form", 11 | "form", 12 | "final-form", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-final-form": "2.3.4", 19 | "final-form": "4.20.1", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1", 22 | "react-final-form": "6.5.1", 23 | "styled-components": "4.4.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/react-final-form/js/shopping-cart-array-validator/form-validation.js: -------------------------------------------------------------------------------- 1 | import { Validators } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | import { isNumber } from '@lemoncode/fonk-is-number-validator'; 4 | 5 | const validationSchema = { 6 | field: { 7 | products: [ 8 | { 9 | validator: Validators.array, 10 | customArgs: { 11 | field: { 12 | name: [Validators.required], 13 | quantity: [Validators.required, isNumber], 14 | price: [Validators.required, isNumber], 15 | }, 16 | }, 17 | }, 18 | ], 19 | }, 20 | }; 21 | 22 | export const formValidation = createFinalFormValidation(validationSchema); 23 | -------------------------------------------------------------------------------- /examples/vanilla/ts/shopping-cart-array-validator/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validators, 3 | ValidationSchema, 4 | createFormValidation, 5 | } from '@lemoncode/fonk'; 6 | import { isNumber } from '@lemoncode/fonk-is-number-validator'; 7 | 8 | const validationSchema: ValidationSchema = { 9 | field: { 10 | products: [ 11 | { 12 | validator: Validators.array, 13 | customArgs: { 14 | field: { 15 | name: [Validators.required], 16 | quantity: [Validators.required, isNumber], 17 | price: [Validators.required, isNumber], 18 | }, 19 | }, 20 | }, 21 | ], 22 | }, 23 | }; 24 | 25 | export const formValidation = createFormValidation(validationSchema); 26 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/async-validator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/nested-field/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-field/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-form/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-record/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-full-example/src/i18n/i18n.js: -------------------------------------------------------------------------------- 1 | import i18next from 'i18next'; 2 | import { initReactI18next } from 'react-i18next'; 3 | import { languages } from './languages'; 4 | import { translations } from '../translations'; 5 | 6 | export const createI18n = language => { 7 | const i18n = i18next.createInstance().use(initReactI18next); 8 | 9 | i18n.init({ 10 | lng: language, 11 | fallbackLng: language, 12 | resources: { 13 | [languages.en]: { 14 | translation: { 15 | ...translations.en, 16 | }, 17 | }, 18 | [languages.es]: { 19 | translation: { 20 | ...translations.es, 21 | }, 22 | }, 23 | }, 24 | }); 25 | 26 | return i18n; 27 | }; 28 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-global-message/src/i18n/i18n.js: -------------------------------------------------------------------------------- 1 | import i18next from 'i18next'; 2 | import { initReactI18next } from 'react-i18next'; 3 | import { languages } from './languages'; 4 | import { translations } from '../translations'; 5 | 6 | export const createI18n = language => { 7 | const i18n = i18next.createInstance().use(initReactI18next); 8 | 9 | i18n.init({ 10 | lng: language, 11 | fallbackLng: language, 12 | resources: { 13 | [languages.en]: { 14 | translation: { 15 | ...translations.en, 16 | }, 17 | }, 18 | [languages.es]: { 19 | translation: { 20 | ...translations.es, 21 | }, 22 | }, 23 | }, 24 | }); 25 | 26 | return i18n; 27 | }; 28 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/i18n-local-message/src/i18n/i18n.js: -------------------------------------------------------------------------------- 1 | import i18next from 'i18next'; 2 | import { initReactI18next } from 'react-i18next'; 3 | import { languages } from './languages'; 4 | import { translations } from '../translations'; 5 | 6 | export const createI18n = language => { 7 | const i18n = i18next.createInstance().use(initReactI18next); 8 | 9 | i18n.init({ 10 | lng: language, 11 | fallbackLng: language, 12 | resources: { 13 | [languages.en]: { 14 | translation: { 15 | ...translations.en, 16 | }, 17 | }, 18 | [languages.es]: { 19 | translation: { 20 | ...translations.es, 21 | }, 22 | }, 23 | }, 24 | }); 25 | 26 | return i18n; 27 | }; 28 | -------------------------------------------------------------------------------- /examples/react-final-form/js/custom-error-message/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-error-message", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with react-final-form using custom error message.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "react-final-form integration", 9 | "state management", 10 | "react-final-form", 11 | "form", 12 | "final-form", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-final-form": "2.3.4", 19 | "final-form": "4.20.1", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1", 22 | "react-final-form": "6.5.1", 23 | "styled-components": "4.4.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/custom-error-message/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/custom-validators/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/local-error-message/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "local-error-message", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with react-final-form using local error message.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "react-final-form integration", 9 | "state management", 10 | "react-final-form", 11 | "form", 12 | "final-form", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-final-form": "2.3.4", 19 | "final-form": "4.20.1", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1", 22 | "react-final-form": "6.5.1", 23 | "styled-components": "4.4.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/shopping-cart-array-validator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/validate-field-record-and-form/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/docs/api/js/email/readme.md: -------------------------------------------------------------------------------- 1 | # Email example 2 | 3 | Example using `email` in vanilla Javascript. 4 | 5 | [![See email example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/lemoncode/fonk/tree/master/examples/docs/api/js/email) 6 | 7 | # About Basefactor + Lemoncode 8 | 9 | We are an innovating team of Javascript experts, passionate about turning your ideas into robust products. 10 | 11 | [Basefactor, consultancy by Lemoncode](http://www.basefactor.com) provides consultancy and coaching services. 12 | 13 | [Lemoncode](http://lemoncode.net/services/en/#en-home) provides training services. 14 | 15 | For the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend 16 | -------------------------------------------------------------------------------- /examples/docs/api/ts/email/readme.md: -------------------------------------------------------------------------------- 1 | # Email example 2 | 3 | Example using `email` in vanilla Typescript. 4 | 5 | [![See email example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/lemoncode/fonk/tree/master/examples/docs/api/ts/email) 6 | 7 | # About Basefactor + Lemoncode 8 | 9 | We are an innovating team of Javascript experts, passionate about turning your ideas into robust products. 10 | 11 | [Basefactor, consultancy by Lemoncode](http://www.basefactor.com) provides consultancy and coaching services. 12 | 13 | [Lemoncode](http://lemoncode.net/services/en/#en-home) provides training services. 14 | 15 | For the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend 16 | -------------------------------------------------------------------------------- /examples/docs/messages/js/react-final-form/global-error-message/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "global-error-message", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with react-final-form using global error message.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "react-final-form integration", 9 | "state management", 10 | "react-final-form", 11 | "form", 12 | "final-form", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-final-form": "2.3.4", 19 | "final-form": "4.20.1", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1", 22 | "react-final-form": "6.5.1", 23 | "styled-components": "4.4.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/global-error-message/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/local-error-message/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/local-error-message/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { ValidationSchema, Validators } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | 4 | const validationSchema: ValidationSchema = { 5 | field: { 6 | ibanAccount: [ 7 | { 8 | validator: Validators.pattern, 9 | customArgs: { pattern: /^ES\d*$/ }, 10 | message: 'Invalid IBAN number', 11 | }, 12 | ], 13 | bicAccount: [ 14 | { 15 | validator: Validators.pattern, 16 | customArgs: { pattern: /^BIC\d*$/ }, 17 | message: 'Invalid BIC number', 18 | }, 19 | ], 20 | }, 21 | }; 22 | 23 | export const formValidation = createFinalFormValidation(validationSchema); 24 | -------------------------------------------------------------------------------- /examples/docs/validators/js/vanilla/async-record-validator/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | async-record-validator, javascript example 4 | 5 | 6 | 7 | 8 |
9 |

Async record validator with Fonk and Plain Vanilla Javascript

10 |
11 |
12 | 15 | 18 |
19 |
    20 |
    21 |
    22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/react-final-form/async-record-validator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/vanilla/async-record-validator/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | async-record-validator, typescript example 4 | 5 | 6 | 7 | 8 |
    9 |

    Async record validator with Fonk and Plain Vanilla Typescript

    10 |
    11 |
    12 | 15 | 18 |
    19 |
      20 |
      21 |
      22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/multiple-user-creation-array-validator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/docs/api/js/pattern/readme.md: -------------------------------------------------------------------------------- 1 | # Pattern example 2 | 3 | Example using `pattern` in vanilla Javascript. 4 | 5 | [![See pattern example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/lemoncode/fonk/tree/master/examples/docs/api/js/pattern) 6 | 7 | # About Basefactor + Lemoncode 8 | 9 | We are an innovating team of Javascript experts, passionate about turning your ideas into robust products. 10 | 11 | [Basefactor, consultancy by Lemoncode](http://www.basefactor.com) provides consultancy and coaching services. 12 | 13 | [Lemoncode](http://lemoncode.net/services/en/#en-home) provides training services. 14 | 15 | For the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend 16 | -------------------------------------------------------------------------------- /examples/docs/api/ts/pattern/readme.md: -------------------------------------------------------------------------------- 1 | # Pattern example 2 | 3 | Example using `pattern` in vanilla Typescript. 4 | 5 | [![See pattern example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/lemoncode/fonk/tree/master/examples/docs/api/ts/pattern) 6 | 7 | # About Basefactor + Lemoncode 8 | 9 | We are an innovating team of Javascript experts, passionate about turning your ideas into robust products. 10 | 11 | [Basefactor, consultancy by Lemoncode](http://www.basefactor.com) provides consultancy and coaching services. 12 | 13 | [Lemoncode](http://lemoncode.net/services/en/#en-home) provides training services. 14 | 15 | For the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend 16 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-full-example/src/i18n/i18n.ts: -------------------------------------------------------------------------------- 1 | import i18next from 'i18next'; 2 | import { initReactI18next } from 'react-i18next'; 3 | import { languages } from './languages'; 4 | import { translations } from '../translations'; 5 | 6 | export const createI18n = (language: string): i18next.i18n => { 7 | const i18n = i18next.createInstance().use(initReactI18next); 8 | 9 | i18n.init({ 10 | lng: language, 11 | fallbackLng: language, 12 | resources: { 13 | [languages.en]: { 14 | translation: { 15 | ...translations.en, 16 | }, 17 | }, 18 | [languages.es]: { 19 | translation: { 20 | ...translations.es, 21 | }, 22 | }, 23 | }, 24 | }); 25 | 26 | return i18n; 27 | }; 28 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-global-message/src/i18n/i18n.ts: -------------------------------------------------------------------------------- 1 | import i18next from 'i18next'; 2 | import { initReactI18next } from 'react-i18next'; 3 | import { languages } from './languages'; 4 | import { translations } from '../translations'; 5 | 6 | export const createI18n = (language: string): i18next.i18n => { 7 | const i18n = i18next.createInstance().use(initReactI18next); 8 | 9 | i18n.init({ 10 | lng: language, 11 | fallbackLng: language, 12 | resources: { 13 | [languages.en]: { 14 | translation: { 15 | ...translations.en, 16 | }, 17 | }, 18 | [languages.es]: { 19 | translation: { 20 | ...translations.es, 21 | }, 22 | }, 23 | }, 24 | }); 25 | 26 | return i18n; 27 | }; 28 | -------------------------------------------------------------------------------- /examples/docs/messages/ts/react-final-form/i18n-local-message/src/i18n/i18n.ts: -------------------------------------------------------------------------------- 1 | import i18next from 'i18next'; 2 | import { initReactI18next } from 'react-i18next'; 3 | import { languages } from './languages'; 4 | import { translations } from '../translations'; 5 | 6 | export const createI18n = (language: string): i18next.i18n => { 7 | const i18n = i18next.createInstance().use(initReactI18next); 8 | 9 | i18n.init({ 10 | lng: language, 11 | fallbackLng: language, 12 | resources: { 13 | [languages.en]: { 14 | translation: { 15 | ...translations.en, 16 | }, 17 | }, 18 | [languages.es]: { 19 | translation: { 20 | ...translations.es, 21 | }, 22 | }, 23 | }, 24 | }); 25 | 26 | return i18n; 27 | }; 28 | -------------------------------------------------------------------------------- /examples/docs/validators/ts/react-final-form/iban-custom-sync-validator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": false, 7 | "noImplicitAny": false, 8 | "sourceMap": true, 9 | "jsx": "react", 10 | "noLib": false, 11 | "allowJs": true, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "lib": ["dom", "dom.iterable", "esnext"], 16 | "allowSyntheticDefaultImports": true, 17 | "strict": false, 18 | "forceConsistentCasingInFileNames": true, 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true 22 | }, 23 | "include": ["./src/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/docs/api/js/required/readme.md: -------------------------------------------------------------------------------- 1 | # Required example 2 | 3 | Example using `required` in vanilla Javascript. 4 | 5 | [![See required example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/lemoncode/fonk/tree/master/examples/docs/api/js/required) 6 | 7 | # About Basefactor + Lemoncode 8 | 9 | We are an innovating team of Javascript experts, passionate about turning your ideas into robust products. 10 | 11 | [Basefactor, consultancy by Lemoncode](http://www.basefactor.com) provides consultancy and coaching services. 12 | 13 | [Lemoncode](http://lemoncode.net/services/en/#en-home) provides training services. 14 | 15 | For the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend 16 | -------------------------------------------------------------------------------- /examples/docs/api/ts/required/readme.md: -------------------------------------------------------------------------------- 1 | # Required example 2 | 3 | Example using `required` in vanilla Typescript. 4 | 5 | [![See required example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/lemoncode/fonk/tree/master/examples/docs/api/ts/required) 6 | 7 | # About Basefactor + Lemoncode 8 | 9 | We are an innovating team of Javascript experts, passionate about turning your ideas into robust products. 10 | 11 | [Basefactor, consultancy by Lemoncode](http://www.basefactor.com) provides consultancy and coaching services. 12 | 13 | [Lemoncode](http://lemoncode.net/services/en/#en-home) provides training services. 14 | 15 | For the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend 16 | -------------------------------------------------------------------------------- /examples/docs/validators/js/react-final-form/iban-custom-sync-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "iban-custom-sync-validator", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with react-final-form using custom sync validator.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "react-final-form integration", 9 | "state management", 10 | "react-final-form", 11 | "form", 12 | "final-form", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-final-form": "2.3.4", 19 | "final-form": "4.20.1", 20 | "react": "16.13.1", 21 | "react-dom": "16.13.1", 22 | "react-final-form": "6.5.1", 23 | "styled-components": "4.4.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/react-final-form/ts/shopping-cart-array-validator/src/form-validation.ts: -------------------------------------------------------------------------------- 1 | import { Validators, ValidationSchema } from '@lemoncode/fonk'; 2 | import { createFinalFormValidation } from '@lemoncode/fonk-final-form'; 3 | import { isNumber } from '@lemoncode/fonk-is-number-validator'; 4 | 5 | const validationSchema: ValidationSchema = { 6 | field: { 7 | products: [ 8 | { 9 | validator: Validators.array, 10 | customArgs: { 11 | field: { 12 | name: [Validators.required], 13 | quantity: [Validators.required, isNumber], 14 | price: [Validators.required, isNumber], 15 | }, 16 | }, 17 | }, 18 | ], 19 | }, 20 | }; 21 | 22 | export const formValidation = createFinalFormValidation(validationSchema); 23 | -------------------------------------------------------------------------------- /examples/vanilla/ts/nested-field/src/helpers.ts: -------------------------------------------------------------------------------- 1 | export const setErrorsByIds = (ids: string[]) => newErrors => { 2 | ids.forEach(id => { 3 | const element = document.getElementById(`${id}-error`); 4 | if (element) { 5 | element.textContent = newErrors[id] ? newErrors[id].message : ''; 6 | } 7 | }); 8 | }; 9 | 10 | export const onValidateForm = (id: string, callback: () => void) => { 11 | const element = document.getElementById(id); 12 | element.onsubmit = e => { 13 | e.preventDefault(); 14 | callback(); 15 | }; 16 | }; 17 | 18 | export const onValidateField = (id: string, callback: (event) => void) => { 19 | const element = document.getElementById(id); 20 | element.oninput = event => callback(event); 21 | element.onblur = event => callback(event); 22 | }; 23 | -------------------------------------------------------------------------------- /examples/react-final-form/js/validate-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-field", 3 | "version": "1.0.0", 4 | "description": "Example integrating fonk with react-final-form at field level.", 5 | "keywords": [ 6 | "fonk", 7 | "form-validation", 8 | "react-final-form integration", 9 | "state management", 10 | "react-final-form", 11 | "form", 12 | "final-form", 13 | "react" 14 | ], 15 | "main": "index.js", 16 | "dependencies": { 17 | "@lemoncode/fonk": "1.4.0", 18 | "@lemoncode/fonk-final-form": "2.3.4", 19 | "@lemoncode/fonk-is-number-validator": "1.1.2", 20 | "final-form": "4.20.1", 21 | "react": "16.13.1", 22 | "react-dom": "16.13.1", 23 | "react-final-form": "6.5.1", 24 | "styled-components": "4.4.1" 25 | } 26 | } 27 | --------------------------------------------------------------------------------