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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sunmi/max-money-calculator

v3.2.9

Published

> 面向 browser 使用的 npm 包,使用 ts 开发,使用 rollup 构建

Downloads

95

Readme

money-calculator

面向 browser 使用的 npm 包,使用 ts 开发,使用 rollup 构建

用于Gpos业务的算价引擎

在模型完成业务抽象之前,暂不保证适配其他业务

插件

注意:使用 Jest Runner 而非 Jest,Jest Runner 适用于单步调试

开发

@sm/max-dslpeerDependency(optional)yarn install / CI 不会拉取私库;esbuild 构建不依赖它。本地跑 yarn test / Jest 前,在内网环境自行安装,例如:yarn add -D @sm/[email protected](并配置 registry.npm.sunmi.com 等)。

# 安装依赖
yarn bootstrap

# 调试
yarn start

构建

yarn build

API

初始化实例

// 0. 将算价引擎产物导入IDE(应用工程使用全局逻辑,模型工程使用自定义工具方法)

// 1. 初始化算价引擎实例
// tips: 由于模型IDE和应用IDE创建工具函数的方式差异,dsl对象的前缀xx存在不同
// 应用IDE,新建全局逻辑,命名 MoneyCalculator
const MoneyCalculator = max.globalFn.MoneyCalculator();
const calculator = new MoneyCalculator({
  orderInfo: {...},
  activityList: [...],
  couponList: [...],
  memberLevel: {...},
  memberActivityList:  [...],
});

// 模型IDE,新建自定义工具,命名 MoneyCalculator
const MoneyCalculator = max.util.MoneyCalculator();
const calculator = new MoneyCalculator({
  orderInfo: {...},
  activityList: [...],
  couponList: [...],
  memberLevel: {...},
  memberActivityList:  [...],
});

MoneyCalculator类定义

declare class MoneyCalculator {
    static quantity: {
      PRECISION: string;
      // 构造一个库存对象
      of: (quantity?: number, unit?: string) => QuantityObject;
      // quantity 存储数量转视图数量
      toViewQuantity: (quantityInfo: QuantityObject) => number;
      // 判断对象是否合法
      isQuantity: (quantityInfo: any) => any;
    };
    // 商品售价(规格、加料、套餐)
    static calcItemOriginalPrice(product: any): MoneyObject;
    // 商品小计:商品售价 * 数量
    static calcItemOriginalSubtotalAmount(product: any): MoneyObject;
    
    // 兼容老版本引擎调用代码
    static promotion: {
        // 计算营销优惠后的价格
        calcPromotion(order: OrderInfo, activityList: ActivityItem[], couponList: CouponItem[], memberLevel: MemberLevel, memberActivityList: ActivityItem[]): OrderInfo;
    };

    constructor(options: {
        orderInfo: OrderInfo;
        activityList?: ActivityItem[];
        couponList?: CouponItem[];
        memberActivityList?: ActivityItem[];
        memberLevel?: MemberLevel;
    });
    private _analyze;

    // 实例方法
    calcProductOriginalPrice(product: any): MoneyObject;
    calcItemOriginalSubtotalAmount(product: any): MoneyObject;
    calcItemTransactionSubtotalAmount(transactionPrice: MoneyObject, quantityInfo: QuantityObject): MoneyObject;
    // 订单总计
    calcOriginalTotalAmount(): OrderInfo;
    // 订单交易总计
    calcTransactionTotalAmount(): MoneyObject;
    // 订单税前总计
    calcActualAmount(): OrderInfo;
    // 订单税额
    calcTaxAmount(): OrderInfo;
    // 订单税后总计
    calcPayableAmount(): OrderInfo;
    // 一次性计算所有价格
    calcAllAmount(): void;
    // 返回结果orderInfo
    result(): OrderInfo;
}

使用方式

算价实例计算

// 方式一:按需分步计算
// 0. 初始化实例
const MoneyCalculator = max.globalFn.MoneyCalculator();
const calculator = new MoneyCalculator({
  orderInfo: {...},
  activityList: [...],
  couponList: [...],
  memberLevel: {...},
  memberActivityList:  [...],
});

// 1. 先算商品售价和商品小计
calculator.calcOriginalTotalAmount();
// 2. 再算订单税前总计
calculator.calcActualAmount();
// 等价于 
// MoneyCalculator.promotion.calcPromotion(orderInfo, activityList, couponList, memberLevel, memberActivityList);
// 3. 再算订单税额
calculator.calcTaxAmount();
// 4. 最后计订单税后总计
calculator.calcPayableAmount();
// 5. 获取订单结果
const finalOrderInfo = calculator.result();

// 方式二:全量计算
// 0. 初始化实例
const MoneyCalculator = max.globalFn.MoneyCalculator();
const calculator = new MoneyCalculator({
  orderInfo: {...},
  activityList: [...],
  couponList: [...],
  memberLevel: {...},
  memberActivityList:  [...],
});
// 1. 最后计订单税后总计
calculator.calcAllAmount();
// 2. 获取订单结果
const finalOrderInfo = calculator.result();

静态方法调用

const MoneyCalculator = max.globalFn.MoneyCalculator();

// 结果:{ quantity: 1000, unit: 'kg' }
const quantityObj = MoneyCalculator.quantity.of(1, 'kg');

const price = MoneyCalculator.calcItemOriginalPrice(productObj)

const subtotalAmount = MoneyCalculator.calcItemOriginalSubtotalAmount(productObj)