
Security News
PolinRider: North Korea-Linked Supply Chain Campaign Expands Across Open Source Ecosystems
PolinRider expands across npm, Packagist, Go modules, and Chrome extensions, using hidden loaders to target developer environments.
@haluo/util
Advanced tools
摩托范工具库
npm publish // 发布包
npm unpublish --force // 强制删除
npm unpublish @haluo/util@0.0.0 // 删除指定版本的包
npm install -D @haluo/util
yarn add -D @haluo/util
// npm install -D @types/@haluo/util # 使用ts构建时
// 方式一
import { cookie, date, dom, match, number, tools } from '@haluo/util' // 全量引用
// 方式二
import tools from '@haluo/util/dist/modules/match' // 局部引用
// 方式三
const date = require('@haluo/util').date // 全量引用
// 方式四
import haluoUtil from '@haluo/util' // 全量引用
// 方式五
import util from '@haluo/util'
util.install(Vue)
this.$cookie、this.$date、this.$dom、this.$match、this.$number、this.$tools
import { date } from '@haluo/util';
date.format(new Date()) // 默认格式 'YYYY-MM-DD HH:mm:ss'
date.format(1586840260500) // 默认格式,传参为linux时间
date.format(new Date(), 'YYYY:MM:DD') // 自定义格式 'YYYY:MM:DD'
addDaysToDate('2020-10-15', 10) // '2020-10-25'
addDaysToDate('2020-10-15', -10) // '2020-10-05'
date.remainTime(new Date()) // 入参为 endTime,出参为:{dd: '天', hh: '时', mm: '分', ss: '秒'}
date.remainTime(new Date(), 1586840260500) // 入参为 endTime、startTime,出参为:{dd: '天', hh: '时', mm: '分', ss: '秒'}
date.remainTime(1586840260500) // {dd: '天', hh: '时', mm: '分', ss: '秒'}
date.formatPassTime(new Date()) // *年前 *个月前 *天前 *小时前 *分钟前 刚刚
formatPassTimeForDetail(1494141000*1000, 'YYYY-MM-DD', false) // *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
import { dom } from '@haluo/util';
dom.createElement('div', '', 'body')
// "1234<a href=\"https://m.jddmoto.com/home-garage\">https://m.jddmoto.com/home-garage</a>你好"
dom.wrapperA('1234https://m.jddmoto.com/home-garage你好')
getFormData({a: 1, b: 2}) // 返回 FormData
import { format } from '@haluo/util';
format.transformObjectNullVal({ a: null, b: 0}, '23') // {a: "23", b: 0}
import { match } from '@haluo/util';
match.checkType('10.120.33.11', 'ip') // true
match.checkType('13111111111', 'phone') // true
match.checkType('wanghui@jddmoto.com', 'email') // true
import { number } from '@haluo/util';
number.formatNumber(1) // 01
number.formatPhone(13111111111) // 131****1111
number.convertToWan(123000) // 12.3万
number.convertToThousand(1200) // 1.2k
number.random(1, 100) // 4
number.formatMoney(123456) // 123,456
number.formatPhoneNumber(13111111111) // 131 1111 1111
import { openApp } from '@haluo/util';
常用函数工具库(防抖、节流、正则类型检测、深浅拷贝等) import { tools } from '@haluo/util';
tools.deepCopy({a: {b: 2}, c: {d: 3}}) // {a: {b: 2}, c: {d: 3}}
tools.deepCopy2({a: {b: 2}, c: {d: 3}}) // {a: {b: 2}, c: {d: 3}}
tools.debounce(func, 300)(args)
tools.throttle(func, 300)(args)
tools.loadJs('https://cdn.jsdelivr.net/npm/vant@2.10.1/lib/index.js').then()
tools.loadCss('https://cdn.jsdelivr.net/npm/vant@2.10.1/lib/index.css').then()
tools.startScroll()
tools.stopScroll()
tools.clipboard('test')
tools.firstUpperCase('abcde') // Abcde
tools.guid() // a5a35c73-f516-9f9d-ec66-78163d092cd2
tools.getBytesOfText('张三a1') // 6
tools.objectToArray({a: 1, b: 2}) // ["a=1", "b=2"]
tools.convertKeyValueEnum({a: 1, b: 2}) // {1: "a", 2: "b"}
tools.uniqueArr[1, 2, 2, 3]) // [1, 2, 3]
tools.swapArray([1, 2, 3, 4], 2, 3) // [1, 2, 4, 3]
tools.filterEmoji() // string
tools.containsEmoji() // true or false
tools.containsHanZi('123哈哈456') // true
tools.isEmpty() // true or false
tools.isDefined() // true or false
tools.sensitiveField(13111111111, 3, 4) // 131****1111
tools.getUrlParams('https://www.baidu.com?a=1&b=2') // {a: "1", b: "2"}
tools.getUrlParams('file:///**/index.html#/certified-sign?a=1&b=2') // {a: "1", b: "2"}
import { sentry } from '@haluo/util';
import { sentry } from '@haluo/util';
const option = {
dsn: http://753ce3bf82e94ab0aa7b5e62fae16d3c@sentry.***.com:9000/2
}
const Sentry = sentry.getInstance(Vue, option);
Vue.prototype.$sentry = sentry;
this.$sentry.log('test');
FAQs
We found that @haluo/util demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 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.

Security News
PolinRider expands across npm, Packagist, Go modules, and Chrome extensions, using hidden loaders to target developer environments.

Security News
Open source attacks are accelerating as AI coding agents pull in dependencies faster, with less human review.

Research
/Security News
Malicious Chrome and Firefox extensions posed as free VPNs while stealing clipboard data through later extension updates.