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

newsroom-dojo

v1.2.5

Published

A collection of helpful utility functions for newsroom projects.

Downloads

143

Readme

Newsroom Dojo

npm version License: MIT

newsroom-dojo is a collection of utility functions designed to assist with common tasks in the newsroom. Just as a dojo equips martial artists with the tools and techniques for training, newsroom-dojo provides functions for wrangling data, loading data, and tackling other everyday project challenges with precision and efficiency.

Table of Contents

Installation

You can install the package via npm:

npm install newsroom-dojo

Load the specific helper functions you want to use (A full list will be coming very soon).

Usage

import { contains, getJson } from 'newsroom-dojo/dist/index.js'

API

Schema function

Give it some json data and it generates a schema containing property names and data types.

import { schema } from 'newsroom-dojo/dist/schema/index.js'

or

import { schema, getJson } from 'newsroom-dojo/dist/index.js'

If you are starting with a CSV you need to convert it to JSON first. In the context of converting a CSV to JSON, the JSON version of a column is typically represented as an array of values within an object where the keys are the column headers. These arrays are often referred to as "fields" or "properties" in the JSON object. Each "field" or "property" corresponds to a column in the original CSV.

;(async ()=>{

    try {

      // Load some json data
      let googledoc = await getJson("https://interactive.guim.co.uk/docsdata/11LFp54PIb08Cqu6fBpQGDcQ15enT2F-9HsO8kokXbfQ.json")

      // Pass your JSON to the schema function
      let info = await schema(googledoc.sheets.data)

      console.log(info)

    } catch (error) {
      console.error(error);
    }

})()

The schema function is meant to make generating graphics, charts and tables from your data just a little bit easier. The output of the schema function looks something like this:


[
    {
        "column": "Country",
        "index": 0,
        "label": "Country",
        "dataTypes": [
            "string"
        ],
        "formats": [
            {
                "type": "string",
                "format": {
                    "hasRepeat": false,
                    "longest": 9,
                    "scale": "scaleOrdinal"
                }
            }
        ]
    },
    {
        "column": "2005",
        "index": 1,
        "label": "2005",
        "dataTypes": [
            "number"
        ],
        "formats": [
            {
                "type": "number",
                "format": {
                    "min": 50.4,
                    "max": 73,
                    "scale": "scaleLinear",
                    "hasEmptyValues": false,
                    "sequential": false
                }
            }
        ]
    },
    {
        "column": "2023",
        "index": 2,
        "label": "2023",
        "dataTypes": [
            "number"
        ],
        "formats": [
            {
                "type": "number",
                "format": {
                    "min": 56.9,
                    "max": 77.4,
                    "scale": "scaleLinear",
                    "hasEmptyValues": false,
                    "sequential": false
                }
            }
        ]
    },
    {
        "column": "2024",
        "index": 3,
        "label": "2024",
        "dataTypes": [
            "number"
        ],
        "formats": [
            {
                "type": "number",
                "format": {
                    "min": 50.4,
                    "max": 73,
                    "scale": "scaleLinear",
                    "hasEmptyValues": false,
                    "sequential": false
                }
            }
        ]
    },
    {
        "column": "2025",
        "index": 4,
        "label": "2025",
        "dataTypes": [
            "number"
        ],
        "formats": [
            {
                "type": "number",
                "format": {
                    "min": 56.9,
                    "max": 77.4,
                    "scale": "scaleLinear",
                    "hasEmptyValues": false,
                    "sequential": false
                }
            }
        ]
    }
]