@xapp/arachne-utils 1.7.0 → 1.7.1

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.
@@ -0,0 +1,18 @@
1
+ /*! Copyright (c) 2024, XAPP AI */
2
+ /**
3
+ * Generates a URL pattern that will enable the crawler to
4
+ * follow through sub paths for the provided URL.
5
+ *
6
+ * For example:
7
+ *
8
+ * www.example.com/faqs
9
+ *
10
+ * will become
11
+ *
12
+ * https://[(www.)?]example.com/faqs[.+]
13
+ *
14
+ * NOTE: This will throw an error if the URL was not a proper URL.
15
+ *
16
+ * @param urlString
17
+ */
18
+ export declare function generateFollowThroughPattern(urlString: string): string;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2024, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.generateFollowThroughPattern = void 0;
5
+ /**
6
+ * Generates a URL pattern that will enable the crawler to
7
+ * follow through sub paths for the provided URL.
8
+ *
9
+ * For example:
10
+ *
11
+ * www.example.com/faqs
12
+ *
13
+ * will become
14
+ *
15
+ * https://[(www.)?]example.com/faqs[.+]
16
+ *
17
+ * NOTE: This will throw an error if the URL was not a proper URL.
18
+ *
19
+ * @param urlString
20
+ */
21
+ function generateFollowThroughPattern(urlString) {
22
+ if (!urlString) {
23
+ throw new Error(`Unabled to generate follow through patterns, URL not provided.`);
24
+ }
25
+ // Remove the trailing "/"
26
+ if (urlString.endsWith("/")) {
27
+ urlString = urlString.slice(0, -1);
28
+ }
29
+ let url;
30
+ try {
31
+ url = new URL(urlString);
32
+ }
33
+ catch (e) {
34
+ throw new Error(`Unabled to generate follow through patterns, URL ${urlString} is invalid`);
35
+ }
36
+ const protocol = url.protocol;
37
+ let host = url.host;
38
+ // Remove the www. if it is there
39
+ if (host.startsWith("www.")) {
40
+ host = host.replace("www.", "");
41
+ }
42
+ let path = url.pathname;
43
+ if (path.endsWith("/")) {
44
+ path = path.slice(0, -1);
45
+ }
46
+ let pattern;
47
+ const protocolPattern = protocol.startsWith("http") ? "http[(s)?]:" : protocol;
48
+ // Either starts with www or is just domain.tld
49
+ if (url.host.startsWith("www.") || url.host.split(".").length === 2) {
50
+ // make www optional
51
+ pattern = `${protocolPattern}//[(www.)?]${host}${path}[.+]`;
52
+ }
53
+ else {
54
+ pattern = `${protocolPattern}//${host}${path}[.+]`;
55
+ }
56
+ return pattern;
57
+ }
58
+ exports.generateFollowThroughPattern = generateFollowThroughPattern;
59
+ //# sourceMappingURL=generateFollowThroughPattern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateFollowThroughPattern.js","sourceRoot":"","sources":["../src/generateFollowThroughPattern.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;AAElC;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,4BAA4B,CAAC,SAAiB;IAE1D,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IACtF,CAAC;IACD,0BAA0B;IAC1B,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,GAAQ,CAAC;IAEb,IAAI,CAAC;QACD,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,oDAAoD,SAAS,aAAa,CAAC,CAAC;IAChG,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;IAC9B,IAAI,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IACpB,iCAAiC;IACjC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC;IACxB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACrB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IAED,IAAI,OAAe,CAAC;IAEpB,MAAM,eAAe,GAAG,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC;IAE/E,+CAA+C;IAC/C,IAAI,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClE,oBAAoB;QACpB,OAAO,GAAG,GAAG,eAAe,cAAc,IAAI,GAAG,IAAI,MAAM,CAAC;IAChE,CAAC;SAAM,CAAC;QACJ,OAAO,GAAG,GAAG,eAAe,KAAK,IAAI,GAAG,IAAI,MAAM,CAAC;IACvD,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AA3CD,oEA2CC"}
package/lib/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /*! Copyright (c) 2020, XAPP AI */
2
2
  export * from "./ArachneURLPattern";
3
3
  export * from "./constants";
4
- export * from "./normalizeURL";
5
- export * from "./promiseWithTimeout";
4
+ export * from "./generateFollowThroughPattern";
6
5
  export * from "./hallucinationDetector";
7
6
  export * from "./hasExtension";
7
+ export * from "./normalizeURL";
8
+ export * from "./promiseWithTimeout";
package/lib/index.js CHANGED
@@ -17,8 +17,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./ArachneURLPattern"), exports);
19
19
  __exportStar(require("./constants"), exports);
20
- __exportStar(require("./normalizeURL"), exports);
21
- __exportStar(require("./promiseWithTimeout"), exports);
20
+ __exportStar(require("./generateFollowThroughPattern"), exports);
22
21
  __exportStar(require("./hallucinationDetector"), exports);
23
22
  __exportStar(require("./hasExtension"), exports);
23
+ __exportStar(require("./normalizeURL"), exports);
24
+ __exportStar(require("./promiseWithTimeout"), exports);
24
25
  //# 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,iDAA+B;AAC/B,uDAAqC;AACrC,0DAAwC;AACxC,iDAA+B"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xapp/arachne-utils",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
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": "2d24174076a3a351f2a70f2bf5da88904cf80570"
41
+ "gitHead": "e47078cc574afec8f4be9f05055d52b7a0171fd1"
42
42
  }