0.0.9 • Published 8 years ago

isomorphic-urlencode v0.0.9

Weekly downloads
4
License
ISC
Repository
-
Last release
8 years ago

Isomorphic Urlencode

Main motivation for building this Repo is that:

  • Enable GBK Encoding by Pure Client-Side JavaScript
  • Guarantee isomorphic and seamless migration between test in node and production in browser for fetch

Usage

The Node implementation is based on node-urlencode,so api style is as same as node-urlencode. But the encode in browser is async,so i use Promise as return;

use npm to install:

npm install --save isomorphic-urlencode

If used in Browser, add this to head of your HTML

if (parent._urlEncode_iframe_callback) {

    parent._urlEncode_iframe_callback(location.search.split('=')[1]);

    //直接关闭当前子窗口
    window.close();
}
var urlencode = require("isomorphic-urlencode");
urlencode("王下邀月熊").then(function (data) {
  console.log(data);

  //测试解码
  urlencode.decode(data).then(function (data) {
    console.log(data);
  })
});

urlencode("王下邀月熊", "gbk").then(function (data) {
  console.log(data);

  //测试解码
  urlencode.decode(data, "gbk").then(function (data) {
    console.log(data);
  })
});

The Browser Version is built on iframe and form, you can refer to this blog for more details;

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago