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

@kasko/quote-calculator-js

v1.2.3

Published

KASKO Spreadsheet Quote Calculator

Downloads

36

Readme

quote-calculator-js-lib

KASKO Spreadsheet Quote Calculator Lib.

When in doubt, consult documentation!

Requirements

Usage

yarn add @kasko/quote-calculator-js

Example:

import { Calculator } from '@kasko/quote-calculator-js';

// Initiate calculator instance
const calculator = new Calculator();

(async () => {
  // Relative location of xlsx file
  const path = './kasko-demo.xlsx';
  /**
   * This will fill `Field Value` column based on
   * `Input field` name match. It will replace empty
   * fields with `null`.
   */
  const input = {
    duration: 'P5Y',
    policy_start_date: '2018-02-10',
  };
  /**
   * This will fill `Field Value` column based on
   * `Predefined field` name match. It will leave default
   * values as is, only replacing the ones provided in config.
   */
  const config = {
    tax_rate: 0.05
  };

  // Loads xlsx file, parses it and fills input and config values.
  await calculator.init(path, input, config);

  /**
   * To get calculated field `isValid` column.
   *
   * @example output:
   * ```json
   * {
   *   duration: true,
   *   policy_start_date: true
   * }
   * ```
   */
  const validation = calculator.validateInput();

  /**
   * To get calculated output data based on
   * `Quote field` and `Quote value` columns.
   *
   * @example output:
   * ```json
   * {
   *   gross_premium: 30000,
   *   extra_data: {
   *     flow: 'default'
   *   }
   * }
   * ```
   */
  const output = calculator.getOutput();
})()

In case of loading parsed xlsx file as json:

+const workbook = require('./kasko-demo.json');
-const path = './kasko-demo.xlsx';
 ...
+await calculator.init(workbook, input, config);
-await calculator.init(path, input, config);

Development

Installation

yarn install

Building

yarn build

Developing with real pricing: First you must edit the development file /index.js to take correct input and pricing file.

Then run build command.

And finally run:

yarn start

To execute that development file and see the result.

Testing

Single run (of everything):

yarn test

Testing formulas

yarn test:formulas

Testing pricing

yarn test:pricing

Running generic tests

yarn test:generic

Debug UI mode

First make sure to set path to pricing xlsx file in ./debugger/index.tsx file:

@@ -1,32 +1,19 @@
 import { Calculator } from '../packages/calculator/src/calculator';
 // @ts-ignore
-import Workbook from '../pricing/baloise-legal-protection.xlsx';
+import Workbook from '../pricing/kasko-demo.xlsx';

 import { debuggerApp } from './app';

To start UI run:

yarn debug

Now you can open UI in browser by following the url in terminal. It is possible to update calculator & formula code and see changes in UI.

Debug performance

First make sure to set path to pricing xlsx file in ./trace/trace.ts file:

@@ -1,32 +1,19 @@
 import { Calculator } from '../packages/calculator/src/calculator';
 // @ts-ignore
-import Workbook from '../pricing/pricing/fermion-motor.xlsx';
+import Workbook from '../pricing/kasko-demo.xlsx';

import { initTrace, writeTrace } from './utils';

To generate trace run:

yarn trace

This now generated ./trace.json file in repo root dir. This trace file can now be uploaded (file is not uploaded to any server, instead it's uploaded to browser memory) to chrome://tracing/ or https://ui.perfetto.dev/.