-
-
Notifications
You must be signed in to change notification settings - Fork 37
formatter.js
Provides easy used methods using in this project.
Kind: global class
-
Formatter
-
.castCsvBill(buffer) ⇒
object
-
.castCsvLine(row, [keys], [skipFirstChar], [separator]) ⇒
object
-
.nonce([size]) ⇒
string
-
.timestamp() ⇒
number
-
.authorization(mchid, nonce, signature, timestamp, serial) ⇒
string
-
.request(method, uri, timestamp, nonce, body) ⇒
string
-
.response(timestamp, nonce, body) ⇒
string
-
.joinedByLineFeed(...pieces) ⇒
string
-
.ksort(thing) ⇒
object
-
.queryStringLike(thing) ⇒
string
-
.castCsvBill(buffer) ⇒
Cast the CSV
bill.
Kind: static method of Formatter
Returns: object
- - The casted source intputs as {rows, summary} Object
Param | Type | Description |
---|---|---|
buffer |
string | Buffer
|
CSV file content. |
Cast the CSV
line string by the keys named object.
Kind: static method of Formatter
Returns: object
- - The casted source line as Object
Param | Type | Default | Description |
---|---|---|---|
row | string |
CSV line. | |
[keys] | Array.<string> |
CSV headers. | |
[skipFirstChar] | boolean |
true |
Skip the first character of the CSV line, default is true. |
[separator] | string |
"',`'" |
Split separator, default is ',`' (two chars). |
Generate a Base62 random string aka nonce
, similar as crypto.randomBytes
.
Kind: static method of Formatter
Returns: string
- - Base62 random string.
Param | Type | Default | Description |
---|---|---|---|
[size] | number |
32 |
Nonce string length, default is 32 bytes. |
Retrieve the current Unix
timestamp.
Kind: static method of Formatter
Returns: number
- Epoch timestamp.
Formatting for the heading Authorization
value.
Kind: static method of Formatter
Returns: string
- - The APIv3 Authorization header
value
Param | Type | Description |
---|---|---|
mchid |
string | number
|
The merchant ID. |
nonce | string |
The Nonce string. |
signature | string |
The base64-encoded Rsa.sign ciphertext. |
timestamp |
string | number
|
The Unix timestamp. |
serial | string |
The serial number of the merchant public certification. |
Formatting this HTTP.request
for Rsa.sign
input.
Kind: static method of Formatter
Returns: string
- - The content for Rsa.sign
Param | Type | Description |
---|---|---|
method | string |
The HTTP verb, must be the uppercase sting. |
uri | string |
Combined string with URL.pathname and URL.search . |
timestamp |
string | number
|
The Unix timestamp, should be the one used in authorization . |
nonce | string |
The Nonce string, should be the one used in authorization . |
body | string |
The playload string, HTTP GET should be an empty string. |
Formatting this HTTP.response
for Rsa.verify
input.
Kind: static method of Formatter
Returns: string
- - The content for Rsa.verify
Param | Type | Description |
---|---|---|
timestamp |
string | number
|
The Unix timestamp, should be the one from response.headers[wechatpay-timestamp] . |
nonce | string |
The Nonce string, should be the one from response.headers[wechatpay-nonce] . |
body | string |
The response payload string, HTTP status(204 ) should be an empty string. |
Joined this inputs by for Line Feed
(LF) char.
Kind: static method of Formatter
Returns: string
- - The joined string.
Param | Type | Description |
---|---|---|
...pieces | Array.<string> |
The string(s) joined by line feed. |
Sorts an Object by key.
Kind: static method of Formatter
Returns: object
- - The sorted object.
Param | Type | Description |
---|---|---|
thing | object |
The input object. |
Like queryString
does but without the sign
and empty value
entities.
Kind: static method of Formatter
Returns: string
- - The sorted object.
Param | Type | Description |
---|---|---|
thing | object |
The input object. |