Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zeroing-engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
zeroing-engine
Commits
f3708faf
Commit
f3708faf
authored
Feb 29, 2020
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加注释
parent
962fd5d9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
utils.ts
src/zeroing/utils/utils.ts
+47
-0
No files found.
src/zeroing/utils/utils.ts
View file @
f3708faf
...
...
@@ -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
=
/
[\u
4e00-
\u
9fa5
]
/
;
/**
* 字符串长度,中文占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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment