Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@xm-fe/xm-base
Advanced tools
2022 鲜沐科技 前端通用逻辑包
npm i @xm-fe/xm-base
trimAllFields
, FormData 不处理trimAllFields({ a: ' 12 3 4 5 ' }) // { a: '12 3 4 5' }
number.formatMoney
负数问题, 默认输出更改number.formatMoney(1299) // ¥1,299.00
currencyCNY
金额处理方法,使用number.formatMoney
import { number } from '@xm-fe/xm-base'
/**
* 金额处理默认返回 ¥0.00 格式
* 千分位分隔,支持保留多个小数位
* @param {String|Number} value 需要格式化的数值
* @param {Number} precision 小数精确位数,默认是 2
* @param {String | boolean} prefix 金额前缀 为 true 则显示默认的标志 ¥
* @returns {String} 分隔号和小数位数处理后的字符串, 当值不能转化为数字
*/
number.formatMoney('1299', 2, true) // ¥1,299.00
number.formatMoney(1299, 2, '¥') // ¥1,299.00
number.formatMoney(1299, 2, '$') // $1,299.00
number.formatMoney(1299, 2, false) // 1,299.00
import { number } from '@xm-fe/xm-base'
/**
* 金额处理默认返回 ¥0.00 格式
* 千分位分隔,支持保留多个小数位
* @param {String|Number} value 需要格式化的数值
* @param {Number} precision 小数精确位数,默认是 2
* @param {String | boolean} prefix 金额前缀 为 true 则显示默认的标志 ¥
* @returns {String} 分隔号和小数位数处理后的字符串, 当值不能转化为数字
*/
number.formatMoney('1299', 2, true) // ¥1,299.00
number.formatMoney(1299, 2, '¥') // ¥1,299.00
number.formatMoney(1299, 2, '$') // $1,299.00
number.formatMoney(1299, 2, false) // 1,299.00
import { currencyCNY, isDef } from '@xm-fe/xm-base'
currencyCNY(99) //¥99.00
currencyCNY(''|null|undefined) //''
isDef([]) // false
isDef('') // false
isDef(undefined) // false
isDef(null) // false
isDef(0) // true
import { number } from '@xm-fe/xm-base'
number.formatMoney() // 金额千分位处理 number.formatMoney()
number.toFixed() // 精确的四舍五入 -> return string
number.toFixedNumber() // 精确的四舍五入 -> return number
number.isNumber() // 判断是否为数字(可计算),isNaN Infinity 也返回为 false
number.plus() // 加法 plus(1,2,3) plus([1,2,3]) plus([1,2], [3,4])
number.minus() // 减法 minus(1,2,3) minus([1,2,3]) minus([1,2], [3,4])
number.times() // 乘法 times(1,2,3) times([1,2,3]) times([1,2], [3,4])
number.divide() // 除法 divide(1,2,3) divide([1,2,3]) divide([1,2], [3,4])
如果计算时不要求保留几位小数,请使用四则运算方法计算,切勿直接使用 js 的四则运算!!!
如果计算需要保留小数位,比如计算货品相加后的金额数字需要保留 2 位小数,则可以直接使用number.toFixed(0.1 + 0.2, 2)
结果是'0.3'
# 安装依赖
npm i
# 发布流程
# 编译
npm run build
# 第一次登录
npm login
# 发布(发布前修改版号)
npm publish --tag
# 配置npm全局使用淘宝镜像源
npm config set registry https://registry.npm.taobao.org
# 配置npm全局恢复官方镜像源
npm config set registry https://registry.npmjs.org
# 本项目
npm link
# 引用调试的项目
npm link @xm-fe/xm-base
# 取消关联
npm unlink 包名
# 查看
npm ls -g
FAQs
We found that @xm-fe/xm-base demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.