Socket
Socket
Sign inDemoInstall

@kkday/web-js-lib

Package Overview
Dependencies
1
Maintainers
4
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @kkday/web-js-lib

kkday front end javascript libraries


Version published
Maintainers
4
Install size
1.40 MB
Created

Readme

Source

@kkday/web-js-lib

npm (scoped)

Install

$ npm install @kkday/web-js-lib

Usage

SkuCalculator

Calculate valid sku, amount, price and detail status of each spec according to selected specs.

// load SkuCalculator into project
import { SkuCalculator } from '@kkday/web-js-lib';

// specs
const specs = {
	depart: [
		'Taipei',
		'Kaohsiung',
	],
	arrive: [
		'Taipei',
		'Kaohsiung',
	],
	age: [
		'adult',
		'child',
	],
};

// skus composed with spec combination, amount and price
const skus = [
	{
		spec: {
			age: 'adult',
			depart: 'Taipei',
			arrive: 'Kaohsiung'
		},
		amount: 5,
		price: 1000,
	},
	{
		spec: {
			age: 'child',
			depart: 'Taipei',
			arrive: 'Kaohsiung'
		},
		amount: 3,
		price: 500,
	},
	{
		spec: {
			age: 'adult',
			depart: 'Kaohsiung',
			arrive: 'Taipei'
		},
		amount: 4,
		price: 800,
	},
	{
		spec: {
			age: 'child',
			depart: 'Kaohsiung',
			arrive: 'Taipei'
		},
		amount: 2,
		price: 400,
	},
];

// define which spec(s) make sku(s) primary
const primarySpecs = {
	age: 'adult'
};

// skus data contain amount or not
const hasAmount = true;

// define which spec(s) can be selected with multiple values
const multiSpecs = ['age'];

// create SkuCalculator instance
const skuCalculator = new SkuCalculator({
	specs,
	skus,
	primarySpecs,
	hasAmount,
	multiSpecs
});

// set selected specs
const selectionArray = [
	{
		amount: 2,
		spec: {
			age: 'adult',
			depart: 'Taipei',
			arrive: 'Kaohsiung',
		},
	},
	{
		amount: 3,
		spec: {
			age: 'child',
			depart: 'Taipei',
			arrive: 'Kaohsiung',
		},
	}
];
skuCalculator.setSelectionArray(selectionArray);

// print calculation result
console.log(skuCalculator.specStatus);
console.log(skuCalculator.statistics);
console.log(skuCalculator.selectionSpecStatus);

FAQs

Last updated on 04 Nov 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc