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

@aspot/core

v0.6.2

Published

Provides a store that composes all data as Subject Predicate Object sentences

Downloads

25

Readme

ASPOT

ASPOT is a subject Predicate Object Transformer. It is a store that hold all of its data as a array of sentences with three parts subject predicate and object. As an example lets see some information about Bob.

| Subject | Predicate | Object | | ----------- | ------------ | --------- | | d47c38d1... | firstName | Bob | | d47c38d1... | lastName | Newhart | | d47c38d1... | age | 75 |

Now lets add more info about Bob's husband and Bobs relationship

| Subject | Predicate | Object | | ----------- | ------------ | --------- | | fbf8d8d0... | firstName | Sam | | fbf8d8d0... | lastName | Newhart | | fbf8d8d0... | age | 78 | | d47c38d1... | Husband | fbf8d8d0... |

Because the data is stored in this way ASPOT can be use in a distribed manor where each of these sentences are updated independently of each other.

While the data is stored this way as you will see in Usage this is not how we access the data.

Instalation

To install use npm or yarn

npm install @asopt/core

or

yarn install @asopt/core

Usage

Aspot proves a store contructor function aspot.

import aspot from '@aspot/core'
const store = aspot();

By default the store is only held in memory it can be connect to local storage by using localConnector.

localConnector('localStoragekey')(store);

all change to the store will then be help in the browser localStorage.

There are two main was to use the store, one is to walk the nodes and the other is to do a search.

Walking nodes

I will be using an example of date around a person named bob in the following section

to walk the nodes one first use store.node to initiate a node.

const bob = store.node('d47c38d1...')

we can then start walking the node tree using the s function. and can use the value method to get values. One can use multiple s calls to keep walking'

const firstName = bob.s('firstName').value();
const lastName = bob.s('lastName').value();
const husbandFirstName = bob.s('husband').s('firstName').value();

value can also be used with a depth prop which will give one a object at depth.

const bobData = bob.value(1)
// bobData wouldbe something like
// {
//   firstName: 'bob'
//   lastName: 'NewHart'
//   age: '75',
//   husband:'fbf8d8d0...'
// }
const bobData2 = bob.value(2)
// bobData2 wouldbe something like
// {
//   firstName: 'bob'
//   lastName: 'NewHart'
//   age: '75',
//   husband: {
//     lastName: 'NewHart',
//     firstName: 'Sam',
//     age: '78',
//   }
// }

The is function is used to set values

bob.s('middleName').is('Juan');

Along with the is method there is an on method that can be pass a function to run each time the value is updated.

bob.s('age').on(age => sendBirthdayCard('bob', age))

The list function is used to get an array of all children nodes of the current node. This is often used when trying to store data that is more array like.

const children = bob.s('children').list();
const childrenfristnames = children.map(n => n.s('firstname'))
// childrenFirstNames would be 
// ['Cathey', 'Fahren', 'Davey']

Searching

To search one using the find method of the store. The point of the find is not to find data but to find a node in the map. After doing the find one can then walk the nodes to get data or update data.

The find method takes a match function. There are a set of helper function that can be used here.

Match Helpers

has

THe has helper is a curry function that takes a part to search on then a string or regex expresion

// Find statements that have on object of bob
const result = store.find(has(TermType.object)('bob'));
// Find statements that finds any statements that have a prediate ending in Name
const result = store.find(has(TermType.predicate)/.*Name$/));
not

Takes a different match and just does the inverse.

// Find statements that do not have on object of bob
const result = store.find(not(has(TermType.object)('bob')));
and

Takes 1 or more other matches and does a match if they all return true

// Find statements that have a predicate of firstname as well as a object of bob
const result = store.find(and(has(TermType.predicate)('firstName')), has(TermType.object)('bob')));
or

Takes 1 or more other matches and does a match if any of them return true

// Find statements have a object of sam or bob
const result = store.find(or(has(TermType.object)('sam')), has(TermType.object)('bob'))); 
join

Is a bit speceal because it compares multiple finds. With each find one can name it, and then refer to that name here.

// Find all statements about people that are a boss;
const result = store.find(has(TermType.predicate)('boss'), 'firstLevel')
  .find(join('firstlevel')(TermType.object)(TermType.subject)) 
// Find all statements about people that are a boss with a first name of bob
const result = store.find(has(TermType.predicate)('boss'), 'firstLevel')
  .find(and(
    join('firstlevel')(TermType.object)(TermType.subject)),
    has(TermType.predicate)('firstName'),
    has(TermType.object)('bob'),
     

Result Object

After one has done the find they can then start walking with two methods nodes and list.

nodes

Returns an array of nodes that are based on the unique subject for the last find.

// get the lastName of everyone person with firstName 'bob'
const lastNames = store.find(and(has(TermType.predicate)('firstName'), has(TermType.object)('bob'))
  .nodes()
  .map(node => node.s('lastName').value())
list

Returns an array of nodes that are based on each statement.

// get the lastName of everyone that is a boss
const lastNames = store.find(TermType.predicate)('boss'))
  .list()
  .map(node => node.s('lastName').value())