npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

columbus-magic-url

v1.2.3

Published

encode and decode columbus url

Downloads

14

Readme

columbus-magic-url

安装

  • 使用 npmyarn 安装
# npm 安装
npm i columbus-magic-url -S

# yarn 安装
yarn add columbus-magic-url
  • 使用script引入

script引入时,会注入全局变量columbusMagicUrl

API

encode

入参

属性 | 类型 | 说明 --- | ---| --- url | string | url地址 params | object | url需要携带的参数(会与原url携带的参数比较并增量更新)

返回值

返回编码后的url

示例

import { encode } from 'columbus-magic-url';

const url = encode('https://example.com?from=wx', {from: 'abc', info: {id: 1, name: 'test'}});
// https://example.com?from=abc&info=eyJpZCI6MSwibmFtZSI6InRlc3QifQ%253D%253D

encodeStringify

入参

属性 | 类型 | 说明 --- | ---| --- params | object | 需要编码的对象

返回值

返回编码后的字符串

示例

import { encodeStringify } from 'columbus-magic-url';

const url = encodeStringify({from: 'abc', info: {id: 1, name: 'test'}});
// eyJmcm9tIjoiYWJjIiwiaW5mbyI6eyJpZCI6MSwibmFtZSI6InRlc3QifX0%3D

decode

入参

属性 | 类型 | 说明 --- | ---| --- url | string | url地址

返回值

url中携带的参数

示例

import { decode } from 'columbus-magic-url';

const params = decode('https://example.com?from=abc&info=eyJpZCI6MSwibmFtZSI6InRlc3QifQ%253D%253D');
// {from: 'abc', info: {id: 1, name: 'test'}}

decodeParse

入参

属性 | 类型 | 说明 --- | ---| --- str | string | 字符串

返回值

object

示例

import { decodeParse } from 'columbus-magic-url';

const params = decodeParse('eyJmcm9tIjoiYWJjIiwiaW5mbyI6eyJpZCI6MSwibmFtZSI6InRlc3QifX0%3D');
// {from: 'abc', info: {id: 1, name: 'test'}}

decodeWithReturnOrignUrl

入参

属性 | 类型 | 说明 --- | ---| --- url | string | url地址

返回值

属性 | 类型 | 说明 --- | ---| --- originUrl | string | 原始url地址 params | object | url中携带的参数

示例

import { decodeWithReturnOrignUrl } from 'columbus-magic-url';

const params = decodeWithReturnOrignUrl('https://example.com?from=abc&info=eyJpZCI6MSwibmFtZSI6InRlc3QifQ%253D%253D');
// {originUrl: 'https://example.com', params: {from: 'abc', info: {id: 1, name: 'test'}}}

encodeColumbusConnect 与 decodeColumbusConnect

仅对url携带的connect生效,用法同encodedecode

示例

import { encodeColumbusConnect, decodeColumbusConnect } from 'columbus-magic-url';

const url = encodeColumbusConnect('https://example.com?from=wx', { info: {id: 1, name: 'test'}, source: 'shop' });
// https://example.com?from=wx&connect=eyJpbmZvIjp7ImlkIjoxLCJuYW1lIjoidGVzdCJ9LCJzb3VyY2UiOiJzaG9wIn0%253D

const params = decodeColumbusConnect('https://example.com?from=wx&connect=eyJpbmZvIjp7ImlkIjoxLCJuYW1lIjoidGVzdCJ9LCJzb3VyY2UiOiJzaG9wIn0%253D');
// { info: {id: 1, name: 'test'}, source: 'shop' }