Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commitff2773c

Browse files
committed
refactor(utils): use stringz in cutFrom
1 parent0137b05 commitff2773c

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

‎package-docker.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"sentry-testkit":"^2.1.0",
9090
"shortid":"^2.2.8",
9191
"store":"^2.0.12",
92+
"stringz":"^2.0.0",
9293
"styled-components":"4.1.3",
9394
"timeago-react":"2.0.0",
9495
"uuid":"3.3.2"

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"sentry-testkit":"^2.1.0",
121121
"shortid":"^2.2.8",
122122
"store":"^2.0.12",
123+
"stringz":"^2.0.0",
123124
"styled-components":"4.3.2",
124125
"timeago-react":"2.0.0",
125126
"uuid":"^3.3.2"

‎utils/functions.js‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
importRfrom'ramda'
22
importPubSubfrom'pubsub-js'
3+
import{limit,length}from'stringz'
34

45
import{TAG_COLOR_ORDER}from'@config'
56
import{EVENT}from'@constant'
@@ -46,16 +47,7 @@ export const Rlog = (arg = 'Rlog: ') => R.tap(log(arg))
4647
*@param {*number} len 需要显示多少个汉字,两个英文字母相当于一个汉字
4748
*/
4849
exportconstcutFrom=(str,len=20)=>{
49-
constreg=/[\u4e00-\u9fa5]/g// 匹配中文
50-
constslice=str&&str.substring(0,len)
51-
// eslint-disable-next-line no-bitwise
52-
constchineseCharNum=~~(
53-
slice&&
54-
slice.match(reg)&&
55-
slice.match(reg).length
56-
)
57-
constrealen=slice&&slice.length*2-chineseCharNum
58-
returnstr&&str.substr(0,realen)+(realen<str.length ?'...' :'')
50+
returnlen>=length(str) ?str :`${limit(str,len,'')}...`
5951
}
6052

6153
// https://stackoverflow.com/questions/9461621/how-to-format-a-number-as-2-5k-if-a-thousand-or-more-otherwise-900-in-javascrip

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp