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

dougy-lib

v0.5.6

Published

--- ### 获取应用 - 方法:`getBill` - 类型:`(target: string) => Promise<Menu | undefined>` - 参数: - `name`单据名称**billName**/单据类型**billType**,**必传** - `menus`菜单列表,**非必传** - 说明:从菜单列表中获取billName/billType的菜单,若传入menus,则从menus中查找,默认情况下从缓存中查找 - 代码示例: ```typescript imp

Downloads

9

Readme

业务


获取应用

  • 方法:getBill
  • 类型:(target: string) => Promise<Menu | undefined>
  • 参数:
    • name单据名称billName/单据类型billType必传
    • menus菜单列表,非必传
  • 说明:从菜单列表中获取billName/billType的菜单,若传入menus,则从menus中查找,默认情况下从缓存中查找
  • 代码示例:
import { getBill } from "dougy-lib";

await getBill("收入合同"); // 通过名称获取收入合同应用
  • 返回示例:
{
  billType: "IncomeContract",
  billTypeName: "收入合同",
  cDataPower: "1",
  cProjectPower: "1",
  createTime: "",
  creatorId: "",
  creatorName: "",
  diyId: "IncomeContract",
  diyType: "1",
  icon: "static/images/icon/incomeContract.png",
  isDefault: "0",
  isEnable: "0",
  isFavourite: "0",
  oldName: "收入合同",
  recordId: "",
  sort: 1,
  vBillPower: [
    0, 1, 2, 3, 4, 5, 7, 9, 15, 16, 17, 18, 19, 20, 15, 16
  ],
  vModule: "CR",
  vModuleName: "合同管理",
  vName: "收入合同",
  vPkMenu: "81",
};

获取应用权限

  • 方法:getPower
  • 类型:function getPower(target: Menu | string): Power & { notExist: boolean; }
  • 参数:
    • target单据对象/单据名称/单据类型
  • 说明:从单据对象,或用单据名称/单据类型查询到的单据对象中取得应用的权限
  • 代码示例:
import { getPower } from "dougy-lib";

const incomeContract = {...} // 收入合同应用对象
getPower(incomeContract);
getPower("收入合同")
getPower("IncomeContract")
  • 返回示例:
{
  vBillPower: [], // 业务权限列表
  cDataPower: "empty", // 数据权限
  cProjectPower: "empty", // 项目权限
  notExist: true, // 是否未查询到应用
}

验证应用权限

  • 方法:powerVerify
  • 类型: (target: string, powerName: (typeof POWER_NAMES)[number]) => { valid: boolean; message: string; }
  • 参数:
    • target单据名称/单据类型
    • powerName权限名称 查看, 新增, 编辑, 删除, 导入, 打印, 支付确认, 导出, 配置, 修订, 项目看板, 公司看板, 统计分析, 开票, 付款, 去签证, 去执行, 去结算, 去申请开票, 去开票, 去收款, 去申请付款, 去付款, 去采购
  • 说明:从单据对象,或用单据名称/单据类型查询到的单据对象中取得应用的权限
  • 代码示例:
import { powerVerify } from "dougy-lib";

powerVerify("收入合同", "查看")
powerVerify("IncomeContract", "新增")
  • 返回示例:
{
  valid: false, // 是否有权限
  message: "未查询到应用权限", // 提示文字
}

获取应用列表权限

  • 方法:getDataPower
  • 类型:(target: string) => DataPowerReturn
  • 参数:
    • target单据名称/单据类型
  • 说明:获取单据列表的数据权限
  • 代码示例:
import { getDataPower } from "dougy-lib";

getDataPower("收入合同")
getDataPower("IncomeContract")
  • 返回示例:
{
  cProjectPower: "0", // 是否有权限
  cDataPower: "0", // 提示文字
}

获取单据在选择时的权限

  • 方法:getSelectDataPower
  • 类型:(options: GetSelectDataPowerOptions) => DataPowerReturn
  • 参数:
    • options.bill页面单据名称/单据类型
    • options.selectTarget选择目标的单据名称/单据类型
    • options.billIsDoc页面单据是否为档案类型
    • options.selectTargetIsDoc选择目标单据是否为档案类型
  • 代码示例:
import { getSelectDataPower } from "dougy-lib";

getSelectDataPower({
  bill: "收入合同",
  selectTarget: "项目",
  billIsDoc: false,
  selectTargetIsDoc: false
})
  • 返回示例:
{
  cProjectPower: "0", // 是否有权限
  cDataPower: "0", // 提示文字
}

获取参数控制开启状态

  • 方法:getParameterConfiguration
  • 类型:(type: string, i: number) => boolean
  • 参数:
    • type单据名称
    • i位置
  • 代码示例:
import { getParameterConfiguration } from "dougy-lib";

getParameterConfiguration("付款登记", 7)
  • 返回示例:
false

数据


