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

fork-string

v1.2.1

Published

Synchronous forkable string primitive.

Downloads

10

Readme

fork-string

Synchronous forkable string primitive.

Like a regular textual string, except each character has a unique ID and records what IDs are to its immediate left and right. This allows non-conflicting changes to be made in any order.

Usage

var fstring = require('fork-string')

var str = fstring()

// A 'prev' and 'next' param of null indicates this text is a root; it depends
// on no other pre-existing string data.
var chars = str.insert(null, null, 'beep boop', 'id1')
console.log('chars1', chars)

var chars2 = str.insert(chars[8], null, 'ity!', 'id2')
console.log('chars2', chars2)

// Delete between IDs 1 and 7 ("eep boo").
str.delete(chars[1], chars[7], 'id3')

console.log('final chars', str.chars())

console.log(str.text())

outputs

chars1 [ 'id1@0', 'id1@1', 'id1@2', 'id1@3', 'id1@4', 'id1@5', 'id1@6', 'id1@7', 'id1@8' ]

chars2 [ 'id2@0', 'id2@1', 'id2@2', 'id2@3' ]

final chars [ { chr: 'b', pos: 'id1@0' },
              { chr: 'p', pos: 'id1@8' },
              { chr: 'i', pos: 'id2@0' },
              { chr: 't', pos: 'id2@1' },
              { chr: 'y', pos: 'id2@2' },
              { chr: '!', pos: 'id2@3' } ]

bpity!

API

var fstring = require('fork-string')

var str = fstring()

Creates a new forkable string.

str.insert(prev, next, text, id)

Insert text text between the IDs prev and next. The text will have the ID id.

str.delete(from, to)

Delete the text from ID from to ID to.

str.chars()

Returns an array of all characters and their IDs, in order. Each element is of the form

{
  chr: 'H',
  pos: 'abcd@3'
}

str.text()

Returns the human-readable text of the string in its current state.

str.pos(id)

Returns the absolute position of id in the string.

str.clone()

Return a copy of the fork-string.

Install

With npm installed, run

$ npm install fork-string

See Also

License

ISC