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

Appearance settings

zh-rocco/gbk-string

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gbk-string

GBK 编码/解码
示例:测试文本 -> %B2%E2%CA%D4%CE%C4%B1%BE

背景

使用 node 爬网站数据时,个别接口需要传入 GBK 编码后的字符串。

安装

$ npm install gbk-string -S

使用

此插件仅可运行在 Node 环境下,不支持浏览器环境。

const { encodeGBK, decodeGBK } = require('gbk-string');

encodeGBK('测试文本');
//=> "%B2%E2%CA%D4%CE%C4%B1%BE"

decodeGBK('%B2%E2%CA%D4%CE%C4%B1%BE');
//=> "测试文本"

或者:

const gbk = require('gbk-string');

gbk.encodeGBK('测试文本');
//=> "%B2%E2%CA%D4%CE%C4%B1%BE"

gbk.decodeGBK('%B2%E2%CA%D4%CE%C4%B1%BE');
//=> "测试文本"

API

encodeGBK(text)

text

Type: string

decodeGBK(str)

str

Type: string

依赖

License

MIT © zh-rocco

About

"中文 GBK 编码/解码, 示例:`测试` -> `%B2%E2%CA%D4`"

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.