验证空数据

  • 方法:dataVerify
  • 类型:
    • function dataVerify<T = unknown>(data: T | undefined, defaultData: T): T
    • function dataVerify<T = unknown>(data: T | undefined): T | undefined
  • 参数:
    • data验证数据对象
    • defaultData默认值,非必传
  • 代码示例:
import { dataVerify } from "dougy-lib";

dataVerify("", [])
dataVerify(undefined, [])
dataVerify([{}], [])
dataVerify([{}])
  • 返回示例:
// ""
// []
// [{}]
// [{}]

列表合并

  • 方法:mergeList
  • 类型:<P, T = P>(prevList: P[], curList: T[], options?: { params?: Record<string, unknown> | undefined; transform?: ((item: T) => P) | undefined; } | undefined) => P[]
  • 参数:
    • prevList历史数组
    • curList当前数组
    • options合并配置非必传
    • options.params分页参数非必传
    • options.transformcurItem到prevItem的转换方法非必传
  • 说明:如果是单据列表数据的合并,则必须传options.params
  • 代码示例:
import { mergeList } from "dougy-lib";

mergeList([1,2], [3,4])
mergeList(
  [
    { v: 123, c: "222" },
    { v: 123, c: "222" },
  ],
  [{ t: "2223" }],
  {
    transform: item => ({ v: Number(item.t), c: "1" }),
  }
);
  • 返回示例:
// [1,2,3,4]
// [
//   { v: 123, c: "222" },
//   { v: 123, c: "222" },
//   { v: 2223, c: "1" }
// ]

数组比较 arrayCompare

对象比较 objCompare

金额转大写 amountUpper

是否改变 isDiff

工具


缓存 DgyStorage

获取URL查询参数

  • 方法:getUrlQuery
  • 类型:(params?: { url?: string, key?: string }) => Record<string, string>
  • 参数:
    • url需要获取参数的url,非必传
    • key需要从url中获取的某一个参数的键名,非必传
  • 说明:从url中获取参数,两个参数都是非必传,传入url则从该url中获取参数,默认从当前页面url中获取,传入key则返回该键名对应的查询参数,默认返回所有参数的对象
  • 代码示例:
import { getUrlQuery } from "dougy-lib";

getUrlQuery(); // 获取当前url中所有参数
getUrlQuery({ key: "corpId" }) // 获取当前url中的corpId的值
getUrlQuery({ key: ["userId", "corpId"] }) // 获取当前url中的{userId, corpId}
getUrlQuery({ url: "xxx" }) // 获取传入url中的所有参数
getUrlQuery({ url: "xxx", key: "corpId" }) // 获取传入url中的userId
getUrlQuery({ url: "xxx", key: ["userId", "corpId"] }) // 获取传入url中的{userId, corpId}
  • 返回示例:
// {userId: "123", corpId: "ding123"}
// 或
// "123"
// 或
// undefined

数字转内存大小 toSC

对象转字符串 jsonToString

字符串转对象 stringToJson

UUID uuid

路径取值

  • 方法:getPropByPath
  • 类型:<T = unknown>(target: Record<string, unknown> | unknown[], path: string, defaultValue?: T) => T
  • 参数:
    • target取值对象
    • path取值路径
    • defaultValue未取到值时的默认值
  • 说明:可以使用字符串拼接属性,从目标对象中取值
  • 代码示例:
import { getPropByPath } from "dougy-lib";

getPropByPath({}, "a.b")
getPropByPath(
  { test: [{ val: [{ num: 123, str: "string" }] }] },
  "test[0].val[0].num"
)
  • 返回示例:
// ""
// 123

防抖

  • 方法:debounce
  • 类型:(fn: (...arg: unknown[]) => unknown | Promise<unknown>, delary?: number): (...arg: unknown[]) => void
  • 参数:
    • fn用于防抖的方法回调
    • delary延时,默认150s,非必传
  • 说明:无论执行多少次,都只会在最后一次触发delary毫秒后才执行,并且每次执行,都会刷新delary
  • 代码示例:
import { debounce } from "dougy-lib";

const testFn = debounce((i: number) => {
  console.log(i)
}, 200)

testFn(1);
testFn(2);
testFn(3);
setTimeout(() => {
  testFn(4);
}, 150)
setTimeout(() => {
  testFn(5)
}, 300)
setTimeout(() => {
  testFn(6)
}, 510)
  • 返回示例:
// 5
// 6

节流

  • 方法:throttle
  • 类型:(fn: (...arg: unknown[]) => unknown | Promise<unknown>, delary?: number): (...arg: unknown[]) => void
  • 参数:
    • fn用于节流的方法回调
    • delary延时,默认150s,非必传
  • 说明:在delary延时内,只执行第一次的调用,后面的调用将被取消
  • 代码示例:
import { throttle } from "dougy-lib";

const testFn = throttle((i: number) => {
  console.log(i)
}, 200)

