Commit f3708faf authored by rockyl's avatar rockyl

添加注释

parent 962fd5d9
......@@ -7,6 +7,11 @@ export const linkedFlag = '$_linked_$';
export const nodeScheme = 'node://';
export const linkScheme = 'link://';
/**
* 数组查找
* @param arr
* @param predicate
*/
export function arrayFind(arr, predicate) {
if (!arr) {
return;
......@@ -20,6 +25,10 @@ export function arrayFind(arr, predicate) {
}
}
/**
* 对象深度克隆
* @param obj
*/
export function objClone(obj) {
return JSON.parse(JSON.stringify(obj));
}
......@@ -169,6 +178,11 @@ export function importUMDCode(code) {
return exports;
}
/**
* 字符串两端删除字符
* @param str
* @param char
*/
export function trimChar(str: string, char: string) {
if (!str || !char) {
return;
......@@ -190,6 +204,10 @@ export function trimChar(str: string, char: string) {
return str;
}
/**
* 路径拼接
* @param segments
*/
export function joinPath(...segments: string[]) {
let result = [];
for (let segment of segments) {
......@@ -198,6 +216,11 @@ export function joinPath(...segments: string[]) {
return result.join('/');
}
/**
* 属性查找
* @param name
* @param contexts
*/
export function findVariable(name: string, ...contexts) {
let result;
for (let context of contexts) {
......@@ -213,6 +236,10 @@ export function findVariable(name: string, ...contexts) {
let el;
/**
* html文本转纯文本
* @param htmlText
*/
export function htmlToPureText(htmlText) {
if (!el) {
el = document.createElement('div');
......@@ -227,6 +254,10 @@ export function htmlToPureText(htmlText) {
const zhReg = /[\u4e00-\u9fa5]/;
/**
* 字符串长度,中文占2个字母宽度
* @param str
*/
export function strLen(str) {
let len = 0;
for (let char of str) {
......@@ -235,6 +266,12 @@ export function strLen(str) {
return len;
}
/**
* 字符串简短化
* @param str
* @param limit
* @param replace
*/
export function strShort(str, limit, replace = '…') {
let result = '';
if (strLen(str) > limit) {
......@@ -255,11 +292,21 @@ export function strShort(str, limit, replace = '…') {
return result;
}
/**
* 脚本实例化
* @param node
* @param ScriptConfig
*/
export function instantiateScript(node, ScriptConfig) {
const {script: scriptName, props, disabled} = ScriptConfig;
const script = node.scripts.add(scriptName, props, disabled);
}
/**
* 属性注入
* @param target
* @param source
*/
export function injectProperties(target, source) {
for (let key in source) {
propertyParse(key, target, source);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment