Skip to content

Commit

Permalink
feat: 支持url参数加解密功能
Browse files Browse the repository at this point in the history
  • Loading branch information
pearone committed Dec 17, 2023
1 parent df91cb6 commit 1d85893
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 41 deletions.
63 changes: 61 additions & 2 deletions packages/event/__tests__/url.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { encodeParamsURI, decodeParamsURI } from '../src/url';

import {
encodeParamsURI,
decodeParamsURI,
encodeHashURI,
decodeHashURI
} from '../src/url';
/** TEST encodeParamsURI、decodeParamsURI */
test('default url', () => {
const url = encodeParamsURI('https://wuba.xinghuo.58.com', {
header: 'aaa',
Expand Down Expand Up @@ -58,3 +63,57 @@ test('object params url', () => {
const params = decodeParamsURI(url);
console.log(params, url);
});

test('object params anchor url', () => {
const url =
encodeParamsURI('https://wuba.xinghuo.58.com?name=xxx', {
header: '请选择用户或用户组我是一个很长的中文字符中文',
user: {
name: 'bbb',
age: 18,
sex: 'male'
},
target: 'ccc'
}) + '#anchor=111';

const params = decodeParamsURI(url);
console.log(params, url);
});

/** TEST encodeHashURI、decodeHashURI */
test('default hash url', () => {
const url = encodeHashURI('https://wuba.xinghuo.58.com#hash=111', {
header: 'aaa',
user: 'bbb',
target: 'ccc'
});

const hash = decodeHashURI(url);
console.log(hash, url);
});

/** TEST prototype encodeParamsURI、decodeParamsURI */
test('default url prototype url', () => {
const url = new URL('https://wuba.xinghuo.58.com#hash=111');
const encode_url = url.encodeParamsURI({
header: 'aaa',
user: 'bbb',
target: 'ccc'
});

const params = new URL(encode_url).decodeParamsURI();
console.log(params, url);
});

/** TEST prototype encodeHashURI、decodeHashURI */
test('default url prototype url', () => {
const url = new URL('https://wuba.xinghuo.58.com#hash=111');
const encode_url = url.encodeHashURI({
header: 'aaa',
user: 'bbb',
target: 'ccc'
});

const params = new URL(encode_url).decodeHashURI();
console.log(params, url);
});
39 changes: 0 additions & 39 deletions packages/event/src/url.ts

This file was deleted.

0 comments on commit 1d85893

Please sign in to comment.