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

jsrepeater

v1.2.4

Published

Building on the concept of [JqueryRepeater](https://github.com/DubFriend/jquery.repeater?tab=readme-ov-file), JsRepeater is a pure JavaScript form toolkit. It allows you to create and manage repeatable form elements through simple HTML5 configurations, en

Downloads

249

Readme

JsRepeater

Building on the concept of JqueryRepeater, JsRepeater is a pure JavaScript form toolkit. It allows you to create and manage repeatable form elements through simple HTML5 configurations, enabling dynamic addition and deletion of items in web forms.

JsRepeater rewrites the 'name' attribute to avoid naming conflicts within the same form. In the following example, the form item names will be redefined with the 'name' attribute as MyGroup[0][name] and MyGroup[0][age].

Install

npm install jsrepeater --save

Initialization

<div id="myRepeater">
  <div data-repeater-list="myGroup">
    <div data-repeater-item>
      <input type="text" name="name">
      <input type="text" name="age">
      <input type="checkbox" name="course" value="math">
      <input type="checkbox" name="course" value="science">
      <button data-repeater-delete>Delete</button>
    </div>
  </div>
  <button data-repeater-create>Add</button>
</div>
<script>
const repeater = JsRepeater.create(document.getElementById('myRepeater'), {
  /**
   * Set default values
   * @type object
   */
  defaultValues: {data: {name: 'john', age: 40}},

  /**
   * Animation effect (ms) when adding/deleting items, 0(default) for no animation
   * @type Integer
   */
  animationMs: 0,

    /**
   * When deleting an item, specify a field name as the identifier for the deleted item.
   * Example: Typically, you would specify the item's id. When setting deleteInputName = '_delInputName' and deleteInputField = 'id', if items with ids 12 and 34 are deleted, the form submission will include post._delInputName = [12, 34]. The backend can then delete or process items with ids 12 and 34 accordingly.
   * @type {String}
   * @type {String}
   */
  deleteInputField: '',

  /**
   *  When deleting an item, specify a form name for a hidden field. This field is automatically created when an item is deleted. Usually used to track deleted items. Must be used in conjunction with `deleteInputField`.
   * @type string
   */
  deleteInputName: '',

  /**
   * Callback function after adding an item
   * @param  object  item       item  Newly added form item (Node list)
   * @param  object  itemConfig data  Object containing data passed when adding the item, including:
   *                            data: Object containing the new item's data
   *                            extra: Object containing additional settings (if any)
   */
  onItemAdded: (item, itemConfig) => {
    // do something after add
  },

  /**
   * Callback function after deleting an item
   * @param  object  item  Deleted form item (Node list)
   */
  onItemRemoved: (item) => {
    // do something after remove
  }
});
</script>script>

HTML

  1. data-repeater-list: Element group, aimed at preventing form element name collisions
  2. data-repeater-item: Form element template
  3. data-repeater-create: Add button, adds data-repeater-item to the data-repeater-list group
  4. data-repeater-delete: Delete button, removes data-repeater-item

API

1. Adding Items

Add a single item
repeater.addItem({
  data: {name: 'John', age: 30}
});
Add multiple items
repeater.addItems([
  {data: {name: 'John', age: 30}},
  {data: {name: 'Mary', age: 20}, extra: {}}, // extra will be passed as a parameter to the add callback function
]);

2. Reset indexes

Redefines indexes when form items are added or deleted

repeater.setIndexes();