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

basquiat

v0.0.38

Published

Basquiat is a Redux form library

Downloads

79

Readme

Bo$$Key

Bo$$Key is a Redux form library that generates a form reducer and container given a simple specification.

##Overview

  1. Installation
  2. API

##Installation

npm install --save basquiat 

API

Bo$$Key exports a single function with the following signature: config => [ formReducer, formContainer ]

Configuration

The config Bo$$Key accepts is an object with the following keys:

  {
    component,
    statePath,
    fieldMap,
    hydrate,
    onSubmit,
  }

component

type: React Component

The form component that you want wrapped by Bo$$Key.

Example

 const LoginForm = ({
  email,
  password,
  errors,
  onSubmit,
  processEmailOnChange,
  processEmailOnBlur,
  processPasswordOnChange,
  processPasswordOnBlur,
}) => (
  <form method="POST" onSubmit={onSubmit}>
      <input
          type="text"
          value={email}
          onChange={processEmailOnChange}
          onBlur={processEmailOnBlur}
      />
      
      <p className="form-error">{errors.email}</p>

      <input
          type="password"
          value={password}
          onChange={processPasswordOnChange}
          onBlur={processPasswordOnBlur}
      />
      
      <p className="form-error">{errors.password}</p>

      <button type="submit">Submit</button>
  </form>
)

statePath

type: [String] | String

The statePath specifies where in the Redux tree to find the form's state.

Examples

Simple Example
{
  ...,
  bo$$Form: formState
}

If the Redux tree has the above shape, the correct statePath would be:

"bo$$Form"
Nested Example
{
  ...,
  involedForm: {
    lessInvolvedForm: {
      bo$$Form: formState
  }
}

If the Redux tree has the above shape, the correct statePath would be:

['involvedForm', 'lessInvolvedForm', 'bo$$Form']

fieldMap

type: the fieldMap is a nested object with the following shape:

  {
    fieldName: {
     checks: check | [check],
     streamTransformation: [String],
     blurTransformation: [String],
     inititialValue: Any,
     optional: Boolean
    }
  }

Every key in a field's config is optional. If you don't need to specify anything, simply set the field to null, and it will default to the following configuration:

  fieldName: {
    checks: [requiredCheck],
    initialValue: '',
    optional: false
  }

checks

A check is an array of two functions.

The first function is a predicate that takes the field's value, and asserts a property.

The second function takes the field's name, and returns an error message. If the first function returns false, then the error message returned by the second function is set as the field's error.

You can specify a single check, or an array of checks. If you specify an array of checks, then the error message for the field will be the one produced by the first check to fail.

If you don't specify a field as optional, the requiredField check, which is defined interally is automatically set.

The requiredField check looks something like this:

[
  value => !isEmptyField(value),
  field => `${field} is a required field`
]
Example
const threeToTwenty = [
  [
    value => /^.{3,20}$/.test(value),
    field => `${field} must be 3 to 20 characters`
  ]
];

streamTransformations

Redux Transform is a peer dependency for Bo$$Key.

streamTransformations is an array that specifies the transformations you want to perform to the value onStream (i.e. onChange).

Example
['trim', 'capitalize', 'singleSpace']

blurTransformations

Exactly like streamTransformation, but carried out onBlur. This is especially useful for trimming.

initialValue

Lets you initialize a field's value.

optional

Lets you declare a field as optional

hydrate

hydrate is a function that takes whatever arguments you pass in, and return the slice of formState you want to hydrate.

onSubmit

type: Function | { motive: Function, prepForSubmit: Function shouldDispatch: Boolean }

If you pass a function to onSubmit, it will be treated as the motive function.

If a motive is passed as a prop to the form's component, then that will serve as the motive function. The prop takes precedence over the motive specified in the config object.

  motive: ownProps.motive ? ownProps.motive : onSubmit.motive

motive

motive is the function you want called onSubmit. This is generally the function that will send an AJAX request.

prepForSubmit

prepForSubmit is a function that lets you modify the data that motive is called with.

prepForSubmit defaults to the following:

  (formState, extraArguments = []) => [formState, ...extraArguments]

shouldDispatch

Lets you specify whether the motive should be dispatched or not. shouldDispatch defaults to true.