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

@nitsudgo/library-of-babel

v1.1.0

Published

A Library of Babel implementation written in Typescript.

Downloads

18

Readme

The Library of Babel (.ts)

GitHub stars GitHub forks npm (scoped)

Disclaimer: This was a project I started for my personal entertainment and education. I have taken steps to make sure that it functions as expected, but I am not all-knowing. Use at your own risk!

This is a TS package I wrote whilst studying, and trying to replicate, the algorithm behind the Library of Babel website. The original creator, librarianofbabel, explains the approach and I followed this implementation very closely.

Install

npm i --save @nitsudgo/library-of-babel

Usage

Before you begin

If you aren't familiar with how the Library of Babel works (from the short story), then this whole repo may not make much sense. I highly suggest you give it a read. The documentation will assume you have some knowledge of the concepts.

Instancing

This package exports a LibraryOfBabel class. First, you must import the package and create a new instance. Here, you may pass in any number to use as a seed. If no seed is given, a default value of 8888 will be used.

Instances that have different seeds will not have reproducible results between them.

const { LibraryOfBabel } = require('library-of-babel');

// If constructor is left blank, a default seed of 8888 is used
const LoB = new LibraryOfBabel(69);

search

The search function will look for either a partial or exact match of a given string in the library and return the address of the page that the search result is in.

const searchString = 'some string to search for';

// Exact search looks for PRECISELY the string you have given
const exactSearchResult = LoB.search(searchString, 'exact');

// Partial search simply finds a page where your string appears in the content, regardless of where in the content it is located
const partialSearchResult = LoB.search(searchString, 'partial');

getPage

The getPage function accepts an address and returns the content of that particular page.

const pageContent = LoB.getPage(exactSearchResult);

getTitle

The getTitle function accepts an address and returns the title of the volume (book). Different pages within the same volume will give the same result.

const pageTitle = LoB.getTitle(exactSearchResult);

Development

To play with the code, simply clone this Git repo to your machine, cd into the project directory root, and run the following:

npm i

Tests

I've included some test suites in the /__tests__ directory. To run them, simply enter the following command in the terminal.

npm run test

Contributing

To contribute, simply checkout to your own branch, push your commits to that branch, and then raise a pull request!

I hope you enjoy the package!