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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-validated-proxy

v0.1.0

Published

An approach to form validation in React that makes use of [ES6 Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy), by way of [**@poteto**](https://github.com/poteto)'s [`validated-proxy`](https://github.com/pote

Readme

react-validated-proxy

An approach to form validation in React that makes use of ES6 Proxy, by way of @poteto's validated-proxy library.

react-validated-proxy exports a single component <Validate>, which you can use to validate changes to any object.

Install

Note: this library is in alpha and is not ready for production use.

$ npm i react-validated-proxy

Example

import Validate from 'react-validated-proxy';
import { isPresent, hasLength } from './validations';

const user = {
  firstName: 'Billy',
  lastName: 'Bob',
  // ...
};

const Adult = {
  firstName: [isPresent(), hasLength({ min: 2 })],
  lastName: [isPresent(), hasLength({ min: 2 })],
  // ...
};

<Validate model={user} as={Adult}>
  {({ model, set, reset, isPristine, hasErrors, flush }) => (
    <form onSubmit={flush}>
      <input type="text" value={model.firstName} onChange={e => set('firstName', e.target.value)} />
      <input type="text" value={model.lastName} onChange={e => set('lastName', e.target.value)} />
      <button type="submit" disabled={isPristine || hasErrors}>Save</button>
      <button type="button" onClick={reset}>Reset</button>
    </form>
  )}
</Validate>

See the full code for this example under example/. You can also clone this repo and run npm install && npm start to see the example running live.

Rationale

ES6 Proxies have many cool use cases – one of which is validating changes to objects. You can modify an object as you normally would, and a Proxy can intercept those modifications to add custom behavior.

In the case of this library, the <Validate> component accepts a model object, as well as a map of validations in the format defined by validated-proxy. <Validate> will then wrap your model in a Proxy, and pass the Proxy to your children render prop. You can then interact with the Proxy as your model, but with the added benefit of knowing when and why changes to the model are invalid. (Specifically, you can easily retrieve error messages from the Proxy.)

react-validated-proxy owes its existence to validated-proxy and ember-changeset by Lauren Tan. It's mostly an experiment in distilling ember-changeset to its framework-agnostic core.

API

<Validate model={T} as={IValidationMap}>...</Validate>

Pass in a data model that you want to validate, as well as a validation map of validators for your data model. The validation map should be in the format expected by validated-proxy.

const user = {
  firstName: 'Jim',
  lastName: 'Bob',
  age: 15,
};

const Adult = {
  firstName: [isPresent(), hasLength({ min: 2 })],
  lastName: [isPresent(), hasLength({ min: 2 })],
  age: isNumber({ op: '>=', value: 18 }),
};

<Validate model={user} as={Adult}>
  {({ model, set, reset, isPristine, hasErrors, flush }) => (
    <form>{/* ... */}</form>
  )}
</Validate>

<Validate> accepts a render prop as its children, and will pass the wrapped model (and some helper properties and functions) to the render prop:

interface HelperProps {
  model: BufferedProxy
  set: <T>(name: string, value: T) => void
  reset: () => void
  isPristine: boolean
  hasErrors: boolean
  flush: () => void
}

Jason Tu · GitHub @nucleartide · Twitter @nucleartide