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

takeout.js

v1.3.1

Published

A Takeout client for Node.js

Downloads

43

Readme

Installation 🏗

You can install Takeout.js using either NPM or Yarn.

$ npm install takeout.js
$ yarn add takeout.js

Then, import it like this:

const TakeoutClient = require('takeout.js')
const client = new TakeoutClient()

You can also initialise a new TakeoutClient with 'debug' mode enabled via new TakeoutClient(true). For now, it just prints success messages to the console.

Setup 🛠

First, get your token from the Takeout dashboard. You'll need it in a little bit.

Then, using that token you just got, use it here:

client.login('your token here')

As of right now, your code should look something like this:

const TakeoutClient = require('takeout.js')
const client = new TakeoutClient()
client.login('your token here')

"But I want to actually send an email!" ⇨ we're getting there!

Sending your first email 📤

Define a 'template' similar to this:

const emailTemplate = {
    to: '[email protected]',
    from: 'Takeout.js', // This will be (e.g) 'Takeout.js via Takeout' for free users
    subject: 'I just sent an email using Takeout!',
    html: "<b>My first email!</b>",
}

or

const emailTemplate = {
    to: '[email protected]',
    from: 'Takeout.js', // This will be (e.g) 'Takeout.js via Takeout' for free users
    subject: 'I just sent an email using Takeout!',
    text: 'My first email!',
}

and then...

client.send(emailTemplate)

You can also use await for client.send() - where it'll return an email ID. This ID can be used to view your email in the browser.

See? It's super simple. Oh, and you can also import HTML/text directly from a file, using getLocalTemplate() (prev. getHTMLFileContents()). This is demonstrated here:

async function sendEmail() {
    const html = await client.getLocalTemplate('templates/index.html')

    const emailTemplate = {
        to: '[email protected]',
        from: 'Takeout.js', // This will be (e.g) 'Takeout.js via Takeout' for free users
        subject: 'Getting HTML from a file',
        html: html,
    }

    await client.send(emailTemplate)
}

sendEmail()

Additional fields

Takeout.js allows you to CC one person (a method to CC more is coming soon). Define this in your template.

const emailTemplate = {
    to: '[email protected]',
    from: 'Takeout.js', // This will be (e.g) 'Takeout.js via Takeout' for free users
    subject: 'I just sent an email using Takeout!',
    text: 'My first email!',
    cc: '[email protected]'
}

Furthermore, Takeout.js allows you to set a reply-to email. Define this in your template.

const emailTemplate = {
    to: '[email protected]',
    from: 'Takeout.js', // This will be (e.g) 'Takeout.js via Takeout' for free users
    subject: 'I just sent an email using Takeout!',
    text: 'My first email!',
    replyTo: '[email protected]'
}

Takeout Cloud ☁️

If you're a Takeout+ subscriber, you can upload email templates to Takeout Cloud via the dashboard. You can upload up to 5 templates, each of which can be up to 5 megabytes in size.

You can retrieve your template(s) using the package's built-in method, getCloudTemplate(). It'll only work after client.login(), and it expects the exact file name for your template.

As an example, you'd use this code snippet of code to retrieve a template called SomeRandomCloudTemplate.html

const html = await client.getCloudTemplate('SomeRandomCloudTemplate.html')

In the dashboard, after uploading the template, it'll look similar to this:

If you want to actually do something with the template, consider installing a package like Lodash & their _.template function.

Errors

With the arrival of 1.2.0, came a new method to authenticate with Takeout's API. This removed your token from the request body and moved it to the Authorization header. If you're running an older version Takeout.js, Takeout will throw an error. Upgrade to a version >=1.2.0

Roadmap 🚦

  • Lodash templating built in, allowing you a greater variety of options in a single package (with... well some dependencies).
  • Fixing SMTP email validation.
  • Bug fixes.
  • A lot more.

See complete examples in examples/