Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
茶陵後
Translate Mds
提交
354003cc
T
Translate Mds
项目概览
茶陵後
/
Translate Mds
9 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Translate Mds
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
354003cc
编写于
11月 30, 2018
作者:
a865501259
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix: lengthEqual
上级
40fd3513
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
73 addition
and
80 deletion
+73
-80
README.md
README.md
+0
-2
src/Fix/lengthEqual.js
src/Fix/lengthEqual.js
+69
-74
src/setObjectKey.js
src/setObjectKey.js
+2
-2
test/Fix/lengthEqual.test.js
test/Fix/lengthEqual.test.js
+2
-2
未找到文件。
README.md
浏览文件 @
354003cc
...
...
@@ -10,14 +10,12 @@ like
---
[
![Build Status
](
https://travis-ci.org/chinanf-boy/translate-mds.svg?branch=master
)
](https://travis-ci.org/chinanf-boy/translate-mds)
[
![codecov
](
https://codecov.io/gh/chinanf-boy/translate-mds/branch/master/graph/badge.svg
)
](https://codecov.io/gh/chinanf-boy/translate-mds)
[
![GitHub license
](
https://img.shields.io/github/license/chinanf-boy/translate-mds.svg
)
](https://github.com/chinanf-boy/translate-mds/blob/master/License)
![
npm
](
https://img.shields.io/npm/v/translate-mds.svg
)
![
GitHub release
](
https://img.shields.io/github/tag/chinanf-boy/translate-mds.svg
)
## 生活
[
help me live , live need money 💰
](
https://github.com/chinanf-boy/live-need-money
)
...
...
src/Fix/lengthEqual.js
浏览文件 @
354003cc
const
{
getOptions
}
=
require
(
'
../config/work-options.js
'
)
let
configs
=
getOptions
()
const
{
matchs
,
skips
}
=
configs
const
{
tc
}
=
require
(
'
../util/util.js
'
)
const
{
getOptions
}
=
require
(
'
../config/work-options.js
'
);
let
configs
=
getOptions
();
const
{
matchs
,
skips
}
=
configs
;
const
{
tc
}
=
require
(
'
../util/util.js
'
);
let
Equal
;
function
translateLengthEquals
(
source
,
tranTxt
){
let
skipArr
=
[
"
...
"
,
"
etc.
"
,
"
i.e.
"
,
"
e.g.
"
].
concat
(
skips
)
let
matchArr
=
[
"
.
"
,
"
!
"
,
"
;
"
,
"
!
"
,
"
?
"
,
"
。
"
].
concat
(
matchs
)
let
trim
=
[
"
'
"
,
'
"
'
]
Equal
=
source
.
length
let
newSource
=
[].
concat
(
source
)
for
(
let
i
in
source
){
// typeof i == string
// if(Equal == tranTxt.length) return
source
[
i
]
=
source
[
i
].
trim
()
let
idxStr
=
source
[
i
]
let
howMany
=
0
// let s = source[i]
matchArr
.
forEach
(
function
(
val
){
if
(
trim
.
some
(
x
=>
(
idxStr
.
startsWith
(
x
)
&&
idxStr
.
endsWith
(
x
)))){
// ' ** ' /" ** "
return
val
function
translateLengthEquals
(
source
,
tranTxt
)
{
let
skipArr
=
[
'
...
'
,
'
etc.
'
,
'
i.e.
'
,
'
e.g.
'
].
concat
(
skips
);
let
matchArr
=
[
'
.
'
,
'
!
'
,
'
;
'
,
'
!
'
,
'
?
'
,
'
。
'
].
concat
(
matchs
);
let
trim
=
[
"
'
"
,
'
"
'
];
Equal
=
source
.
length
;
let
newSource
=
[].
concat
(
source
);
for
(
let
i
in
source
)
{
// typeof i == string
// if(Equal == tranTxt.length) return
source
[
i
]
=
source
[
i
].
trim
();
let
idxStr
=
source
[
i
];
if
(
trim
.
some
(
x
=>
idxStr
.
startsWith
(
x
)
&&
idxStr
.
endsWith
(
x
)))
{
// ' ** ' /" ** "
}
else
{
let
howMany
=
0
;
// let s = source[i]
let
thisMatch
=
matchArr
.
filter
(
m
=>
idxStr
.
includes
(
m
));
// just filter match string
thisMatch
.
forEach
(
function
(
val
)
{
while
(
idxStr
.
includes
(
val
))
{
let
skipIndexs
=
[];
skipArr
.
forEach
(
function
(
skip
)
{
if
(
idxStr
.
includes
(
skip
))
{
skipIndexs
.
push
(
skip
);
}
});
if
(
skipIndexs
.
length
)
{
skipIndexs
.
forEach
(
skip
=>
{
idxStr
=
idxStr
.
replace
(
skip
,
tc
.
bgMagenta
(
`👌 `
));
// over val
});
continue
;
}
else
{
if
(
idxStr
.
indexOf
(
val
)
+
val
.
length
==
idxStr
.
length
)
{
break
;
}
while
(
val
&&
idxStr
.
includes
(
val
)
){
let
skipIndexs
=
[]
skipArr
.
forEach
(
function
(
skip
){
if
(
idxStr
.
includes
(
skip
)){
skipIndexs
.
push
(
skip
)
}
})
if
(
skipIndexs
.
length
){
skipIndexs
.
forEach
(
skip
=>
{
idxStr
=
idxStr
.
replace
(
skip
,
tc
.
bgMagenta
(
`👌 `
))
// over val
})
continue
;
}
else
{
idxStr
=
idxStr
.
replace
(
val
,
tc
.
bgRed
(
`🥄 `
))
// over val
howMany
++
// how many ". "/ etc
}
}
})
!!
(
howMany
)
&&
mergeAndCut
(
tranTxt
,
+
i
,
howMany
)
// pay attion two + , string/number
newSource
[
i
]
=
idxStr
idxStr
=
idxStr
.
replace
(
val
,
tc
.
bgRed
(
`🥄 `
));
// over val
howMany
++
;
// how many ". "/ etc
}
}
});
!!
howMany
&&
mergeAndCut
(
tranTxt
,
+
i
,
howMany
);
// pay attion two + , string/number
newSource
[
i
]
=
idxStr
;
}
}
return
newSource
return
newSource
;
}
function
mergeAndCut
(
Arr
,
index
,
howMany
,
TestLen
){
let
E
=
Equal
||
TestLen
let
num
=
0
;
// Merge howMany items to Index item
for
(
let
i
=
index
;
i
<
index
+
howMany
;
i
++
){
if
(
1
||
Arr
.
length
-
num
!==
E
){
Arr
[
i
+
1
]
&&
(
Arr
[
index
]
=
Arr
[
index
]
+
Arr
[
i
+
1
])
num
++
}
// else{
// break;
// }
}
// splice Items : From the Index + 1 to ` i `
Arr
.
splice
(
index
+
1
,
num
)
function
mergeAndCut
(
Arr
,
index
,
howMany
,
TestLen
)
{
let
E
=
Equal
||
TestLen
;
let
num
=
0
;
// Merge howMany items to Index item
for
(
let
i
=
index
;
i
<
index
+
howMany
;
i
++
)
{
if
(
1
||
Arr
.
length
-
num
!==
E
)
{
Arr
[
i
+
1
]
&&
(
Arr
[
index
]
=
Arr
[
index
]
+
Arr
[
i
+
1
]);
num
++
;
}
// else{
// break;
// }
}
// splice Items : From the Index + 1 to ` i `
Arr
.
splice
(
index
+
1
,
num
);
}
module
.
exports
=
{
translateLengthEquals
,
mergeAndCut
}
module
.
exports
=
{
translateLengthEquals
,
mergeAndCut
};
src/setObjectKey.js
浏览文件 @
354003cc
...
...
@@ -63,7 +63,7 @@ async function translateValue(value, api) {
if
(
value
.
length
==
result
.
result
.
length
)
{
return
result
.
result
}
}
if
(
value
.
length
>
result
.
result
.
length
)
{
return
translateValue
(
value
.
slice
(
result
.
result
.
length
),
api
).
then
(
youdao
=>
{
...
...
@@ -239,7 +239,7 @@ async function setObjectKey(obj, opts) {
if
(
markChunkTran
.
length
!=
thisResult
.
length
)
{
// debug only unequal
debugMsg
(
2
,
this
ChunkTran
,
thisResult
)
debugMsg
(
2
,
mark
ChunkTran
,
thisResult
)
}
...
...
test/Fix/lengthEqual.test.js
浏览文件 @
354003cc
...
...
@@ -53,7 +53,7 @@ test("translateLengthEquals with '. ' and '!' ", t =>{
test
(
`translateLengthEquals with '. ' and '。' `
,
t
=>
{
let
b
=
[
`asdf。. asdf. 。`
,
`asdf`
]
let
c
=
[
`asdf。`
,
`. `
,
`asdf. `
,
`。`
,
`asdf`
]
translateLengthEquals
(
b
,
c
)
t
.
deepEqual
(
c
,
[
`asdf。. asdf. 。asdf`
]
)
translateLengthEquals
(
b
,
c
)
t
.
deepEqual
(
c
,
b
)
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录