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

@batuhanw/haf

v1.0.0

Published

Fully typed, modern, cross-platform persistent JSON storage solution for NodeJS projects.

Downloads

7

Readme

🧠 🔒 Haf 🦺 ✏️

npm version CI Known Vulnerabilities Maintainability Test Coverage

Haf is a fully typed 🔒, cross-platform, persistent 💾 JSON storage ⚙️ solution for your NodeJS projects with a great developer experience!

  • ✏️ Auto-completed dot-notation suggestions as you type when you try to get()/set()/delete()/reset() data from the store.
  • ✅ The type of the value you get() from the store is correctly inferred. So you always know what you'll get().
  • ❌ Non-nullable values aren't suggested on delete(). Trying to delete() a non-nullable field will throw a type error.

Go to gifs section to see it in action!

Installation

npm i @batuhanw/haf

OR

yarn add @batuhanw/haf

🏃 Getting Started

1. Define Your Schema

interface DogSchema {
  name: string;
  age: number;
  toys: string[];
  vaccines: { name: string; date: string; nextDate?: string }[];
  appearance: {
    eyeColor: string;
    hairColor: {
      primary: string;
      secondary?: string;
      otherColors: string[];
    };
  };
  sterilizedAt?: string;
  hasPuppies: boolean;
}

2. Initiate Haf

import Haf from '@batuhanw/haf';

const haf = new Haf<DogSchema>({
  name: 'myDog',
  defaultSchema: {
    name: 'Pop',
    age: 2,
    toys: ['socks', 'toilet paper'],
    vaccines: [
      { name: 'rabbies', date: '2020-01-01' },
      { name: 'parasite', date: '2020-01-01', nextDate: '2020-01-03' },
    ],
    appearance: {
      eyeColor: 'brown',
      hairColor: {
        primary: 'white',
        secondary: undefined,
        otherColors: ['black'],
      },
    },
    sterilizedAt: undefined,
    hasPuppies: false,
  },
});

3. Enjoy

Get

  const name = haf.get('name') // string
  const age = haf.get('age') // number
  const hasPuppies = haf.get('hasPuppies') // boolean
  const vaccines = haf.get('vaccines') // { name: string; date: string; nextDate?: string }[]
  const hairColor: haf.get('appearance.haircolor') // { primary: string; secondary?: string, otherColors: string[] }
  const secondaryHairColor: haf.get('appearance.hairColor.secondary') // string | undefined

  const invalid = haf.get('non-existent') // type error

Set

haf.set('name', 'Pop');
haf.set('appearance.hairColor', { primary: 'white' });
haf.set('appearance.hairColor.secondary', 'brown');
haf.set('appearance.hairColor.secondary', undefined);
haf.set('appearance.hairColor.otherColors', ['black']); // This will overwrite existing array

haf.set('name', 1); // type error
haf.set('toys', [1, 2]); // type error
haf.set('appearance.haircolor', { primary: 1 }); //type error
haf.set('appearance.hairColor.primary', 1); // type error
haf.set('appearance.haircolor', { notExist: 'white' }); //type error

Append

Appends given values to the existing array

haf.get('toys'); // ['socks', 'toilet paper']

haf.append('toys', 'human hand', 'bone');

haf.get('toys'); // ['socks', 'toilet paper', 'human hand', 'bone']

Delete

haf.delete('sterilizedAt');
haf.delete('appearance.hairColor.secondary');

haf.delete('name'); // type error
haf.delete('appearance.hairColor.primary'); // type error

Gifs

Get

Set

Delete