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

@cosiu/periodix

v1.0.1

Published

A deterministic financial slicing engine for commercial leasing — split contracts into billing-accurate monthly segments.

Downloads

69

Readme

Periodix

面向商业地产租赁的确定性财务分片引擎,用于处理复杂的账期周期、按日折算、租金调整,保持数学一致性。


概述

这是一个 合同账期拆分与计费引擎,将一份租赁合同转化为一组财务一致的账期片段

解决的实际痛点:

  • 非自然月账期(如 14 号 → 次月 13 号)
  • 免租期
  • 租金递增(定点递增 / 周年递增)
  • 碎段按日折算
  • 跨月精度修正
  • 严格的片段合并规则

核心能力

1. 时间分片(切点模型)

引擎将合同时间线切成最小粒度片段,切点来源:

  • 合同起止日
  • 账期锚点(pivotDate / 拨片日)
  • 免租期边界
  • 递增事件生效日

每个片段在财务逻辑上是原子且同质的


2. 双权重体系

每个片段携带一个时间权重

• 桶权重(主权重)

基于账期周期计算:

权重 = 段天数 / 桶天数

用于:

  • 账期对齐
  • 周期归一化

• 自然月权重(修正层)

仅应用于碎段(非整月片段)

权重 = Σ (该月在段内的天数 / 该月总天数)

保证:

  • 跨月片段的财务精度
  • 消除账单畸变

3. 递增模型

支持复合叠加的调租规则:

  • POINT:在指定日期生效
  • ANNIVERSARY:每年在锚点日之后生效

实际利率:

R(t) = Π (1 + rate_k)

4. 免租期处理

免租期以二进制掩码作用于时间线:

  • 免租期内租金 = 0
  • 管理费仍照常收取

5. 片段合并(确定性压缩)

仅当满足以下条件时才合并相邻片段:

  • 同费率
  • 同免租状态
  • 非首期
  • 均为完整周期(权重为整数)

保证:

  • 财务不失真
  • 输出结果精简

6. 输出语义

每段输出类型:

| 类型 | monthEquivalent | termDays | | --- | --- | --- | | 整月 | 整数 | null | | 碎段 | null | 实际天数 |


使用示例

const Periodix = require('./Periodix');

const contract = {
  startDate: "2025-01-15",
  endDate: "2025-12-14",
  pivotDate: "2025-02-01",
  area: 100,
  baseTotalRentRate: 50000,
  serviceRate: 10,

  freePeriods: [
    { startDate: "2025-01-15", endDate: "2025-02-14" }
  ],

  increaseRules: [
    { type: "POINT", effectiveDate: "2025-06-01", rate: 0.05 },
    { type: "ANNIVERSARY", anchorDate: "2025-01-15", rate: 0.03 }
  ]
};

const result = Periodix.splitContractPeriods(contract);

console.log(result);

输出示例(简化)

[
  {
    "startDate": "2025-02-01",
    "endDate": "2025-02-28",
    "monthEquivalent": 1,
    "totalRent": 50000,
    "isFreeRent": false
  },
  {
    "startDate": "2025-03-01",
    "endDate": "2025-03-15",
    "termDays": 15,
    "totalRent": 25000,
    "isFreeRent": false
  }
]

设计原则

确定性

相同输入 → 相同输出,无隐藏状态。


财务完整性优先

  • 无四舍五入漂移
  • 不少收不多收
  • 自然月修正确保精度

关注点分离

| 层 | 职责 | | --- | --- | | 切分引擎 | 时间网格划分 | | 权重模型 | 时间归一化 | | 递增引擎 | 价格演化 | | 合并引擎 | 输出压缩 |


可组合

引擎可扩展支持:

  • 季度 / 年度账期
  • 多租户聚合
  • OLAP 分析
  • 分布式计费系统

数学基础

引擎等价于:

离散时间测度 + 分段常数函数积分系统

其中:

  • 时间被分割为可测区间
  • 每段携带权重(测度)
  • 价格是一个时间函数
  • 总金额为所有片段上的积分

适用场景

  • 商业地产租赁系统
  • 物业管理系统 SaaS
  • 财务计费引擎
  • 合同生命周期平台
  • 收入确认系统

已知限制

  • 基于月度账期范式设计

  • 暂不支持:

    • 周付
    • 日内实时调整
    • 增值税 / 税率层(应在外部叠加)

路线图

  • [ ] 季度 / 年度账期抽象
  • [ ] SQL 兼容计算模型
  • [ ] 流式计费支持
  • [ ] 可视化工具(时间线渲染)
  • [ ] NPM 包发布

许可证

MIT