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

asset-tool

v1.2.0

Published

Tool to help calculate and view a breakdown of daily, monthly, and annual finances.

Downloads

15

Readme

Asset tool

Build Status semantic-release

NOTE: Only USD currently supported

This tool is geared for personal use and is not recommended / robust enough to be used in a production environment.

The workflow for using this tool is as follows:

  1. Type out your income and expenses by interval (daily, monthly, annual) in a Node.js script that imports this module.
  2. Run the file to calculate your total earnings and expenses per each interval.
  3. Save the summary of the calculations to a pdf or html file, or simply print the summary to your console.

See example.js for an example script that uses this tool to calculate a daily, monthly, and annual breakdown of your finances.

The following is an image of the html summary generated from running example.js.

Example summary

Usage

Install

npm i -s asset-tool

Import the module

const Asset = require('asset-tool')

QuickStart

Simply use example.js as a template, or read on from here to learn how to setup the tool from the ground up.

Declare your assets

Asset.construct(amount, type, interval, label)

  • amount: A number value in dollars of the amount of the asset.
    • Can be an array of numbers that will be averaged. (e.g. [200, 400] will be averaged to 300)
  • type: Can be a value from Asset.TYPE (see Static Values)
  • interval: Can be a value from Asset.INT (see Static Values)
  • label: A string identifying the asset (e.g. 'Rent')
  • isCents: defaults to false, if set to true, amount will be in cents.

Example

Asset.construct(100000, Asset.TYPE.INCOME, Asset.INT.ANNUAL, 'Tech Company')

Example of average amounts

Asset.construct([65, 100], Asset.TYPE.EXPENSE, Asset.INT.MONTHLY, 'Internet')

Example when an amount of $19.99 is specified in cents

Asset.construct(1999, Asset.TYPE.EXPENSE, Asset.INT.MONTHLY, '3 payments of', true)

Declare using default constructor

new Asset(amount, {type: '', interval: '', label: ''}, isCents

  • amount: A number value in dollars of the amount of the asset.
    • Can be an array of numbers that will be averaged. (e.g. [200, 400] will be averaged to 300)
    • Always Required
  • type: Can be a value from Asset.TYPE (see Types of Assets)
    • Optional. Defaults to Asset.TYPE.EXPENSE
  • interval: Can be a value from Asset.INT (see Available Intervals)
    • Optional. Defaults to Asset.INT.MONTHLY
  • label: A string identifying the asset (e.g. 'Rent')
    • Optional. Defaults to Unlabelled
  • isCents: defaults to false, if set to true, amount will be in cents.
    • Optional. Defaults to false (dollars)

Include an Asset in calculations

include() each asset that you want to participate in final calculations. If you create assets and manipulate them with calculations, then you only want to include() the final asset.

Example:

Asset.construct([65, 100], Asset.TYPE.EXPENSE, Asset.INT.MONTHLY, 'Internet').include()

View results

You can run calculations and view the breakdown of all on your include()'d assets from:

  1. The command line.
  2. A generated HTML or PDF file.

To generate an html or pdf file at the end of your script include:

Asset.generateSummary()

See Generate Summary for an overview of generating a pdf or html.

To print your totals for each interval (daily, monthly, annual) in the command line, at the end of your script include:

Asset.printAll()

To print your totals and the breakdown for a specific interval, at the end of your script include:

Asset.printInterval(interval)

// Example for monthly interval
Asset.printInterval('monthly')

Generate Summary

A summary contains your totals by interval and the breakdowns that compose those totals.

By default, Asset.generateSummary() will generate an HTML file called summary.html in the directory that the script is run.

PDF options

To generate a pdf you have the following options. The example shows the defaults, the comments show possible values.

opts = {
  generatePdf: false, // true or false (if any other pdf option is specified this defaults to true)
  orientation: "portrait", // portrait or landscape
  format: "Letter", // A3, A4, A5, Legal, Letter, or Tabloid
  pdfName: "./summary.pdf" // Can be any file path string ending with .pdf
}

HTML options

Additionally, you can specify the html file's path.

opts = {
  htmlName: "./summary.html"
}

Shared options

For both html and pdf summaries, the following options are available.

opts = {
  open: false, // Open a new tab in default browser or pdf viewer on success
  noLogging: false // Don't log a success message upon summary creation
}
Asset.generateSummary(opts)

Types of Assets

An asset can be one of the following types,

  1. income: Amount gained from employment(s) (net positive)
  2. investment: Amount gained from investment(s) (net positive)
  3. saving: Amount saved (net negative)
  4. expense: Amount spent (net negative)

and can programmatically be accessed using the following static properties:

Asset.TYPE = {
  INCOME: 'income',
  INVESTMENT: 'investment',
  SAVING: 'saving',
  EXPENSE: 'expense'
}

e.g. Asset.TYPE.INCOME.

Types are currently only used for grouping in the summary's financial breakdown.

Future plans will allow types to have properties attached to them, for instance,

  • A saving could accept a percent return for an interval.
  • An investment could accept the amount invested (net negative) and projected rates of return (net positive0).
  • An income could accept total tax percentages.

Available Intervals

An interval can be one of the following,

  1. daily
  2. monthly
  3. annual

and can programmatically be accessed using the following static properties:

Asset.INT = {
  DAILY: 'daily',
  MONTHLY: 'monthly',
  ANNUAL: 'annual'
}

e.g. Asset.INT.DAILY.

TODO

  • Add modifiers to certain types as specified in Types of Assets
  • Add tests and CI script to run those tests
  • Add quarterly intervals?
  • Make more robust / less hacky