@xapp/arachne-utils 1.2.2 → 1.3.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.
@@ -0,0 +1,5 @@
1
+ /*! Copyright (c) 2024, XAPP AI */
2
+ export declare const IMAGE_EXTENSIONS: string[];
3
+ export declare const VIDEO_EXTENSIONS: string[];
4
+ export declare const AUDIO_EXTENSIONS: string[];
5
+ export declare const COMMON_DOCUMENT_EXTENSIONS: string[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2024, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.COMMON_DOCUMENT_EXTENSIONS = exports.AUDIO_EXTENSIONS = exports.VIDEO_EXTENSIONS = exports.IMAGE_EXTENSIONS = void 0;
5
+ // common image extensions
6
+ exports.IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif', '.svg', '.webp'];
7
+ // common video extensions
8
+ exports.VIDEO_EXTENSIONS = ['.mp4', '.webm', '.ogg'];
9
+ // common audio extensions
10
+ exports.AUDIO_EXTENSIONS = ['.mp3', '.wav', '.ogg'];
11
+ exports.COMMON_DOCUMENT_EXTENSIONS = ['.pdf', '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx'];
12
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;AAElC,0BAA0B;AACb,QAAA,gBAAgB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnF,0BAA0B;AACb,QAAA,gBAAgB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAE1D,0BAA0B;AACb,QAAA,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5C,QAAA,0BAA0B,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /*! Copyright (c) 2024, XAPP AI */
2
+ /**
3
+ * Determines if the provided URL has a certain file extension. This is useful to filter out undesirable URLs to follow such as .pdf, .jpg, .png or other file types that don't have hyperlinks themselves.
4
+ *
5
+ * It assumes that a URL without an extension is HTML.
6
+ *
7
+ * @param url
8
+ * @param extension
9
+ */
10
+ export declare function hasExtension(url: string | URL, extension: string | string[]): boolean;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2024, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.hasExtension = void 0;
5
+ /**
6
+ * Determines if the provided URL has a certain file extension. This is useful to filter out undesirable URLs to follow such as .pdf, .jpg, .png or other file types that don't have hyperlinks themselves.
7
+ *
8
+ * It assumes that a URL without an extension is HTML.
9
+ *
10
+ * @param url
11
+ * @param extension
12
+ */
13
+ function hasExtension(url, extension) {
14
+ if (!url) {
15
+ return false;
16
+ }
17
+ let testUrl;
18
+ try {
19
+ testUrl = new URL(url);
20
+ }
21
+ catch (e) {
22
+ try {
23
+ // URL here doesn't really matter, we just need to make sure it parses
24
+ testUrl = new URL(`https://example.com${url}`);
25
+ }
26
+ catch (e) {
27
+ console.error(`⚠️ Error parsing URL: ${url}`);
28
+ return false;
29
+ }
30
+ }
31
+ const path = testUrl.pathname;
32
+ const extensionIndex = path.lastIndexOf('.');
33
+ const foundExtension = extensionIndex > 0 ? path.substring(extensionIndex) : '.html';
34
+ const testExtensions = [];
35
+ if (typeof extension === 'string') {
36
+ testExtensions.push(extension);
37
+ }
38
+ else {
39
+ testExtensions.push(...extension);
40
+ }
41
+ let hasExtension = false;
42
+ testExtensions.forEach((ext) => {
43
+ // lowercase and ensure we start with a period
44
+ ext = ext.toLowerCase();
45
+ ext = ext.startsWith('.') ? ext : `.${ext}`;
46
+ if (ext === foundExtension.toLowerCase()) {
47
+ hasExtension = true;
48
+ }
49
+ });
50
+ return hasExtension;
51
+ }
52
+ exports.hasExtension = hasExtension;
53
+ //# sourceMappingURL=hasExtension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasExtension.js","sourceRoot":"","sources":["../src/hasExtension.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;AAElC;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAC,GAAiB,EAAE,SAA4B;IAExE,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,IAAI,OAAY,CAAC;IAEjB,IAAI,CAAC;QACD,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,IAAI,CAAC;YACD,sEAAsE;YACtE,OAAO,GAAG,IAAI,GAAG,CAAC,sBAAsB,GAAG,EAAE,CAAC,CAAC;QACnD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,yBAAyB,GAAG,EAAE,CAAC,CAAC;YAE9C,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC;IAE9B,MAAM,cAAc,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAE7C,MAAM,cAAc,GAAG,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAErF,MAAM,cAAc,GAAa,EAAE,CAAC;IAEpC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAChC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;SAAM,CAAC;QACJ,cAAc,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,YAAY,GAAY,KAAK,CAAC;IAElC,cAAc,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC3B,8CAA8C;QAC9C,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QACxB,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;QAE5C,IAAI,GAAG,KAAK,cAAc,CAAC,WAAW,EAAE,EAAE,CAAC;YACvC,YAAY,GAAG,IAAI,CAAC;QACxB,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AAExB,CAAC;AAjDD,oCAiDC"}
package/lib/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /*! Copyright (c) 2020, XAPP AI */
2
2
  export * from "./ArachneURLPattern";
3
+ export * from "./constants";
3
4
  export * from "./normalizeURL";
4
5
  export * from "./promiseWithTimeout";
5
6
  export * from "./hallucinationDetector";
7
+ export * from "./hasExtension";
package/lib/index.js CHANGED
@@ -16,7 +16,9 @@ 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("./constants"), exports);
19
20
  __exportStar(require("./normalizeURL"), exports);
20
21
  __exportStar(require("./promiseWithTimeout"), exports);
21
22
  __exportStar(require("./hallucinationDetector"), exports);
23
+ __exportStar(require("./hasExtension"), exports);
22
24
  //# 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,iDAA+B;AAC/B,uDAAqC;AACrC,0DAAwC"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xapp/arachne-utils",
3
- "version": "1.2.2",
3
+ "version": "1.3.3",
4
4
  "types": "lib/index",
5
5
  "main": "lib/index",
6
6
  "files": [
@@ -11,13 +11,13 @@
11
11
  "access": "public"
12
12
  },
13
13
  "engines": {
14
- "node": "^14 || ^16 || ^18"
14
+ "node": "^14 || ^16 || ^18 || ^20.0.0"
15
15
  },
16
16
  "devDependencies": {
17
- "@microsoft/api-extractor": "7.39.1",
17
+ "@microsoft/api-extractor": "7.39.4",
18
18
  "@types/chai": "4.3.11",
19
19
  "@types/mocha": "10.0.6",
20
- "@types/node": "18.19.8",
20
+ "@types/node": "20.11.7",
21
21
  "@types/sinon": "17.0.3",
22
22
  "@types/sinon-chai": "3.2.12",
23
23
  "@xapp/config": "0.2.3",
@@ -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": "3b4279e8e24beba12e3f8e29275f83ef1ce02086"
41
+ "gitHead": "14a5571867b6172a795541e8a34437ffd43e6384"
42
42
  }