@8ms/helpers 1.3.11 → 1.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/util/getClean.d.ts +11 -0
- package/util/getClean.js +28 -0
- package/util/getWithoutHash.d.ts +8 -0
- package/util/getWithoutHash.js +17 -0
- package/util/getWithoutParameter.d.ts +8 -0
- package/util/getWithoutParameter.js +17 -0
package/package.json
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type GetClean = {
|
|
2
|
+
hash?: boolean;
|
|
3
|
+
input: string;
|
|
4
|
+
lowercase?: boolean;
|
|
5
|
+
parameter?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Return a clean URL with a few options.
|
|
9
|
+
*/
|
|
10
|
+
declare const getClean: ({ hash, input, lowercase, parameter }: GetClean) => string;
|
|
11
|
+
export default getClean;
|
package/util/getClean.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getWithoutParameter_1 = __importDefault(require("./getWithoutParameter"));
|
|
7
|
+
const getWithoutHash_1 = __importDefault(require("./getWithoutHash"));
|
|
8
|
+
/**
|
|
9
|
+
* Return a clean URL with a few options.
|
|
10
|
+
*/
|
|
11
|
+
const getClean = ({ hash, input, lowercase, parameter }) => {
|
|
12
|
+
let response = input.trim();
|
|
13
|
+
if (parameter) {
|
|
14
|
+
response = (0, getWithoutParameter_1.default)({
|
|
15
|
+
input: response,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (hash) {
|
|
19
|
+
response = (0, getWithoutHash_1.default)({
|
|
20
|
+
input: response,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (lowercase) {
|
|
24
|
+
response = response.toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
return response;
|
|
27
|
+
};
|
|
28
|
+
exports.default = getClean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Get a URL without the parameter query.
|
|
5
|
+
*/
|
|
6
|
+
const getWithoutHash = ({ input }) => {
|
|
7
|
+
let response = input;
|
|
8
|
+
// Contains parameter query
|
|
9
|
+
if (-1 !== response.indexOf('#')) {
|
|
10
|
+
const split = response.split('#');
|
|
11
|
+
if (split.length > 1) {
|
|
12
|
+
response = split[0];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return response;
|
|
16
|
+
};
|
|
17
|
+
exports.default = getWithoutHash;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Get a URL without the parameter query.
|
|
5
|
+
*/
|
|
6
|
+
const getWithoutParameter = ({ input }) => {
|
|
7
|
+
let response = input;
|
|
8
|
+
// Contains parameter query
|
|
9
|
+
if (-1 !== response.indexOf('?')) {
|
|
10
|
+
const split = response.split('?');
|
|
11
|
+
if (split.length > 1) {
|
|
12
|
+
response = split[0];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return response;
|
|
16
|
+
};
|
|
17
|
+
exports.default = getWithoutParameter;
|