JSPM

urls-js

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q20002F
  • License ISC

轻量级url参数处理,兼容浏览器和Node.js环境

Package Exports

  • urls-js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (urls-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

urls-js

轻量级url参数处理,兼容浏览器和Node.js环境

引用

var urls = require('urls');

<script src="urls.min.js"></script>

urls.parse() 解析

假设当前页面 url 为 http://baidu.com?a=1&b=2#c=3

urls.parse().query; // ==> { a: '1', b: '2' }
urls.parse().hash;  // ==> { c: '3' }
urls.parse('?a=3&b=4').query;                // ==> { a: '3', b: '4' }
urls.parse('page/index.html?a=3&b=4').query; // ==> { a: '3', b: '4' }
urls.parse('http://localhost/page/index.html?a=3&b=4').query; // ==> { a: '3', b: '4' }

urls.stringify() 拼接

var url = {
    path: 'page/index.html',
    query: {
        a: 1,
        b: 2
    },
    hash: {
        c: ''
    }
};

urls.stringify(url);  // ==> page/index.html?a=1&b=2#c

urls.merge() 合并

var url1 = 'page/index.html?a=1&b=2#c';
var url2 = '?b=3';

urls.merge(url1, url2);  // ==> page/index.html?a=1&b=3#c

urls.merge(url1, {
    query: {
        b: 3
    }
});  // ==> page/index.html?a=1&b=3#c