npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

feathers-hooks-yup

v1.0.1

Published

Feathers hook utility for schema validation and sanitization using YUP.

Downloads

2

Readme

feathers-hooks-yup

Feathers hook utility for schema validation and sanitization using Yup. Error messages are converted to web/mobile friendly formats, and optionally translated for clarity or internationalization.

Supports both JS and Typescript.

The reason I decided to do this, because I found that using Yup clientside with react is the recommended approach. but I did not want to rewrite the rules in JOI or any other validation framework that are already available. this hook allows me to simply share the validations from the clientside.

Build Status Coverage Status

Code Example

import * as Yup from "yup";
import {Hook, HookContext} from '@feathersjs/feathers';
import {BadRequest} from '@feathersjs/errors';

const yupSchema = Yup.object({
  email: Yup.string()
    .email("invalid email")
    .required("email required"),
  retypeEmail: Yup.string()
    .oneOf([Yup.ref('email'), undefined], 'email not equal')
    .required("must enter email again"),
  password: Yup.string()
    .required('must enter password')
    .min(8, 'password must be 8 letters')
    .matches(/[a-zA-Z0-9]/, 'error ...'),
  acceptedTerms: Yup.boolean()
    .required("Required")
    .oneOf([true], "must accept terms"),
});
export default yupSchema;
import yupValidationHook from 'feathers-hook-yup';
import yupSchema from './yupSchema.js';
const yupOptions = {abortEarly: false};
export.before = {
  create: [ yupValidationHook(yupSchema, yupOptions, translationMethod) ],
  update: [ yupValidationHook(yupSchema, yupOptions, translationMethod) ],
  patch: [ yupValidationHook(yupSchema, yupOptions, translationMethod) ]
};

(3) Internationalize or clarify Joi error messages.

Translation method example:

//some translating logic...
function i18n(str) { return str; } // internationalization
const translationMethod = (formattedErrors) => {
        for(const errorKey in formattedErrors){
            formattedErrors[errorKey] = i18n(formattedErrors[errorKey]);
        }
        return formattedErrors;
    }

export.before = {
  create: [ yupValidationHook(yupSchema, yupOptions, translationMethod) ],
};

Motivation

Installation

Install Nodejs.

Run npm install feathers-hooks-yup --save in your project folder.
or
Run yarn add feathers-hooks-yup in your project folder.
You can then require the utilities.

API Reference

To do.

Tests

To do. npm test to run tests.

npm run cover to run tests plus coverage.

Contributors

Credit

  • logicwind for taking their readme as an example, and for the inspiration to set up this package.

License

MIT. See LICENSE.