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

writeasly

v0.0.6

Published

Write.as client library

Downloads

2

Readme

writeasly

Description

writeasly ("write-easily" - I know, I know, terrible!) is a Javascript library implementing the write.as API. It is based on writeas.js by devsnek.

Installation

npm install writeasly

or

yarn add writeasly

Usage

Client

Import the library

import Client from 'writeasly'; // ES6
const Client = require('writeasly').default; // CommonJS

const client = new Client();

Authenticate

const client = new Client();

client.authenticate(username, password).catch(error => {
  // Handle authentication errors
})

Logout

Logs a user out. Returns code 204 for success, 400 for missing auth token, and 404 for an invalid token.

client.authenticate(username, password)
  .then(() => client.logout())
  .then(response => {
    // Do things with response
  })
  .catch(error => {
    // Handle errors
  })

Get current authenticated user

Gets basic information on the currently authenticated user.

client
  .authenticate(username, password)
  .then(() => {
    return client.getCurrentAuthenticatedUser();
  })
  .then(response => {
    // Do things with response
  })
  .catch(error => {
    // Handle errors
  });

Creating an anonymous post

An unauthenticated client will create an anonymous, unclaimed post, whereas an authenticated client will create an anonymous, claimed post that does not belong to a collection.

client.createPost(
  body,
  <{title, font, lang, rtl, crosspost}>
)
  .then(post => {
  // Do things with post
})

Get a post by ID

client.getPost(id)
  .then(post => {
  // Do things with post
})

Update a post by ID

client.updatePost(postID, data, token)
  .then(post => {
  // Do stuff with updated post object
})

client.getPost(postID)
  .then(post => post.update(body, {title, font, lang, rtl}))
  .then(updatedPost => {
  // Do things with updated post
})

Delete a post by ID

Returns a 204 status code upon deletion success

client.getPost(postID)
  .then(post => post.delete())
  .then(response => console.log(response))

Claim a post by ID

Claims an anonymous post. Note that the token is the post's update token that is returned upon publishing an anonymous post, and not the user's access token.

client.getPost(postID)
  .then(post => post.claim(token))
  .then(response => {
    // Do things with response
})

Add a post to a collection

client.createPost('Hello there')
  .then(post => post.addToCollection(alias))
  .then(response => {
    // Do things with response
  })
  .catch(error => {
    // Do things with error
  })

Unpublish a post by ID

Returns status code 410 with an error_msg detailing successful unpublish.

client.getPost(postID)
  .then(post => post.unpublish())
  .then(response => console.log(response))

Get a user's collections

Returns an array of a user's collections (blogs).

client.authenticate(username, password);

client.getUserCollections()
  .then(collections => {
  // Do things with collections
})

Get a user's posts

Returns an array of a user's posts

client.getUserPosts()
  .then(posts => {
    // Do things with posts
})

Get a collection by alias (blog title)

Returns a collection object for a given blog

client.getCollectionByAlias(alias)
  .then(collection => {
  // Do things with collection
})

Create a collection (blog)

This requires a pro subscription to Write.as. Returns a Collection object of the new collection.

client.createCollection(title, <alias>)
  .then(collection => {
    // Do things with collection
  })
  .catch(error => {
    // Do things with error
  })

Delete a collection (blog)

client.getCollectionByAlias('my-blog')
  .then(collection => collection.deleteCollection())
  .then(response => {
    // Do things with response
  })
  .catch(error => {
    // Do things with error
  })

Get a collection's posts

Returns an array of posts from a given collection

client.getCollectionByAlias(alias)
  .then(collection => collection.getPosts())
  .then(posts => {
  // Do things with posts
})

Get a collection's post by its slug (title)

Returns a post object for a post by its slug.

client.getCollectionByAlias(alias)
  .then(collection => collection.getPostBySlug(slug))
  .then(post => {
  // Do things with post
})

Create a new collection post

As opposed to client.createPost() this will create a post on a given collection (blog). Returns the post object.

client.getCollectionByAlias(alias)
  .then(collection => collection.createNewCollectionPost({
  title: 'Hello',
  body: 'I am a writer'
  }))
  .then(post => {
  // Do things with post
})

Pin a post to a collection

Pins a post to the top of a collection. Returns the response object

client.getCollectionByAlias('cocoa')
  .then(collection => {
  collection.pinPostOnCollection('ywlfu4gkyfbhrti5');
  })
  .then(response => {
  // Do things with response
})

Unpin a post on a collection

Unpins a post from a collection. Returns the response object

client.getCollectionByAlias('cocoa')
  .then(collection => collection.unpinPostOnCollection(postID)
  )
  .then(response => {
  // Do things with response
})

Features

writeasly is a work in progress and is missing some features in the API. However, most functionality is implemented. List of supported endpoints:

writeasly currently supports the vast majority of the write.as API, a complete list of supported/unsupported features:

Posts

✅ Publish an anonymous post

✅ Retrieve a post

❌ Update an anonymous post

✅ Update a claimed post

✅ Unpublish a claimed post

✅ Delete an anonymous post

✅ Delete a claimed post

✅ Claim an anonymous post

Collections (blogs)

✅ Create a collection

✅ Retrieve a collection

✅ Delete a collection

✅ Retrieve a collection post

✅ Publish a collection post

✅ Retrieve all collection posts

✅ Move a post to a collection

✅ Pin a post to a collection

✅ Unpin a post from a collection

Users

✅ Authenticate a user

✅ Log a user out

✅ Retrieve authenticated user

✅ Get a user's posts

✅ Get a user's collections

Integrations (crossposting)

✅ Crossposting