Commit f3708faf authored by rockyl's avatar rockyl

添加注释

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