1.2.2 • Published 2 years ago

xtool.js v1.2.2

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

要跑UT请先安装Jest: npm i jest

xtool

Enchance file, number feature of node

Functions

xFile

File relative tools of xTool

Kind: global variable

xHtml

HTML relative tools of xTool

Kind: global variable

xNumber

Number relative tools of xTool

Kind: global variable

xUtil

Utility of xTool

Kind: global variable

prepareDir(dir)

Enchance file, number feature of node

Kind: global function

ParamTypeDescription
dirstringthe path want to prepared

Kind: global variable

readDir(root, setting) => array

Get file list from a root path with configure

Kind: global function
Returns: array - list of file with absolute/relative path

ParamTypeDescription
rootstringfile root path
settingobject | stringoptional, if only one find pattern, can be simplify as a string
setting.absolutebooleanreturn absolute path or path relative from root. default is false
setting.recursivebooleanrecursive to sub directory. default is false
setting.findstring | regexp | arrayprovide human pattern or human pattern list to define filename matcher. default is "*"
setting.ignorestring | regexp | arrayprovide human pattern or human pattern list to define which filename will be ignored. default is none

readFile(file, encoding) => string

Read file content

Kind: global function
Returns: string - if file not exist, will return empty string

ParamTypeDescription
filestringpath to file
encodingstringencoding

existFile(file) => boolean

Test file exist or not

Kind: global function

ParamTypeDescription
filestringpath to file

existDir(dir) => boolean

Test dir exist or not

Kind: global function

ParamTypeDescription
dirstringpath

saveFile(file, content, encoding)

Save content to file

Kind: global function

ParamTypeDescription
filestringpath to file
contentstring | array | objectfile content, array will be join with {crlf}, object will be str
encodingstringencoding

removeFile(file) => boolean

Alias of fs.unlinkSync

Kind: global function
Returns: boolean - if file not exist, return false

ParamTypeDescription
filestringpath to file

scanFile(file, callback)

scan file by line, and do callback to content of each line

Kind: global function

ParamTypeDescription
filestringfilename
callbackfunctioncall back func(lineContent, lineNumber)

scanListFile(list, callback)

scan all file in list by line, and do callback to content of each line

Kind: global function

ParamTypeDescription
listarraythe file list from readDir()
callbackfunctioncall back func(lineContent, lineNumber, fileName)

replaceFile(file, pattern|callback, replacement)

replace file content with pattern & replacement

Kind: global function

ParamTypeDescription
filestringpath to file
patterncallbackstring | regexp | function-
replacementstringif pattern provided, replacement must provide, if pattern is regexp, replacement can use the captured value by $1, $2, etc.

decodeHtml(htmlContent) => string

transfer &#DDDD; & &#xHHHH; it was. make sure the html page under utf-8;

Kind: global function

ParamTypeDescription
htmlContentstringincluded

tolerant(num) => string

修正中文数字常见的错误,并转小写

Kind: global function
Returns: string - 不校验数字拼写是否正确,只转换常错的拼写

ParamTypeDescription
numstring中文数字

numberChnToBig(num) => string

中文数字小写转大写,“万”,“亿”是不区分大小写的

Kind: global function
Returns: string - 不校验数字拼写是否正确,只转换大写

ParamTypeDescription
numstring中文数字

numberChnToSmall(num) => string

中文数字小写转大写,“万”,“亿”是不区分大小写的

Kind: global function
Returns: string - 不校验数字拼写是否正确,只转换大写

ParamTypeDescription
numstring中文数字

numberAri2Chn(num) => string

阿拉伯数字转中文数字

Kind: global function
Returns: string - 返回中文数字

ParamTypeDescription
numnumber阿拉伯数字,大于零,小于一亿亿。不要使用巨大数字,受V8引擎精度限制,10^16左右就会精度失真。Math.pow(10,16) - 1 === Math.pow(10,16) 为 true

numberChn2Ari(num) => number

中文数字转阿拉伯数字

Kind: global function
Returns: number - 返回阿拉伯数字, 返回-1表示中文数字非法

ParamTypeDescription
numstring中文数字,大于零,小于一亿亿。不要使用巨大数字。接近或大于一亿亿的时候,V8引擎下的整数会出现精度问题。

isLegalChnNum(num) => string

检查中文数字合法性,能通过基本容错也为合法

Kind: global function
Returns: string - true表示合法中文数字

ParamTypeDescription
numstring中文数字,大于零,小于一亿亿

numberAri2Roman(num) => string

阿拉伯数字转罗马数字

Kind: global function

ParamTypeDescription
numnumber范围0-3999

numberRoman2Ari(s) => number

罗马数字转阿拉伯数字

Kind: global function

ParamTypeDescription
sstring范围0-3999

typeof(arg) => string

return the truly type of arg

Kind: global function
Returns: string - type of arg

ParamTypeDescription
arg*any type arg

is(value, type) => boolean

compare the value type with expect type

Kind: global function

ParamTypeDescription
value*value will be test
typestringexpect type

flattenArray(arg) => array

recursive embeded array to a flat array, and will remove duplicated value

Kind: global function
Returns: array - return a one dimension array

ParamTypeDescription
argarray | *multi dimensions array, other type of arg will return a array warped arg

distinctArray(arg) => array

remove duplicated value of array

Kind: global function
Returns: array - return an array with every unquie value

ParamTypeDescription
argarray | *array to remopve duplicated value

getArgs() => object

get node command args

Kind: global function
Returns: object - - command line: "node xxx.js -a 111 -b=222 333 -d", will return { 0: "-a", "111", "-b=222", "333", "-d", 1: "-a", 2: "111", 3: "-b=222", 4: "333", "5": "-d", "-a": "111", "-b": "222", "-d": true }

range(start, end) => array

generate values array of specified range, number range should be 0 to 2^32

Kind: global function

ParamTypeDescription
startnumber | stringif "end" is not provided, the range is (0 or "0" or "a" or "A") to "start"
endnumber | string
1.2.2

2 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.6

5 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago