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

sn-extension-api

v0.3.4

Published

Standard Notes API for writing extensions

Downloads

44

Readme

Standard Notes Extension API

This is an easier-to-use API to write Standard Notes extensions.

Getting started

The easiest way to start creating Standard Notes extensions is to use the template repo: https://github.com/nienow/sn-extension-template

Otherwise, install the npm module:

npm install sn-extension-api

Importing theme

Import the base theme variables in your root CSS or SASS file:

@import 'sn-extension-api/dist/sn.min.css';

Then make sure you use the standard notes theme variables when styling your extension.

Basic API usage

import snApi from "sn-extension-api";

// only call this once - it will establish communication with standard notes
snApi.initialize();

// get notified when note is received from standard notes
snApi.subscribe(() => {
  // set current text into text area for editing
  document.getElementById('my-text-area').value = snApi.text;
});

document.getElementById('my-text-area').addEventListener('input', (e) => {
  // update text on change - automatically saves to standard notes
  snApi.text = e.target.value;
});

Full API documentation

Initialize

This needs to be called before doing anything else. Do not call more than once.

snApi.initialize({
  debounceSave: 300 // the number of ms to debounce the save for performance reasons (defaults to 250ms)
});

Note Text

// get text
console.log(snApi.text);
// update text
snApi.text = 'new text';

The note text must be a string. So if the extension uses json, it must be converted back and forth from a string:

// get text
console.log(JSON.parse(snApi.text));
// update text
snApi.text = JSON.stringify({cell1: 'some content', cell2: 2});

Preview Text

By default, the note preview will be generated using the first 50 characters of the text. If you want to use a custom preview, you can set the preview directly after setting the text:

snApi.text = JSON.stringify({...});
snApi.preview = 'my note preview';

Note Metadata

You can store metadata separately from the note text. This data can be any object (it does not need to be a string like the text).

// get metadata
console.log(snApi.meta);

// set metadata
snApi.meta = {lastCursorPosition: 123, selectedLines: [1, 3]};

Extension Metadata

This data is stored per extension (not per note). It can be any object.

// get extension metadata
console.log(snApi.extensionMeta);

// set extension metadata
snApi.extensionMeta = {spacingPreference: 'comfortable'};

Environment

Check which environment the extension is being used in. There are 3 different environments: browser, desktop app, mobile app.

console.log(
  snApi.isRunningInBrowser,
  snApi.isRunningInDesktopApplication,
  snApi.isRunningInMobileApplication
);

Locked

When the "Prevent editing" is toggled for a note, the locked property will be true.

console.log(
  snApi.locked
);