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

datacraft

v0.0.14

Published

LINQ-like JavaScript object query library. No dependencies. Works in all environments.

Downloads

10

Readme

Datacraft

LINQ-like JavaScript object query library. No dependencies. Works in all environments.

Work in progress, stay tuned for the upcoming 1.0.

Node.js CI Deno CI npm version MIT License NPM Downloads No dependencies

  • Works in Node.js >=4.0 (both require and import).
  • Works in Deno >=1.16.
  • Works in browsers as standalone, UMD or ES-module.
  • Includes TypeScript typings.

Quick examples:

More examples...

Installation

Node.js

npm install datacraft --save

JavaScript

// ESM Import ...
import DataSet from "datacraft";

// ... or CommonJS Require
const DataSet = require("datacraft");

TypeScript

Notes for TypeScript:

import DataSet from "datacraft";

const data : DataSet = new DataSet();

Deno

JavaScript

import DataSet from "https://deno.land/x/datacraft/src/datacraft.js";

const data = new DataSet();

TypeScript

import { DataSet } from "https://deno.land/x/datacraft/src/datacraft.js";

const _data : DataSet = new DataSet();

Browser

Manual

  • Download latest zipball
  • Unpack
  • Grab datacraft.min.js (UMD and standalone) or datacraft.min.mjs (ES-module) from the dist/ folder

CDN

To use as a UMD-module (stand alone, RequireJS etc.)

<script src="https://cdn.jsdelivr.net/npm/datacraft@0/dist/datacraft.min.js"></script>

To use as a ES-module

<script type="module">
	import DataSet from "https://cdn.jsdelivr.net/npm/datacraft@0/dist/datacraft.min.mjs";

	// ... see usage section ...
</script>

Documentation

Full documentation available at hexagon.github.io/datacraft.

The short version:

Examples

// Node 
// import { DataSet } from "datacraft";

// Deno
import DataSet from "https://deno.land/x/datacraft/src/datacraft.js";


// Set up data
let persons = new DataSet().insert([
	{name: "Curt", group: 14, age: 34},
	{name: "Lewis", group: 14, age: 38},
	{name: "Stewie", group: 15, age: 31}
]);

let groups = new DataSet().insert([
	{group: 14, name: "Western"},
	{group: 15, name: "North"}
]);

// Set up relations
let personsWithFirstGroup = persons.copy().joinFirst(groups, "groups", (p, g) => p.group == g.group);
let groupsWithAllPersons = groups.copy().join(persons, "persons", (g, p) => g.group == p.group);

// Aggregate data
groupsWithAllPersons
	.avg("persons", "averageAge", p => p.age)
	.min("persons", "maxAge", p => p.age)
	.max("persons", "minAge", p => p.age)
	.count("persons", "personCount", p => p.name);

// Print data
console.log(personsWithFirstGroup.toArray());
console.log(groupsWithAllPersons.toArray());

All methods

All methods of DataSet.

Dataset operations

| Method | Description | | ------ | ----------- | | insert([obj1, obj2]) | Insert new objects into data set | | update(obj, conditionCb) | Update all entries matching conditionCb with properties of obj | | drop(fieldName) | Remove a field from all objects in data set | | copy() | Make a shallow copy of current data set | | calc(outputFieldName, calcCb) | Creates a new field, containing the return value of calcCb | | autonumber(outputFieldName) | Creates a new field, contaning a number that increment for each entry |

Relations

| Method | Description | | ------ | ----------- | | join(otherDataSet, newFieldName, conditionCb) | Join all objects in data set with objects of another data set where conditionsCb return true | | joinFirst(otherDataSet, newFieldName, conditionCb) | Join first object from otherDataSet with objects in current data set |

Filtering

| Method | Description | | ------ | ----------- | | filter(conditionCb) | Keep only objects matching conditionCb | | toArray(conditionCb) | Returns an array of all entries in current data set, optionally filtered by conditionCb | | first(conditionCb) | Returns the first entry if current data set, optionally filtered by conditionCb |

Aggregation

| Method | Description | | ------ | ----------- | | groupBy(groupByFieldsInput, outputFieldName) | Group current dataset by field(s) specified by groupByFieldsInput | | total(outputFieldName) | Group current dataset, placing all entries in a new field named by parameter outputFieldName | | avg(field, outputFieldName, mapCb) | Average a value from entries in field specified by field, in a new field named by outputFieldName. mapCb points out which subfield should be averaged | | sum(field, outputFieldName, mapCb) | Like above | | min(field, outputFieldName, mapCb) | Like above | | max(field, outputFieldName, mapCb) | Like above | | countd(field, outputFieldName, mapCb) | Like above | | count(field, outputFieldName, mapCb) | Like above |

Contributing

See Contribution Guide

License

MIT