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

@getmeli/sdk

v1.0.0

Published

Meli SDK

Downloads

10

Readme

Meli SDK

Forms

Using

Place a .meli.yml at your site root:

forms:
    form1:
        type: email
        recipient: [email protected]

Create an HTML form:

<!doctype html>
<html>
<head>
    <!-- ... other scripts -->
    <script async src="https://unpkg.com/@getmeli/sdk@^1/build/browser.js"></script>
</head>
<body>

<form data-form="form1" id="my-form">
    <input type="text" name="name">
    <input type="file" name="logo">
    <button type="submit">Submit</button>
</form>

<script>
    const formElement = document.getElementById('my-form');
    formElement.addEventListener('submitted', () => {
        console.log('submitted');
    });
</script>

</body>
</html>

By default, the lib will automatically load and look for forms with the data-form attribute. You can disable this by:

  • adding the data-meli-init="false" to your script tag
  • removing the async directive from your script tag

<script ... data-meli-init="false"></script>
<script>
    Meli.Forms.init().catch(console.error);
</script>

Using Npm

Install the lib:

npm i @getmeli/sdk

Use it in your code:

import Meli from 'meli';

Meli.Forms.init().catch(console.error);

Api

To pass your own forms:

const form = document.getElementById('my-form');

Meli.Forms
    .init([form])
    .catch(console.error);

Manually create a form and bind it:

Meli.Forms
    .init([]) // passing the empty array cancels the auto detection
    .then(() => {
        const formElement = document.getElementById('my-form');
        const form = new Meli.Forms.Form(form);
    })
    .catch(console.error);

To remove all listeners:

// ...
const form = new Meli.Forms.Form(form);
forms.remove();

Events

On the HTML form element:

const formElement = document.getElementById('my-form');
formElement.addEventListener('submitted', () => {
    console.log('submitted');
});

Or on the Form object:

Meli.Forms
    .init([])
    .then(() => {
        const formElement = document.getElementById('my-form');
        const form = new Meli.Forms.Form(form);
        form.addEventListener('submitted', () => {
            console.log('submitted');
        });
    })
    .catch(console.error);

| Event | Callback signature | Description | |----|----|----| | submitting | () => void | The form submit callback was called. | | submitted | () => void | The form was submitted successfully. | | error | (error) => void | Something went wrong. |

Development

  1. Run Meli locally
  2. Ship a site with a form
  3. Run npx http-server -p 3030 .
  4. In your site's index.html, use http://localhost:3030/build/browser.js for the SDK src
  5. Start the build npm i && npm start