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

submitjson

v0.9.0

Published

JavaScript client for Submit JSON (submitjson.com)

Downloads

122

Readme

submitjson

npm npm package minimized gzipped size (select exports)

JavaScript client for Submit JSON written in TypeScript. Works in modern browsers, as well as runtimes like Node.js v18+, Bun, Deno, and Edge Runtime.

Quick start

If you haven't already, sign up for a Submit JSON account.

Install the client with a package manager:

npm install submitjson # || pnpm add submitjson || yarn add submitjson

Import and create a new client instance

import SubmitJSON from 'submitjson'

const sj = new SubmitJSON({
  apiKey: 'sjk_xxxxxxxxxxxxxx',
  endpoint: 'XxXxXxXxX'
})

const data = await sj.submit({
  name: 'Yo Yoerson',
  message: 'Yo',
  powerLevel: 9001,
})

console.log('Submission', data)

Table of Contents

Configuration

  • Details

    Import and create a new Submit JSON client instance. We recommend including your endpoint here for easier submit calls down the line. Pass in default options per client to override the current endpoint settings.

  • Type

    interface SubmitJSONConfig {
      apiKey: string
      endpoint?: string
      options: SubmitOptions
    }
    
    interface SubmitOptions {
      emailNotification?: boolean
      emailTo?: string
      emailSubject?: string
      emailReplyTo?: string
      emailBranding?: boolean
      submissionFormat?: 'pretty' | 'raw'
      submissionSound?: 'none' | 'beep' | 'blip' | 'block' | 'coin' | 'ding' | 'dink' | 'honk' | 'jump' | 'ping' | 'pong' | 'snare'
      recaptchaToken?: string
      turnstileToken?: string
      hcaptchaToken?: string
    }
    
    class SubmitJSON {
      constructor(config: SubmitJSONConfig)
      submit(data, options, endpoint): Promise<Submission>
    }
  • Example

    // ~/submitjson.ts
    import SubmitJSON from 'submitjson'
    
    export const sj = new SubmitJSON({
      apiKey: 'sjk_xxxxxxxxxxxxxx',
      endpoint: 'XxXxXxXxX',
      options: { // set defaults for this client & override endpoint settings
        emailNotification: true,
        submissionFormat: 'raw',
        submissionSound: 'none',
      },
    })

API

submit()

  • Details

    POST your data to an endpoint and get notified in real time.

    submit() takes three arguments:

    1. The data (must be a valid JSON object, JSON string, or FormData)
    2. Optional configuration to override the endpoint's default settings. If this argument is a string it is treated as the endpoint for submitting data
    3. An optional endpoint.
  • Type

    function submit(
      data: Record<string, unknown> | string | FormData,
      options?: SubmitOptions,
      endpoint?: string
    ): Promise<Submission>
  • Example with all configuration options

    import SubmitJSON from 'submitjson'
    
    const sj = new SubmitJSON({
      apiKey: 'sjk_xxxxxxxxxxxxxx',
      endpoint: 'XxXxXxXxX',
    })
    
    const data = await sj.submit({
      name: 'Yo Yoerson',
      message: 'Yo',
      powerLevel: 9001,
    }, {
      emailNotification: true,
      emailTo: '[email protected]',
      emailReplyTo: '[email protected]',
      emailBranding: false,
      emailSubject: 'My custom subject line',
      submissionFormat: 'pretty',
      submissionSound: 'ping',
      recaptchaToken: 'xxxxxxxxxxx'
    }, 'YyYyYyYyY') // overrides the endpoint set in the configuration
    
    console.log('Submission', data)
  • Example with multiple clients

    Initialize multiple clients for a seperation of concerns.

    // submitjson.ts
    import SubmitJSON from 'submitjson'
    
    export const contactForm = new SubmitJSON({
      apiKey: 'sjk_xxxxxxxxxxxxxx',
      endpoint: 'XxXxXxXxX',
    })
    
    export const userSignupNotification = new SubmitJSON({
      apiKey: 'sjk_xxxxxxxxxxxxxx',
      endpoint: 'ZzZzZzZzZ',
    })
    // somewhere else in your code
    const data = { name: 'Yo Yoerson', message: 'Yo' }
    await contactForm.submit(data)
    await userSignupNotification.submit(data)

Submit JSON Links

License

MIT License © 2023 Submit JSON