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

cpi-us

v1.202408.0

Published

US CPI historical data.

Downloads

122

Readme

cpi-us: US CPI Data in JSON Format

npm version Pipeline

Homepage | GitHub | GitLab

US CPI Data in JSON format. It is also accessible as an npm package. The data is the same as the Consumer Price Index for All Urban Consumers (CPI-U) provided by US Bureau of Labor Statistics.

There are two ways to use the data:

Direct Download

You can download the data directly through this link.

Format

The root of the JSON file is a dictionary that contains two properties: "firstYear" and "cpi". The value of "firstYear" indicates the earliest year of the data available. The value of "cpi" is an array, in which each element contains the CPI values of a single year. We refer to each element as a year data. The first element of "cpi" is a year data corresponding to the year specified in "firstYear", the second element of "cpi" corresponds to the year after that in "firstYear", etc.

Each year data is an array of size no larger than 12. Each element in a year data is the CPI values of a month in a chronic order. For example, the first element is the CPI value of January, and the fifth element is the CPI value of May.

For example, assuming the value of "firstYear" is 1913, and we intend to look up the CPI value of March, 2023.

  • First, we locate the year. That would be the 2023-1913+1=101'th element of the value of "cpi".
  • Then, March is the third month of a year. Therefore, the CPI value of interest is the 3rd value of the 101th element of the value of "cpi".

Via Npm

If you use npm, you can download the data by running:

npm install cpi-us

Usage

The npm package provides two functions:

getCPI(year, month)

Returns the CPI value of the specified year and month. Both parameters are numbers. For example, year may be 1913, 2000. month indicates the month of the year. month=1 refers to the first month of a year (January), and month=12 refers to the last month of a year (December).

getAllCPIs()

Returns all CPI values by returning the JavaScript object that results from directly loading the JSON file. See the "Direct Download > Format" subsection above for the data format.

getDateRange()

Returns the range of date of the data. Example return value:

[
  { year: 1913, month: 1 },
  { year: 2024, month: 4 },
];

meaning the data ranges from January 1913 to April 2024.

Contributing

Source code is available on GitHub.

To report a bug, visit the issue tracker.

To run test, run npm run test-all. To display test coverage, run npm run coverage. To build for production, run npm pack. To build the documentation, run npm run doc.

To send your contribution, open a pull request.

License

This package is licensed under 0BSD or CC0-1.0. You may choose to comply with either when using this package or dataset.

Copyright (C) 2024 8 Hobbies, LLC <[email protected]>

Permission to use, copy, modify, and/or distribute this software for anypurpose with or without fee
is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS SOFTWARE
INCLUDING ALL IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
LIABLE FORANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGESWHATSOEVER RESULTING
FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ANACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ACTION, ARISING OUT OFOR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

OR

This work is marked with CC0 1.0 Universal.
Visit https://creativecommons.org/publicdomain/zero/1.0/legalcode.txt for the full text of the license.