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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ldform

v0.1.3

Published

form validation tool

Readme

ldform

Form validation helper

Usage

form = new ldform(config);

ldform automatically scan every input fields by \*[name] selector, so you must provide name attributes for each input or .form-control element:

<input type="text" name="username"/>
<textarea class="form-control" name="description"/>

Or, you can specify your own getFields function to apply your own rules.

Additionally, if you have an element with its type being 'submit', ldform will automatically remove it's 'disabled' class when validation passed. You can overwrite this behavior by manually specify a submit element with submit option.

For nested form, simply add a ldform attribute as scoping element to separate them:

<div ldform>
  <input name="a">
  <div ldform>
    <!-- b is scoped and won't be handled, unless we have another ldform over #form2 -->
    <input name="b">
  </form>
</form>

Configurations

  • root: base element for this form. HTMLElement or CSS Selector. Required.

  • init(): init function.

  • verify(name, value, element): validation function.

    • input:
      • name: field name
      • value: field value
      • element: field element
    • returns: status value ( see Status Object below )
    • optional. if omitted, ldform will check against emptiness.
  • getFields(root): customized rules for getting fields. input: root - root element for ldform return: fields object ( see below ) if omitted, default to use selector \*[name]

  • names(status, fields): return list of name for fields to check. if omitted, default to all fields.

    • input:
      • status: status object, see below
      • fields: field elements object.
  • afterCheck(status, fields): custom function for doing anything after check

    • input: see below
  • debounce(n, s): should check call debounce?

    • input
      • n - event field name
      • s - status object
    • returns: true (debounce) / false (no debounce)
  • values: hash object with default values for corresponding keys.

  • submit: specify the element to be un-disabled when form is validated.

  • initCheck: force a checkAll at initialization.

Status Object

An object with each key corresponding to a field and value of that key corresponding to field status. For example:

{
    "name": 0,
    "password": 2,
    "recaptcha": 3,
    "newsletter": 1
}

The values have following meaning:

  • 0 - valid
  • 1 - untouched ( not yet edit )
  • 2 - invalid
  • 3 - editing
  • 4 ~ 9 - preserved
  • 10 and above - user defined.

Fields Object

An object containing fields elements, such as:

{
    "name": ...,
    "password": ...,
    "recaptcha": ...,
    "newsletter": ...
}

Methods

  • ready(): return true if form is valid and ready to engage.

  • check({n, now}): check fields for all touched fields. if n is provided, touch the field named n. if now = true, check immediately without debouncing. to check multiple fields, provide a list:

    check([{...}, {...}, ... ])
  • values(o)

    • without parameter: get values for all fields with a name.
    • else: param should be a hash object with name - value pairs for each fields.
  • on(event-name, cb): listen to event "event-name" by callback cb. current supported event:

    • readystatechange: (is-ready) - fired if ready state is changed.
  • reset(): clear form fields and reset status ( clear is-invalid / is-valid classes )

  • field(n): get input field with name 'n'

  • checkAll(): force check all fields immediately. useful in programmatically input fields.

    • set initCheck config to true for a shorthand check on initialization.
  • getfd(): get FormData object corresponding to all fields in this form.

License

MIT License