
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@o2oa/util
Advanced tools
browser
- Object 浏览器检测信息
uuid () : string
- Function 生成uuid
typeOf ( any ) : string
- Function 检查变量类型
execScript ( code ) : string
- Function 通过嵌入 script 标签,执行js脚本
exec ( text, [bind], [arg=null], [throwError= false] ) : any
- Function 执行代码片段, 使用Function包装
defer ( fn, [timer = 20], [bind], [arg] ) : promise
- Function 延时调用函数。有些方法只需要调用一次,但有可能在短时间内被多次触发时使用
copyTo ( text ) : promise
- Function 将文本内容拷贝到剪切板, 返回Promise, 如果剪贴板的内容被更新,它就会resolve,如果无法写入,则reject
htmlEncode ( html ) : string
- Function 对HTML文本进行编码
htmlDecode ( text ) : string
- Function 对编码后的HTML文本进行解码
htmlFilter ( html ) : string
- Function 过滤掉html中的javascript脚本内容,防止javascript注入
cloneObject ( obj ) : object
- Function 深度克隆一个Json对象,!!!不要传入javascript对象!!!
mergeObject ( obj... ) : object
- Function 合并多个JSON对象,传入要合并的多个JSON对象,并返回一个新的JSON对象。 !!!不要传入javascript对象!!!
openWindow ( url )
- Function 创建<a>标签在新浏览器窗口中打开url,防止浏览器禁止弹出窗口
camelCase ( str ) : string
- Function 将用 - 分隔的字符串,转换驼峰拼写格式
hyphenate ( str ) : string
- Function 将驼峰命名字符串转换为用 - 分隔每个单词
cleanText ( str ) : string
- Function 清除给定字符串的多余空字符
capitalize ( str ) : string
- Function 将字符串首字母大写
parallel ( promise... ) : promise
- async Function 传入多个promise,并行处理,等价与Promise.all
attempt ( obj ) : string | any
- Function 传入一个对象或map,返回第一个值为true的 key
isIterator ( any ) : boolean
- Function 判断传入的对象是否是可迭代对象
isPromise ( any ) : boolean
- Function 判断传入的对象是否是Promise
byteLength ( str ) : number
- Function 计算一个字符串所占的字节数
asyncLoading ( node, fun, ...par ) : any
- Function 第二个参数为异步函数,返回函数的返回值,并为node元素添加loading样式
jsonToCss ( json ) : any
- Function 将json对象转换为css文本,json的key为选择器
erase ( arr, value ) : any
- Function 在arr中删除所有值等于value的元素,直接修改arr
eraseFind ( arr, value ) : any
- Function 在arr中删除所有值等于value的元素,如果value是function,则使用findIndex,将value作为执行函数找到要删除元素的索引,直接修改arr
intersection ( arr1, arr2, fun ) : any
- Function 获取两个数组中的交集元素
complement ( arr1, arr2, fun ) : any
- Function 获取两个数组中, A数组相对于 B数组的补集。(在 B中存在,但 A中不存在的元素)
typeOfOrg ( str ) : string
- Function 判断一个字符串,是否是o2oa组织的distinguishedName,并判断类型。返回类型:I(身份)、P(个人)、U(组织)、G(群组)、R(角色)、UD(职务)、UA(组织属性)、PA(个人属性)、unknown
cn ( distinguishedName ) : string
- Function 返回distinguishedName的简称
import {dom} from '@o2oa/util';
const el = dom('div#myid.classname', {
"data-o2-attr": "div元素的自定义属性"
});
document.body.append(el);
dom.addClass('input#id', 'newClassname');
//...
dom.el ( selector, [el] ) : Element
- 此方法返回文档中与指定选择器或选择器组匹配的第一个 Element对象。如果找不到匹配项,则返回null。(同document.querySelector或Element.querySelector方法)
dom.els ( selector, [el] ) : NodeList
- 此方法返回与指定的选择器组匹配的文档中的元素列表 (使用深度优先的先序遍历文档的节点)。返回的对象是 NodeList 。(同document.querySelectorAll或Element.querySelectorAll方法)
dom.addClass ( el, className ) : Element
- 为一个Element添加class属性值
dom.removeClass ( el, className ) : Element
- 为一个Element删除一个class属性值
dom.hasClass ( el, className ) : boolean
- 判断一个Element的class属性中是否有指定的值
dom.toggleClass ( el, className, [force=false] ) : Element
- 换一个Element的class属性值。如果有指定属性值,则删除它;如果没有指定属性值,则添加它。
dom.checkClass ( el, className, check ) : Element
- 根据check的值(true 或 false),决定为Element元素添加或删除指定的className
dom.set ( el, key, [value] ) : Element
- 给目标Element设置属性
dom.get ( el, key ) : string
- 获取目标Element的属性值
dom.getScroll ( el) : object
- 获取目标Element滚动的距离
dom.getOffsetParent ( el ) : Element
- 获取包含目标Element的最近的上级定位元素
dom.getPosition ( el, [relative] ) : object
- 获取目标Element的位置
- 设置目标Element的位置。(left和top)dom.getSize ( el ) : object
- 获取目标元素的大小
dom.getScrollSize ( el ) : object
- 获取目标元素的大小,包括由于 overflow 溢出而在屏幕上不可见的内容。
dom.getStyle ( el, key ) : string
- 获取目标元素计算后的样式值。
dom.getStyles ( el, key... ) : object
- 获取目标元素计算后的多个样式值。
dom.setStyle ( el, key, value ) : Element
- 给目标Element设置css样式。
dom.setStyles ( el, styles ) : Element
- 给目标Element设置多个css样式。
dom.isPositioned ( el ) : boolean
- 判断目标元素是否是一个定位元素。
dom.show ( el ) : Element
- 设置目标元素可见。
dom.hide ( el ) : Element
- 设置目标元素隐藏。
dom.getParentSrcollNode ( el ) : Element
- 获取包含目标元素的可滚动元素。
dom.getParent ( el, [match] ) : Element
- 获取目标元素符合匹配条件的最近上级元素。
dom.isDisplayNone ( el) : Element
- 判断当前元素及其父元素的display是否为none。
cloneDate ( date ) : Date
- 克隆日期
lastDayOfMonth ( year, month ) : Date
- 传入年和月(1~12),获取对应月份的最后一天。
lastTimeOfMonth ( year, month ) : Date
- 传入年和月(1~12),获取对应月份的最后一天,时间为最后一秒。
lastTimeOfDate ( date, isClone ) : Date
- 传入日期,获取对应日期的最后一刻。
clearTime ( date, isClone ) : Date
- 传入日期,清除时间。
increment ( date, interval , times ) : Date
- 传入日期,增加times个单位。interval可以为 year, month, week, day, hour, minute, second, and ms
formatDate ( date, format ) : String
- 将日期时间格式化为指定的格式,并返回格式化后的字符串。
{Date} date 需格式化日期
{String} format 格式化字符串,如 YYYY-MM-DD HH:mm:ss
Y - 年份
M - 月份
D - 日期
H - 小时(24 小时制)
h - 小时(12 小时制)
m - 分
s - 秒
q - 季度
S - 毫秒
a - 上午/下午
A - AM/PM
const date = new Date();
formatDate(date, 'YYYY-MM-DD HH:mm:ss'); // 2023-02-16 08:25:05
formatDate(date, 'YYYY年MM月DD日 HH:mm:ss'); // 2023年02月16日 08:25:05
formatDate(date, 'YYYY-MM-DD HH:mm:ss S'); // 2023-02-16 08:25:05 950
formatDate(date, 'YYYY-MM-DD HH:mm:ss A'); // 2023-02-16 08:25:05 上午
- 传入数组[日期1开始时间,日期1结束时间],[日期2开始时间,日期2结束时间],是否忽略边界。返回日期1和日期2是否相交。const date1Start = new Date('2000-01-01 00:00:00');
const date1End = new Date('2000-01-01 23:59:59');
const date2Start = new Date('2000-01-01 23:00:00');
const date2End = new Date('2000-01-02 23:59:59');
const flag = isIntersect([date1Start, date1End], [date2Start, date2End]); //返回true
FAQs
- **browser** `- Object 浏览器检测信息`
We found that @o2oa/util demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.