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

honst

v0.1.2

Published

Data Integrity fixer for JavaScript Object-Arrays.

Downloads

18

Readme

⛓️ honst

The name: I wanted it to be "honest", but it was occupied, so I removed a letter, and it became "honst".

Data Integrity fixer for an object matrix.

Use Cases

  • On editing a joined matrix data needs the data integrity to be kept.
  • Keeping your local state correct.

Demo

You can play with honst on CodeSandbox:

Edit honst demo

Overview

const data = [
  { username: "johndoe", name: "John", surname: "Doe", age: "22" },
  { username: "johndoe", name: "John", surname: "Doe", age: "25" },
  { username: "johndoe2", name: "John", surname: "Doe", age: "22" },
  { username: "johndoe2", name: "John", surname: "Doez", age: "22" },
]

According to username field, there are many integrity issues around the array. So let honst fix these:

[
  { username: "johndoe", name: "John", surname: "Doe", age: 22 },
-  { username: "johndoe", name: "John", surname: "Doe", age: 25 },
+  { username: "johndoe", name: "John", surname: "Doe", age: 22 },
  { username: "johnapple", name: "John", surname: "Apple", age: 29 },
- { username: "johnapple", name: "John", surname: "Orange", age: 22 },
+ { username: "johnapple", name: "John", surname: "Apple", age: 29 },
]
  1. Referencing to data[0].username, name, surname, and age should be John, Doe and 22.
  2. But data[1].age is 25 and it should be fixed.
  3. Referencing to data[3].username, name, surname, and age should be John, Apple and 29.
  4. But data[1].age is 25, data[1].surname is Orange and these should be fixed as well.

honst simply fixes these integirty issues.

Usage

Install using npm or yarn:

npm install honst
# or
yarn add honst

Now you can start:

import { honst } from 'honst';

const { data, delta } = honst({
  data: [
    { username: "johndoe", name: "John", surname: "Doe", age: "22" },
    { username: "johndoe", name: "John", surname: "Doe", age: "25" }
  ],
  pivot: 0,     // an index number, "scan" or "reverse-scan"
  delta: true,  // boolean
  rules: {
    // the ruleset of integrity
    // e.g. we want all names, surnames and ages to be same according to "username"
    name: ["username"],
    surname: ["username"],
    age: ["username"],
  }
})

This will generate following data:

const fixedData = {
  data: [
    { username: "johndoe", name: "John", surname: "Doe", age: "22" },
    { username: "johndoe", name: "John", surname: "Doe", age: "22" },
  ],
  delta: [
    {
      candidatePath: "age", // the path of the field
      falseValue: "25", // the wrong value
      candidateValue: "22", // the candidate value
      pivot: 0, // the pivot row index
      candidateIndex: 1, // the false row index
    }
  ]
}

Scanning and Reverse Scanning

Just pass pivot value scan or reverse-scan.

If you want to fix all the rows from top-down or bottom-up, this will scan the data and fix'em all.

const { data, delta } = honst({
  data: [
    { username: "johndoe", name: "John", surname: "Doe", age: "22" },
    { username: "johndoe", name: "John", surname: "Doe", age: "25" },
    { username: "johndoe2", name: "John", surname: "Doe", age: "22" },
    { username: "johndoe2", name: "John", surname: "Doez", age: "22" },
  ],
  pivot: "scan",
  delta: true,
  rules: {
    name: ["username"],
    surname: ["username"],
    age: ["username"],
  }
})

This will generate the following:

const fixedData = [
  { username: "johndoe", name: "John", surname: "Doe", age: "22" },
  { username: "johndoe", name: "John", surname: "Doe", age: "22" },
  { username: "johndoe2", name: "John", surname: "Appleseed", age: "22" },
  { username: "johndoe2", name: "John", surname: "Appleseed", age: "22" },
]

If you select scan the upper rows will be fixed first, and matching rows below will be updated accordingly. If you select reverse-scan it'll start fixing from bottom and scan to the top, so the bottom rows will be assumed correct.

Nested Objects?

Yes it supports nested objects as well.

const { data, delta } = honst({
  data: [
    // ... some nested data
  ],
  rules: {
    'user.name': ["account.username"],
    'user.surname': ["account.username"],
    'profile.age': ["account.username"],
  }
})

Contribution

  • Clone and edit the source as you wish.
  • Please do not forget to add tests.
  • Write a descriptive PR.

License

This project uses MIT license.