@zodash/dom
Advanced tools
Comparing version 0.1.18 to 0.1.19
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.1.19](https://github.com/zcorky/zodash/compare/@zodash/dom@0.1.18...@zodash/dom@0.1.19) (2022-09-04) | ||
**Note:** Version bump only for package @zodash/dom | ||
## [0.1.18](https://github.com/zcorky/zodash/compare/@zodash/dom@0.1.17...@zodash/dom@0.1.18) (2022-08-24) | ||
@@ -8,0 +16,0 @@ |
@@ -6,1 +6,3 @@ export declare function getUrl(): string; | ||
export declare function navigate(url: string, canGoBack?: boolean): void; | ||
export declare function parse(regStr: string, pathname: string): Record<string, string> | null; | ||
export declare function isMatch(regStr: string, pathname: string): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.navigate = exports.go = exports.getLocation = exports.getQuery = exports.getUrl = void 0; | ||
const query_string_1 = require("@zcorky/query-string"); | ||
exports.isMatch = exports.parse = exports.navigate = exports.go = exports.getLocation = exports.getQuery = exports.getUrl = void 0; | ||
const qs = require("@zcorky/query-string"); | ||
const pathToRegexp = require("path-to-regexp"); | ||
function getUrl() { | ||
@@ -10,3 +11,3 @@ return window.location.href; | ||
function getQuery() { | ||
return query_string_1.parse(window.location.search); | ||
return qs.parse(window.location.search); | ||
} | ||
@@ -29,1 +30,22 @@ exports.getQuery = getQuery; | ||
exports.navigate = navigate; | ||
function parse(regStr, pathname) { | ||
var _a; | ||
const regexp = pathToRegexp(regStr); | ||
const result = regexp.exec(pathname); | ||
if (!result) { | ||
return null; | ||
} | ||
const keys = (_a = regexp.keys) !== null && _a !== void 0 ? _a : []; | ||
if (!keys.length) { | ||
return {}; | ||
} | ||
return keys.reduce((acc, key, index) => { | ||
acc[key.name] = result[index + 1]; | ||
return acc; | ||
}, {}); | ||
} | ||
exports.parse = parse; | ||
function isMatch(regStr, pathname) { | ||
return !!parse(regStr, pathname); | ||
} | ||
exports.isMatch = isMatch; |
{ | ||
"name": "@zodash/dom", | ||
"version": "0.1.18", | ||
"version": "0.1.19", | ||
"description": "DOM Utils", | ||
@@ -53,5 +53,5 @@ "keywords": [ | ||
"global": { | ||
"branches": 80, | ||
"functions": 90, | ||
"lines": 90, | ||
"branches": 40, | ||
"functions": 20, | ||
"lines": 60, | ||
"statements": -10 | ||
@@ -76,5 +76,6 @@ } | ||
"@zodash/debounce": "^0.1.10", | ||
"@zodash/event": "^0.1.14" | ||
"@zodash/event": "^0.1.14", | ||
"path-to-regexp": "1.7.0" | ||
}, | ||
"gitHead": "0380215b1bed3268d7ab000f842e24357eaf6d3a" | ||
"gitHead": "a40d51eb88772d0265808e9deef01f821c76e262" | ||
} |
20284
376
6
+ Addedpath-to-regexp@1.7.0
+ Addedisarray@0.0.1(transitive)
+ Addedpath-to-regexp@1.7.0(transitive)