@apiverve/codedetector 1.1.10 → 1.1.13

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2024 APIVerve, and Evlar LLC
3
+ Copyright (c) 2025 APIVerve, and EvlarSoft LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -5,8 +5,9 @@ Code Detector is a simple tool for detecting the language of code in text. It re
5
5
  ![Build Status](https://img.shields.io/badge/build-passing-green)
6
6
  ![Code Climate](https://img.shields.io/badge/maintainability-B-purple)
7
7
  ![Prod Ready](https://img.shields.io/badge/production-ready-blue)
8
+ [![npm version](https://img.shields.io/npm/v/@apiverve/codedetector.svg)](https://www.npmjs.com/package/@apiverve/codedetector)
8
9
 
9
- This is a Javascript Wrapper for the [Code Detector API](https://apiverve.com/marketplace/codedetector)
10
+ This is a Javascript Wrapper for the [Code Detector API](https://apiverve.com/marketplace/codedetector?utm_source=npm&utm_medium=readme)
10
11
 
11
12
  ---
12
13
 
@@ -27,15 +28,15 @@ yarn add @apiverve/codedetector
27
28
  ## Configuration
28
29
 
29
30
  Before using the Code Detector API client, you have to setup your account and obtain your API Key.
30
- You can get it by signing up at [https://apiverve.com](https://apiverve.com)
31
+ You can get it by signing up at [https://apiverve.com](https://apiverve.com?utm_source=npm&utm_medium=readme)
31
32
 
32
33
  ---
33
34
 
34
35
  ## Quick Start
35
36
 
36
- [Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart)
37
+ [Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart?utm_source=npm&utm_medium=readme)
37
38
 
38
- The Code Detector API documentation is found here: [https://docs.apiverve.com/ref/codedetector](https://docs.apiverve.com/ref/codedetector).
39
+ The Code Detector API documentation is found here: [https://docs.apiverve.com/ref/codedetector](https://docs.apiverve.com/ref/codedetector?utm_source=npm&utm_medium=readme).
39
40
  You can find parameters, example responses, and status codes documented here.
40
41
 
41
42
  ### Setup
@@ -58,7 +59,9 @@ const api = new codedetectorAPI({
58
59
  Using the API is simple. All you have to do is make a request. The API will return a response with the data you requested.
59
60
 
60
61
  ```javascript
61
- var query = "a = 5\nb = 6\nc = 7\n\n# Uncomment below to take inputs from the user\n# a = float(input('Enter first side: '))\n# b = float(input('Enter second side: '))\n# c = float(input('Enter third side: '))\n\n# calculate the semi-perimeter\ns = (a + b + c) / 2\n\n# calculate the area\narea = (s*(s-a)*(s-b)*(s-c)) ** 0.5\nprint('The area of the triangle is %0.2f' %area)";
62
+ var query = {
63
+ "code": "a = 5\nb = 6\nc = 7\n\n# calculate the semi-perimeter\ns = (a + b + c) / 2\n\n# calculate the area\narea = (s*(s-a)*(s-b)*(s-c)) ** 0.5\nprint('The area of the triangle is %0.2f' %area)"
64
+ };
62
65
 
63
66
  api.execute(query, function (error, data) {
64
67
  if (error) {
@@ -76,7 +79,9 @@ api.execute(query, function (error, data) {
76
79
  You can also use promises to make requests. The API returns a promise that you can use to handle the response.
77
80
 
78
81
  ```javascript
79
- var query = "a = 5\nb = 6\nc = 7\n\n# Uncomment below to take inputs from the user\n# a = float(input('Enter first side: '))\n# b = float(input('Enter second side: '))\n# c = float(input('Enter third side: '))\n\n# calculate the semi-perimeter\ns = (a + b + c) / 2\n\n# calculate the area\narea = (s*(s-a)*(s-b)*(s-c)) ** 0.5\nprint('The area of the triangle is %0.2f' %area)";
82
+ var query = {
83
+ "code": "a = 5\nb = 6\nc = 7\n\n# calculate the semi-perimeter\ns = (a + b + c) / 2\n\n# calculate the area\narea = (s*(s-a)*(s-b)*(s-c)) ** 0.5\nprint('The area of the triangle is %0.2f' %area)"
84
+ };
80
85
 
81
86
  api.execute(query)
82
87
  .then(data => {
@@ -95,7 +100,9 @@ You can also use async/await to make requests. The API returns a promise that yo
95
100
 
96
101
  ```javascript
97
102
  async function makeRequest() {
98
- var query = "a = 5\nb = 6\nc = 7\n\n# Uncomment below to take inputs from the user\n# a = float(input('Enter first side: '))\n# b = float(input('Enter second side: '))\n# c = float(input('Enter third side: '))\n\n# calculate the semi-perimeter\ns = (a + b + c) / 2\n\n# calculate the area\narea = (s*(s-a)*(s-b)*(s-c)) ** 0.5\nprint('The area of the triangle is %0.2f' %area)";
103
+ var query = {
104
+ "code": "a = 5\nb = 6\nc = 7\n\n# calculate the semi-perimeter\ns = (a + b + c) / 2\n\n# calculate the area\narea = (s*(s-a)*(s-b)*(s-c)) ** 0.5\nprint('The area of the triangle is %0.2f' %area)"
105
+ };
99
106
 
100
107
  try {
101
108
  const data = await api.execute(query);
@@ -115,7 +122,7 @@ async function makeRequest() {
115
122
  "status": "ok",
116
123
  "error": null,
117
124
  "data": {
118
- "likelihood": 0.95,
125
+ "likelihood": 0.99,
119
126
  "family": "PYTHON",
120
127
  "current": "python",
121
128
  "readable": "Python Code",
@@ -128,7 +135,7 @@ async function makeRequest() {
128
135
 
129
136
  ## Customer Support
130
137
 
131
- Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact).
138
+ Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=npm&utm_medium=readme).
132
139
 
133
140
  ---
134
141
 
@@ -140,14 +147,14 @@ Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Tw
140
147
 
141
148
  ## Legal
142
149
 
143
- All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms) and all legal documents and agreements.
150
+ All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms?utm_source=npm&utm_medium=readme), [Privacy Policy](https://apiverve.com/privacy?utm_source=npm&utm_medium=readme), and [Refund Policy](https://apiverve.com/refund?utm_source=npm&utm_medium=readme).
144
151
 
145
152
  ---
146
153
 
147
154
  ## License
148
155
  Licensed under the The MIT License (MIT)
149
156
 
150
- Copyright (©) 2025 APIVerve, and Evlar LLC
157
+ Copyright (©) 2026 APIVerve, and EvlarSoft LLC
151
158
 
152
159
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
153
160
 
package/index.d.ts CHANGED
@@ -7,10 +7,19 @@ declare module '@apiverve/codedetector' {
7
7
  export interface codedetectorResponse {
8
8
  status: string;
9
9
  error: string | null;
10
- data: any;
10
+ data: CodeDetectorData;
11
11
  code?: number;
12
12
  }
13
13
 
14
+
15
+ interface CodeDetectorData {
16
+ likelihood: number;
17
+ family: string;
18
+ current: string;
19
+ readable: string;
20
+ extension: string;
21
+ }
22
+
14
23
  export default class codedetectorWrapper {
15
24
  constructor(options: codedetectorOptions);
16
25
 
package/index.js CHANGED
@@ -34,6 +34,102 @@ class codedetectorWrapper {
34
34
 
35
35
  // secure is deprecated, all requests must be made over HTTPS
36
36
  this.baseURL = 'https://api.apiverve.com/v1/codedetector';
37
+
38
+ // Validation rules for parameters (generated from schema)
39
+ this.validationRules = {"code":{"type":"string","required":true}};
40
+ }
41
+
42
+ /**
43
+ * Validate query parameters against schema rules
44
+ * @param {Object} query - The query parameters to validate
45
+ * @throws {Error} - If validation fails
46
+ */
47
+ validateParams(query) {
48
+ const errors = [];
49
+
50
+ for (const [paramName, rules] of Object.entries(this.validationRules)) {
51
+ const value = query[paramName];
52
+
53
+ // Check required
54
+ if (rules.required && (value === undefined || value === null || value === '')) {
55
+ errors.push(`Required parameter [${paramName}] is missing.`);
56
+ continue;
57
+ }
58
+
59
+ // Skip validation if value is not provided and not required
60
+ if (value === undefined || value === null) {
61
+ continue;
62
+ }
63
+
64
+ // Type validation
65
+ if (rules.type === 'integer' || rules.type === 'number') {
66
+ const numValue = Number(value);
67
+ if (isNaN(numValue)) {
68
+ errors.push(`Parameter [${paramName}] must be a valid ${rules.type}.`);
69
+ continue;
70
+ }
71
+
72
+ if (rules.type === 'integer' && !Number.isInteger(numValue)) {
73
+ errors.push(`Parameter [${paramName}] must be an integer.`);
74
+ continue;
75
+ }
76
+
77
+ // Min/max validation for numbers
78
+ if (rules.min !== undefined && numValue < rules.min) {
79
+ errors.push(`Parameter [${paramName}] must be at least ${rules.min}.`);
80
+ }
81
+ if (rules.max !== undefined && numValue > rules.max) {
82
+ errors.push(`Parameter [${paramName}] must be at most ${rules.max}.`);
83
+ }
84
+ } else if (rules.type === 'string') {
85
+ if (typeof value !== 'string') {
86
+ errors.push(`Parameter [${paramName}] must be a string.`);
87
+ continue;
88
+ }
89
+
90
+ // Length validation for strings
91
+ if (rules.minLength !== undefined && value.length < rules.minLength) {
92
+ errors.push(`Parameter [${paramName}] must be at least ${rules.minLength} characters.`);
93
+ }
94
+ if (rules.maxLength !== undefined && value.length > rules.maxLength) {
95
+ errors.push(`Parameter [${paramName}] must be at most ${rules.maxLength} characters.`);
96
+ }
97
+
98
+ // Format validation
99
+ if (rules.format) {
100
+ const formatPatterns = {
101
+ 'email': /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
102
+ 'url': /^https?:\/\/.+/i,
103
+ 'ip': /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
104
+ 'date': /^\d{4}-\d{2}-\d{2}$/,
105
+ 'hexColor': /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
106
+ };
107
+
108
+ if (formatPatterns[rules.format] && !formatPatterns[rules.format].test(value)) {
109
+ errors.push(`Parameter [${paramName}] must be a valid ${rules.format}.`);
110
+ }
111
+ }
112
+ } else if (rules.type === 'boolean') {
113
+ if (typeof value !== 'boolean' && value !== 'true' && value !== 'false') {
114
+ errors.push(`Parameter [${paramName}] must be a boolean.`);
115
+ }
116
+ } else if (rules.type === 'array') {
117
+ if (!Array.isArray(value)) {
118
+ errors.push(`Parameter [${paramName}] must be an array.`);
119
+ }
120
+ }
121
+
122
+ // Enum validation
123
+ if (rules.enum && Array.isArray(rules.enum)) {
124
+ if (!rules.enum.includes(value)) {
125
+ errors.push(`Parameter [${paramName}] must be one of: ${rules.enum.join(', ')}.`);
126
+ }
127
+ }
128
+ }
129
+
130
+ if (errors.length > 0) {
131
+ throw new Error(`Validation failed: ${errors.join(' ')} See documentation: https://docs.apiverve.com/ref/codedetector`);
132
+ }
37
133
  }
38
134
 
39
135
  async execute(query, callback) {
@@ -58,14 +154,8 @@ class codedetectorWrapper {
58
154
  }
59
155
  }
60
156
 
61
- var requiredParams = ["text"];
62
- if (requiredParams.length > 0) {
63
- for (var i = 0; i < requiredParams.length; i++) {
64
- if (!query[requiredParams[i]]) {
65
- throw new Error(`Required parameter [${requiredParams[i]}] is missing. See documentation: https://docs.apiverve.com/ref/codedetector`);
66
- }
67
- }
68
- }
157
+ // Validate parameters against schema rules
158
+ this.validateParams(query);
69
159
 
70
160
  const method = 'POST';
71
161
  const url = method === 'POST' ? this.baseURL : this.constructURL(query);
@@ -108,7 +198,7 @@ class codedetectorWrapper {
108
198
  constructURL(query) {
109
199
  let url = this.baseURL;
110
200
 
111
- if(query && typeof query === 'object')
201
+ if(query && typeof query === 'object')
112
202
  {
113
203
  if (Object.keys(query).length > 0) {
114
204
  const queryString = Object.keys(query)
@@ -119,6 +209,7 @@ class codedetectorWrapper {
119
209
  }
120
210
  return url;
121
211
  }
212
+
122
213
  }
123
214
 
124
215
  module.exports = codedetectorWrapper;
package/package.json CHANGED
@@ -1,26 +1,40 @@
1
1
  {
2
2
  "name": "@apiverve/codedetector",
3
- "version": "1.1.10",
3
+ "version": "1.1.13",
4
4
  "description": "Code Detector is a simple tool for detecting the language of code in text. It returns details such as extension, language, family, and more.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
+ "sideEffects": false,
8
+ "engines": {
9
+ "node": ">=14.0.0"
10
+ },
11
+ "files": [
12
+ "index.js",
13
+ "index.d.ts",
14
+ "LICENSE"
15
+ ],
7
16
  "scripts": {
8
17
  "test": "mocha",
9
18
  "example": "node examples/basic.js"
10
19
  },
11
20
  "repository": {
12
21
  "type": "git",
13
- "url": "git+https://github.com/apiverve/codedetector-API.git"
22
+ "url": "git+https://github.com/apiverve/codedetector-api.git",
23
+ "directory": "npm"
14
24
  },
15
25
  "keywords": [
16
- "code detector", "code detection", "code detect", "code api", "code tool"
26
+ ""
17
27
  ],
18
- "author": "APIVerve <hello@apiverve.com> (http://apiverve.com/)",
28
+ "author": {
29
+ "name": "APIVerve",
30
+ "email": "hello@apiverve.com",
31
+ "url": "https://apiverve.com"
32
+ },
19
33
  "license": "MIT",
20
34
  "bugs": {
21
- "url": "https://github.com/apiverve/codedetector-API/issues"
35
+ "url": "https://github.com/apiverve/codedetector-api/issues"
22
36
  },
23
- "homepage": "https://apiverve.com/marketplace/codedetector?utm_source=npm",
37
+ "homepage": "https://apiverve.com/marketplace/codedetector?utm_source=npm&utm_medium=homepage",
24
38
  "devDependencies": {
25
39
  "mocha": "^11.0.1",
26
40
  "chai": "^5.1.2",
@@ -29,6 +43,6 @@
29
43
  "dependencies": {
30
44
  "node-fetch": "^3.3.2",
31
45
  "promise": "^8.3.0",
32
- "axios": "1.8.4"
46
+ "axios": "1.13.2"
33
47
  }
34
48
  }
package/examples/basic.js DELETED
@@ -1,36 +0,0 @@
1
- /**
2
- * Basic Example - Code Detector API
3
- *
4
- * This example demonstrates how to use the Code Detector API.
5
- * Make sure to set your API key in the .env file or replace '[YOUR_API_KEY]' below.
6
- */
7
-
8
- require('dotenv').config();
9
- const codedetectorAPI = require('../index.js');
10
-
11
- // Initialize the API client
12
- const api = new codedetectorAPI({
13
- api_key: process.env.API_KEY || '[YOUR_API_KEY]'
14
- });
15
-
16
- // Example query
17
- var query = "a = 5\nb = 6\nc = 7\n\n# Uncomment below to take inputs from the user\n# a = float(input('Enter first side: '))\n# b = float(input('Enter second side: '))\n# c = float(input('Enter third side: '))\n\n# calculate the semi-perimeter\ns = (a + b + c) / 2\n\n# calculate the area\narea = (s*(s-a)*(s-b)*(s-c)) ** 0.5\nprint('The area of the triangle is %0.2f' %area)";
18
-
19
- // Make the API request using callback
20
- console.log('Making request to Code Detector API...\n');
21
-
22
- api.execute(query, function (error, data) {
23
- if (error) {
24
- console.error('Error occurred:');
25
- if (error.error) {
26
- console.error('Message:', error.error);
27
- console.error('Status:', error.status);
28
- } else {
29
- console.error(JSON.stringify(error, null, 2));
30
- }
31
- return;
32
- }
33
-
34
- console.log('Response:');
35
- console.log(JSON.stringify(data, null, 2));
36
- });
package/tmp/build.dat DELETED
@@ -1 +0,0 @@
1
- #