@xapp/arachne-utils 1.8.2 → 1.8.3
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/lib/cleanForCrawl.d.ts +12 -0
- package/lib/cleanForCrawl.js +38 -0
- package/lib/cleanForCrawl.js.map +1 -0
- package/lib/hashWebsite.d.ts +8 -0
- package/lib/hashWebsite.js +44 -0
- package/lib/hashWebsite.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/isValidURL.d.ts +9 -0
- package/lib/isValidURL.js +22 -0
- package/lib/isValidURL.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
+
/**
|
|
3
|
+
* Prepare a URL for crawling.
|
|
4
|
+
*
|
|
5
|
+
* * Ensures there is no trailing slash
|
|
6
|
+
* * Ensures there is no hash
|
|
7
|
+
* * Ensures there is a scheme, defaults to https://
|
|
8
|
+
*
|
|
9
|
+
* @param url
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const cleanForCrawl: (url: string) => string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.cleanForCrawl = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Prepare a URL for crawling.
|
|
7
|
+
*
|
|
8
|
+
* * Ensures there is no trailing slash
|
|
9
|
+
* * Ensures there is no hash
|
|
10
|
+
* * Ensures there is a scheme, defaults to https://
|
|
11
|
+
*
|
|
12
|
+
* @param url
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
const cleanForCrawl = (url) => {
|
|
16
|
+
// First make sure they have a scheme
|
|
17
|
+
if (!url.startsWith("http")) {
|
|
18
|
+
// make sure it doesn't have // in the beginning
|
|
19
|
+
if (url.startsWith("//")) {
|
|
20
|
+
url = `https:${url}`;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
url = `https://${url}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// Remove trailing slash
|
|
27
|
+
if (url.endsWith("/")) {
|
|
28
|
+
url = url.slice(0, -1);
|
|
29
|
+
}
|
|
30
|
+
// Remove hash
|
|
31
|
+
const hashIndex = url.indexOf("#");
|
|
32
|
+
if (hashIndex > -1) {
|
|
33
|
+
url = url.slice(0, hashIndex);
|
|
34
|
+
}
|
|
35
|
+
return url;
|
|
36
|
+
};
|
|
37
|
+
exports.cleanForCrawl = cleanForCrawl;
|
|
38
|
+
//# sourceMappingURL=cleanForCrawl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanForCrawl.js","sourceRoot":"","sources":["../src/cleanForCrawl.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;AAElC;;;;;;;;;GASG;AACI,MAAM,aAAa,GAAG,CAAC,GAAW,EAAU,EAAE;IACjD,qCAAqC;IACrC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,gDAAgD;QAChD,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,GAAG,GAAG,SAAS,GAAG,EAAE,CAAC;QACzB,CAAC;aAAM,CAAC;YACJ,GAAG,GAAG,WAAW,GAAG,EAAE,CAAC;QAC3B,CAAC;IACL,CAAC;IAED,wBAAwB;IACxB,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACpB,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,cAAc;IACd,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,SAAS,GAAG,CAAC,CAAC,EAAE,CAAC;QACjB,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC,CAAA;AAvBY,QAAA,aAAa,iBAuBzB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.hashWebsite = hashWebsite;
|
|
27
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
28
|
+
const normalizeURL_1 = require("./normalizeURL");
|
|
29
|
+
const crypto = __importStar(require("crypto"));
|
|
30
|
+
/**
|
|
31
|
+
* Returns a hash for a website
|
|
32
|
+
*
|
|
33
|
+
* @param url
|
|
34
|
+
* @throws {Error} if the URL is invalid
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
function hashWebsite(url) {
|
|
38
|
+
const normalizedUrl = (0, normalizeURL_1.normalizeURL)(url, {
|
|
39
|
+
stripProtocol: true,
|
|
40
|
+
stripWWW: true,
|
|
41
|
+
});
|
|
42
|
+
return crypto.createHash('sha256').update(normalizedUrl).digest('hex');
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=hashWebsite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashWebsite.js","sourceRoot":"","sources":["../src/hashWebsite.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAWA,kCAMC;AAjBD,kCAAkC;AAClC,iDAA8C;AAC9C,+CAAiC;AAEjC;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,GAAW;IACnC,MAAM,aAAa,GAAG,IAAA,2BAAY,EAAC,GAAG,EAAE;QACpC,aAAa,EAAE,IAAI;QACnB,QAAQ,EAAE,IAAI;KACjB,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/*! Copyright (c) 2020, XAPP AI */
|
|
2
2
|
export * from "./ArachneURLPattern";
|
|
3
|
+
export * from "./cleanForCrawl";
|
|
3
4
|
export * from "./constants";
|
|
4
5
|
export * from "./generateFollowThroughPattern";
|
|
5
6
|
export * from "./hallucinationDetector";
|
|
6
7
|
export * from "./hasExtension";
|
|
8
|
+
export * from "./hashWebsite";
|
|
9
|
+
export * from "./isValidURL";
|
|
7
10
|
export * from "./normalizeURL";
|
|
8
11
|
export * from "./promiseWithTimeout";
|
package/lib/index.js
CHANGED
|
@@ -16,10 +16,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
__exportStar(require("./ArachneURLPattern"), exports);
|
|
19
|
+
__exportStar(require("./cleanForCrawl"), exports);
|
|
19
20
|
__exportStar(require("./constants"), exports);
|
|
20
21
|
__exportStar(require("./generateFollowThroughPattern"), exports);
|
|
21
22
|
__exportStar(require("./hallucinationDetector"), exports);
|
|
22
23
|
__exportStar(require("./hasExtension"), exports);
|
|
24
|
+
__exportStar(require("./hashWebsite"), exports);
|
|
25
|
+
__exportStar(require("./isValidURL"), exports);
|
|
23
26
|
__exportStar(require("./normalizeURL"), exports);
|
|
24
27
|
__exportStar(require("./promiseWithTimeout"), exports);
|
|
25
28
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;;;;;AAElC,sDAAoC;AACpC,8CAA4B;AAC5B,iEAA+C;AAC/C,0DAAwC;AACxC,iDAA+B;AAC/B,iDAA+B;AAC/B,uDAAqC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;;;;;AAElC,sDAAoC;AACpC,kDAAgC;AAChC,8CAA4B;AAC5B,iEAA+C;AAC/C,0DAAwC;AACxC,iDAA+B;AAC/B,gDAA8B;AAC9B,+CAA6B;AAC7B,iDAA+B;AAC/B,uDAAqC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
+
/**
|
|
3
|
+
* Determines if the URL is a valid URL.
|
|
4
|
+
*
|
|
5
|
+
* It attempts to create a new URL object from the string and returns true if it is successful.
|
|
6
|
+
* @param url
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const isValidURL: (url: string) => boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isValidURL = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Determines if the URL is a valid URL.
|
|
7
|
+
*
|
|
8
|
+
* It attempts to create a new URL object from the string and returns true if it is successful.
|
|
9
|
+
* @param url
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
const isValidURL = (url) => {
|
|
13
|
+
try {
|
|
14
|
+
new URL(url);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.isValidURL = isValidURL;
|
|
22
|
+
//# sourceMappingURL=isValidURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidURL.js","sourceRoot":"","sources":["../src/isValidURL.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;AAElC;;;;;;GAMG;AACI,MAAM,UAAU,GAAG,CAAC,GAAW,EAAW,EAAE;IAC/C,IAAI,CAAC;QACD,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC,CAAA;AAPY,QAAA,UAAU,cAOtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xapp/arachne-utils",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.3",
|
|
4
4
|
"types": "lib/index",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"files": [
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"clean": "rm -rf ./lib/*",
|
|
39
39
|
"test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "f506e88fbc093e8db03beaafadc4057f3647aece"
|
|
42
42
|
}
|