humanizedtext 0.1.0

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.
Files changed (4) hide show
  1. package/README.md +36 -0
  2. package/index.d.ts +32 -0
  3. package/index.js +86 -0
  4. package/package.json +18 -0
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # humanizedtext (npm)
2
+
3
+ Official JavaScript SDK for HumanizedText API.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install humanizedtext
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```js
14
+ const { HumanizedTextClient } = require("humanizedtext");
15
+
16
+ const client = new HumanizedTextClient({
17
+ apiKey: "YOUR_API_KEY",
18
+ baseUrl: "https://api.humanizedtext.pro/api/v1",
19
+ });
20
+
21
+ const result = await client.humanize({
22
+ text: "This is a sample text.",
23
+ tone: "professional",
24
+ ultraHumanize: true,
25
+ keywords: ["SEO", "AI writing"],
26
+ });
27
+
28
+ console.log(result);
29
+ ```
30
+
31
+ ## Methods
32
+
33
+ - `humanize({ text, tone, ultraHumanize, keywords })`
34
+ - `grammarFixer({ text })`
35
+ - `contentRewriter({ text })`
36
+ - `seoBlogWriter({ topic })`
package/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ export interface HumanizeParams {
2
+ text: string;
3
+ tone?: string | null;
4
+ ultraHumanize?: boolean;
5
+ keywords?: string[] | null;
6
+ }
7
+
8
+ export interface GrammarParams {
9
+ text: string;
10
+ }
11
+
12
+ export interface ContentRewriterParams {
13
+ text: string;
14
+ }
15
+
16
+ export interface SeoBlogWriterParams {
17
+ topic: string;
18
+ }
19
+
20
+ export class HumanizedTextAPIError extends Error {
21
+ statusCode?: number;
22
+ payload?: unknown;
23
+ constructor(message: string, statusCode?: number, payload?: unknown);
24
+ }
25
+
26
+ export class HumanizedTextClient {
27
+ constructor(options: { apiKey: string; baseUrl?: string; timeout?: number });
28
+ humanize(params: HumanizeParams): Promise<any>;
29
+ grammarFixer(params: GrammarParams): Promise<any>;
30
+ contentRewriter(params: ContentRewriterParams): Promise<any>;
31
+ seoBlogWriter(params: SeoBlogWriterParams): Promise<any>;
32
+ }
package/index.js ADDED
@@ -0,0 +1,86 @@
1
+ class HumanizedTextAPIError extends Error {
2
+ constructor(message, statusCode, payload) {
3
+ super(message);
4
+ this.name = "HumanizedTextAPIError";
5
+ this.statusCode = statusCode;
6
+ this.payload = payload;
7
+ }
8
+ }
9
+
10
+ class HumanizedTextClient {
11
+ constructor({
12
+ apiKey,
13
+ baseUrl = "https://api.humanizedtext.pro/api/v1",
14
+ timeout = 60000,
15
+ }) {
16
+ if (!apiKey) {
17
+ throw new Error("apiKey is required");
18
+ }
19
+ this.apiKey = apiKey;
20
+ this.baseUrl = baseUrl.replace(/\/$/, "");
21
+ this.timeout = timeout;
22
+ }
23
+
24
+ async request(path, body) {
25
+ const controller = new AbortController();
26
+ const timer = setTimeout(() => controller.abort(), this.timeout);
27
+
28
+ try {
29
+ const response = await fetch(`${this.baseUrl}${path}`, {
30
+ method: "POST",
31
+ headers: {
32
+ "Content-Type": "application/json",
33
+ "X-API-Key": this.apiKey,
34
+ },
35
+ body: JSON.stringify(body),
36
+ signal: controller.signal,
37
+ });
38
+
39
+ const contentType = response.headers.get("content-type") || "";
40
+ const payload = contentType.includes("application/json")
41
+ ? await response.json()
42
+ : { detail: await response.text() };
43
+
44
+ if (!response.ok) {
45
+ const detail =
46
+ payload && payload.detail ? payload.detail : "Request failed";
47
+ throw new HumanizedTextAPIError(
48
+ String(detail),
49
+ response.status,
50
+ payload,
51
+ );
52
+ }
53
+
54
+ return payload;
55
+ } finally {
56
+ clearTimeout(timer);
57
+ }
58
+ }
59
+
60
+ humanize({ text, tone = null, ultraHumanize = false, keywords = null }) {
61
+ const body = {
62
+ text,
63
+ ultra_humanize: ultraHumanize,
64
+ };
65
+ if (tone !== null) body.tone = tone;
66
+ if (keywords !== null) body.keywords = keywords;
67
+ return this.request("/sdk/humanize", body);
68
+ }
69
+
70
+ grammarFixer({ text }) {
71
+ return this.request("/sdk/grammar-fixer", { text });
72
+ }
73
+
74
+ contentRewriter({ text }) {
75
+ return this.request("/sdk/content-rewriter", { text });
76
+ }
77
+
78
+ seoBlogWriter({ topic }) {
79
+ return this.request("/sdk/seo-blog-writer", { topic });
80
+ }
81
+ }
82
+
83
+ module.exports = {
84
+ HumanizedTextClient,
85
+ HumanizedTextAPIError,
86
+ };
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "humanizedtext",
3
+ "version": "0.1.0",
4
+ "description": "Official JavaScript SDK for HumanizedText API",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "humanizedtext",
10
+ "sdk",
11
+ "ai",
12
+ "rewriter",
13
+ "humanizer"
14
+ ],
15
+ "engines": {
16
+ "node": ">=18"
17
+ }
18
+ }