url-transformers
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"scripts": { | ||
@@ -21,10 +21,8 @@ "compile": "rm -rf ./target/ && tsc", | ||
"dependencies": { | ||
"@types/lodash": "^4.14.111", | ||
"@types/node": "^10.5.2", | ||
"lodash": "^4.17.10" | ||
"@types/node": "^10.12.10" | ||
}, | ||
"devDependencies": { | ||
"prettier": "^1.14.2", | ||
"typescript": "^2.9.2" | ||
"prettier": "^1.15.3", | ||
"typescript": "^3.2.1" | ||
} | ||
} |
@@ -1,5 +0,19 @@ | ||
# url-transformers | ||
# `url-transformers` | ||
See the [tests] for example usage. | ||
A small helper library for manipulating URL strings in Node and in the browser. `url-transformers` provides several functions for common URL transformations, such as adding a search/query string to a URL or appending to the URL pathname. | ||
Currently `url-transformers` provides the following helpers: | ||
- `addQueryToUrl` | ||
- `replacePathInUrl` | ||
- `replacePathnameInUrl` | ||
- `appendPathnameToUrl` | ||
- `replaceHashInUrl` | ||
There are many more possibilities, so we would love for you to help us grow this collection! | ||
Currently we don't have documentation, however the code is strongly typed using TypeScript, and it should be easy to scan the function signatures. See the [tests] for example usage. | ||
## Installation | ||
```sh | ||
@@ -10,6 +24,12 @@ yarn add url-transformers | ||
## Development | ||
```sh | ||
yarn | ||
npm run test | ||
npm run prepublishOnly && npm version patch && npm publish && git push && git push --tags | ||
``` | ||
[tests]: ./src/tests.ts |
@@ -13,2 +13,7 @@ /// <reference types="node" /> | ||
}) => string; | ||
export declare const replacePathnameInUrl: (b: { | ||
url: string; | ||
}) => (a: { | ||
newPathname: string; | ||
}) => string; | ||
export declare const appendPathnameToUrl: (b: { | ||
@@ -15,0 +20,0 @@ url: string; |
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
@@ -14,3 +17,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
var other_1 = require("./helpers/other"); | ||
var pipe = require("lodash/flow"); | ||
var pipe_1 = require("./helpers/pipe"); | ||
var getPathnameFromParts = function (parts) { return "/" + parts.map(encodeURIComponent).join('/'); }; | ||
@@ -29,3 +32,3 @@ var getPartsFromPathname = function (pathname) { | ||
var mapUrl = function (fn) { | ||
return pipe(function (_a) { | ||
return pipe_1.pipe(function (_a) { | ||
var url = _a.url; | ||
@@ -36,3 +39,3 @@ return urlHelpers.parse(url); | ||
var mapUrlWithParsedQuery = function (fn) { | ||
return pipe(function (_a) { | ||
return pipe_1.pipe(function (_a) { | ||
var url = _a.url; | ||
@@ -59,4 +62,4 @@ return parseUrlWithQueryString(url); | ||
}; | ||
exports.addQueryToUrl = other_1.flipCurried(pipe(addQueryToParsedUrl, mapUrlWithParsedQuery)); | ||
var parsePath = pipe(urlHelpers.parse, function (_a) { | ||
exports.addQueryToUrl = other_1.flipCurried(pipe_1.pipe(addQueryToParsedUrl, mapUrlWithParsedQuery)); | ||
var parsePath = pipe_1.pipe(urlHelpers.parse, function (_a) { | ||
var search = _a.search, pathname = _a.pathname; | ||
@@ -69,6 +72,14 @@ return ({ search: search, pathname: pathname }); | ||
var parsedUrl = _a.parsedUrl; | ||
return pipe(function () { return parsePath(newPath); }, function (newPathParsed) { return (__assign({}, parsedUrl, newPathParsed)); })(); | ||
return pipe_1.pipe(function () { return parsePath(newPath); }, function (newPathParsed) { return (__assign({}, parsedUrl, newPathParsed)); })({}); | ||
}; | ||
}; | ||
exports.replacePathInUrl = other_1.flipCurried(pipe(replacePathInParsedUrl, mapUrl)); | ||
exports.replacePathInUrl = other_1.flipCurried(pipe_1.pipe(replacePathInParsedUrl, mapUrl)); | ||
var replacePathnameInParsedUrl = function (_a) { | ||
var newPathname = _a.newPathname; | ||
return function (_a) { | ||
var parsedUrl = _a.parsedUrl; | ||
return (__assign({}, parsedUrl, { pathname: newPathname })); | ||
}; | ||
}; | ||
exports.replacePathnameInUrl = other_1.flipCurried(pipe_1.pipe(replacePathnameInParsedUrl, mapUrl)); | ||
var appendPathnameToParsedUrl = function (_a) { | ||
@@ -78,3 +89,3 @@ var pathnameToAppend = _a.pathnameToAppend; | ||
var parsedUrl = _a.parsedUrl; | ||
var pathnameParts = pipe(function () { return maybe_1.mapMaybe(parsedUrl.pathname, getPartsFromPathname); }, function (maybe) { return maybe_1.getOrElseMaybe(maybe, function () { return []; }); })(); | ||
var pathnameParts = pipe_1.pipe(function () { return maybe_1.mapMaybe(parsedUrl.pathname, getPartsFromPathname); }, function (maybe) { return maybe_1.getOrElseMaybe(maybe, function () { return []; }); })({}); | ||
var pathnamePartsToAppend = getPartsFromPathname(pathnameToAppend); | ||
@@ -86,3 +97,3 @@ var newPathnameParts = pathnameParts.concat(pathnamePartsToAppend); | ||
}; | ||
exports.appendPathnameToUrl = other_1.flipCurried(pipe(appendPathnameToParsedUrl, mapUrl)); | ||
exports.appendPathnameToUrl = other_1.flipCurried(pipe_1.pipe(appendPathnameToParsedUrl, mapUrl)); | ||
var replaceHashInParsedUrl = function (_a) { | ||
@@ -95,3 +106,3 @@ var newHash = _a.newHash; | ||
}; | ||
exports.replaceHashInUrl = other_1.flipCurried(pipe(replaceHashInParsedUrl, mapUrl)); | ||
exports.replaceHashInUrl = other_1.flipCurried(pipe_1.pipe(replaceHashInParsedUrl, mapUrl)); | ||
//# sourceMappingURL=index.js.map |
@@ -13,2 +13,4 @@ "use strict"; | ||
assert.strictEqual(index_1.replacePathInUrl({ url: 'https://foo.com/foo?example' })({ newPath: '/bar' }), 'https://foo.com/bar'); | ||
assert.strictEqual(index_1.replacePathnameInUrl({ url: 'https://foo.com/foo' })({ newPathname: '/bar' }), 'https://foo.com/bar'); | ||
assert.strictEqual(index_1.replacePathnameInUrl({ url: 'https://foo.com/foo?example' })({ newPathname: '/bar' }), 'https://foo.com/bar?example'); | ||
assert.strictEqual(index_1.appendPathnameToUrl({ url: '/foo' })({ pathnameToAppend: '/bar' }), '/foo/bar'); | ||
@@ -15,0 +17,0 @@ assert.strictEqual(index_1.appendPathnameToUrl({ url: '/foo?example' })({ pathnameToAppend: '/bar' }), '/foo/bar?example'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
17213
1
17
196
35
- Removed@types/lodash@^4.14.111
- Removedlodash@^4.17.10
- Removed@types/lodash@4.17.13(transitive)
- Removedlodash@4.17.21(transitive)
Updated@types/node@^10.12.10