testFn(1);
testFn(2);
testFn(3);
setTimeout(() => {
  testFn(4);
}, 150)
setTimeout(() => {
  testFn(5)
}, 300)
setTimeout(() => {
  testFn(6)
}, 510)
  • 返回示例:
// 1
// 5
// 6

复选

  • 方法:checkSelect
  • 类型:<I = string | number | Record<string, unknown>>(checkList: I[], item: I, key?: keyof I | undefined) => CheckoutSelectReturn<I>
  • 参数:
    • checkList已选列表
    • item判断选中项
    • key判断键名,当item是对象时需要传该参数,非必传
  • 说明:判断某项是否存在列表中,并返回复选结果
  • 代码示例:
import { checkSelect } from "dougy-lib";

checkSelect([1, 3, 6], 2)
checkSelect([{ a: 1 }, { a: 2 }, { a: 3 }], { a: 2 }, "a")
  • 返回示例:
{
  list: [1, 3, 6, 2],
  prevList: [1, 3, 6],
  isHad: false,
}
{
  list: [{ a: 1 }, { a: 3 }],
  prevList: [{ a: 1 }, { a: 2 }, { a: 3 }],
  isHad: true,
}

队列执行 queue

获取终端 getTerminal

配置


数字


税额计算

计算税额

  • 方法:getTaxAmount
  • 类型:(num: string | number, rate: string | number, type: "byAmount" | "byIncluded") => number
  • 参数:
    • num用于计算税额的金额
    • rate税率
    • type byAmount:根据不含税金额计算,byIncluded:根据含税金额计算
  • 说明:根据含税金额/不含税金额、税率计算税额
  • 代码示例:
import { getTaxAmount } from "dougy-lib";

getTaxAmount("167936.29", 13, "byIncluded") // "19320.10"

计算不含税金额

  • 方法:getAmount
  • 类型:(taxIncludedAmount: number | string, rate: number | string, retain?: number | "none") => TaxResult
  • 参数:
    • taxIncludedAmount含税金额
    • rate税率
    • retain保留小数位(默认2)
  • 说明:根据含税金额/不含税金额、税率计算税额
  • 代码示例:
import { getAmount } from "dougy-lib";

getAmount(167936.3, 13)
  • 返回示例:
{
  taxIncludedAmount: "167936.30",
  amount: "148616.19",
  rate: 13,
  taxAmount: "19320.11",
}

计算含税金额

  • 方法:getTaxIncludedAmount
  • 类型:(amount: number | string, rate: number | string, retain?: number | "none") => TaxResult
  • 参数:
    • amount不含税金额
    • rate税率
    • retain保留小数位(默认2)
  • 说明:根据含税金额/不含税金额、税率计算税额
  • 代码示例:
import { getTaxIncludedAmount } from "dougy-lib";

getTaxIncludedAmount(148616.19, 13)
  • 返回示例:
{
  taxIncludedAmount: "167936.29",
  amount: "148616.19",
  rate: 13,
  taxAmount: "19320.10",
}

精度计算

  • 对象:calc
  • 方法:
    • add (...nums: (number | string)[]) => number
    • sub (...nums: (number | string)[]) => number
    • mul (...nums: (number | string)[]) => number
    • div (...nums: (number | string)[]) => number
  • 参数:
    • nums需要计算的数字集合
  • 说明:calc是一个包含加减乘除方法的对象,同样可以单独使用任何一个计算方法,calc中计算的使用方式,同单据使用一致
  • 代码示例:
import { calc } from "dougy-lib";
// 或单个使用
// import { add, sub, mul, div } from "dougy-lib"

calc.add(0.1, 0.1) // 0.2
calc.sub(0.3, 0.1) // 0.2
calc.mul(0.6, 3) // 1.8
calc.div(0.3, 0.1) // 3
calc.div(167936.3, 1.13).toFixed(2) // "148616.19"

转千分符金额

  • 方法:numberCurrency
  • 类型:(num: number | string, options?: CurrentSeparateOptions) => string
  • 参数:
    • num需要转换的数字或字符串,必传
    • options需要从url中获取的某一个参数的键名,非必传
      • options.prefix字符串前缀,非必传
      • options.suffix字符串后缀,非必传
      • options.retain保留位数,默认跟随num的小数位长度,非必传
      • options.currency是否添加货币符号,非必传
  • 说明:将传入的数值转换为带有千分符的金额数值
  • 代码示例:
import { currencyConvert } from "dougy-lib";

numberCurrency(123) // "123"
numberCurrency("123456.001") // "123,456.001"
numberCurrency("12332543.00123", { retain: 3, currency: true }) // "¥12,332,543.001"
numberCurrency("12332543.00123", { prefix: "-", suffix: "=", retain: 3 }) // "-12,332,543.001="

是否为有效数字 numberValid

任意值转数字 toNumber

功能


数据请求 http

请求对比 pedding

Vue


指令

金额千分符 currency

过滤

金额千分符 currency

自定义


枚举