Split export. Added llm and better readme

This commit is contained in:
Warky 2025-03-20 21:11:09 +02:00
parent 2b20d0122d
commit c80c6f3588
6 changed files with 277 additions and 9 deletions

104
README.md
View File

@ -5,33 +5,135 @@ A comprehensive TypeScript/JavaScript utility library focused on precision and e
## Features
### String Tools
- Advanced string manipulation
- Pattern matching and validation
- Text transformation utilities
- Unicode handling
- i18n support
### Blob Tools
- Blob creation and modification
- Binary data handling
- Stream processing
- MIME type management
### File Conversion Tools
- Format conversions
- File type transformations
- Encoding/decoding utilities
- Batch processing capabilities
### Data Queue Tools
- Efficient data processing
- Batch operations support
### DOM
- DOM shortcuts like opening file links
### LLM
- LLM tools for text processing and generation
## Installation
```bash
pnpm install @warkypublic/artemis-kit
```
## Usage/Import examples
```typescript
import { getNestedValue } from "@warkypublic/artemis-kit/object";
import { NestedQueue } from "@warkypublic/artemis-kit/dataqueue";
import { camelCase, formatPercent } from "@warkypublic/artemis-kit/strings";
import {
b64DecodeUnicode,
b64EncodeUnicode,
} from "@warkypublic/artemis-kit/base64";
```
## Available Methods
### Strings
- trimLeft
- trimRight
- replaceStr
- replaceStrAll
- formatNumber
- formatCurrency
- formatDate
- getPlural
- formatPercent
- titleCase
- initCaps
- camelCase
- snakeCase
- reverseSnakeCase
- splitCamelCase
- humanFileSize
- getUUID
- newUUID
- blankValue
- ...
### i18n
- createI18nManager
- \_t
- \_tt
- ...
### Base64
- b64DecodeUnicode
- b64EncodeUnicode
- base64ToBlob
- blobToBase64
- FileToBase64
- FileToBlob
- BlobToString
### Object
- getNestedValue
- setNestedValue
- objectCompare
- createSelectOptions
### Queue
- NestedQueue
### Dom
- openFileLink
### Mime
- getExtFromMime
- getExtFromFilename
- getMimeFromExt
- isValidExtForMime
- getAllExtensionsForMime
### LLM
These are still work in progress.
## Requests
Requests are welcome! Please read our contributing guidelines and send me a message on Discord or add a github issue.
## Contributing
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
## License
MIT
MIT

View File

@ -9,7 +9,15 @@
"exports": {
".": "./src/index.ts",
"./dataqueue": "./src/dataqueue/index.ts",
"./object": "./src/object/index.ts"
"./object": "./src/object/index.ts",
"./strings": "./src/strings/index.ts",
"./mime": "./src/mime/index.ts",
"./base64": "./src/base64/index.ts",
"./promise": "./src/promise/index.ts",
"./dom": "./src/dom/index.ts",
"./i18n": "./src/i18n/index.ts",
"./logger": "./src/logger/index.ts",
"./llm": "./src/llm/index.ts"
},
"typesVersions": {
"*": {
@ -21,6 +29,30 @@
],
"object": [
"./src/object/index.ts"
],
"strings": [
"./src/strings/index.ts"
],
"mime": [
"./src/mime/index.ts"
],
"base64": [
"./src/base64/index.ts"
],
"promise": [
"./src/promise/index.ts"
],
"dom": [
"./src/dom/index.ts"
],
"i18n": [
"./src/i18n/index.ts"
],
"logger": [
"./src/logger/index.ts"
],
"llm": [
"./src/llm/index.ts"
]
}
},
@ -32,7 +64,15 @@
"exports": {
".": "./dist/index.js",
"./dataqueue": "./dist/dataqueue.js",
"./object": "./dist/object.js"
"./object": "./dist/object.js",
"./strings": "./dist/strings.js",
"./mime": "./dist/mime.js",
"./base64": "./dist/base64.js",
"./promise": "./dist/promise.js",
"./dom": "./dist/dom.js",
"./i18n": "./dist/i18n.js",
"./logger": "./dist/logger.js",
"./llm": "./dist/llm.js"
},
"typesVersions": {
"*": {
@ -40,10 +80,34 @@
"./dist/index.d.ts"
],
"dataqueue": [
"./dist/dataqueue..d.ts"
"./dist/dataqueue.d.ts"
],
"object": [
"./dist/object.d.ts"
],
"strings": [
"./dist/strings.d.ts"
],
"mime": [
"./dist/mime.d.ts"
],
"base64": [
"./dist/base64.d.ts"
],
"promise": [
"./dist/promise.d.ts"
],
"dom": [
"./dist/dom.d.ts"
],
"i18n": [
"./dist/i18n.d.ts"
],
"logger": [
"./dist/logger.d.ts"
],
"llm": [
"./dist/llm.d.ts"
]
}
}
@ -62,14 +126,17 @@
},
"keywords": [
"string",
"trim",
"queue",
"blob",
"dependencies",
"workspace",
"package",
"base64",
"file",
"replace",
"tools",
"llm",
"clarion",
"cli",
"tools",
"npm",
"yarn",
"pnpm"
],
"author": "Hein (Warkanum) Puth",

0
src/llm/index.test.ts Normal file
View File

9
src/llm/index.ts Normal file
View File

@ -0,0 +1,9 @@
import { getTextCompletion } from "./openapi";
export const OpenAPI = {
getTextCompletion,
};
export default {
OpenAPI,
};

82
src/llm/openapi.ts Normal file
View File

@ -0,0 +1,82 @@
interface OpenAICompletionResponse {
choices: {
text: string;
index: number;
logprobs: any;
finish_reason: string;
}[];
created: number;
id: string;
model: string;
object: string;
}
interface CompletionOptions {
prompt: string;
options?: {
url?: string;
apiKey?: string;
maxTokens?: number;
temperature?: number;
topP?: number;
n?: number;
stream?: boolean;
stop?: string | string[];
};
}
export async function getTextCompletion({
prompt,
options: {
url = "https://api.openai.com/v1/completions",
apiKey = "x-demo",
maxTokens = 50,
temperature = 0.7,
topP = 1,
n = 1,
stream = false,
stop = null,
},
}: CompletionOptions): Promise<string> {
try {
if (!prompt) {
throw new Error("Blank prompt");
}
if (!url) {
throw new Error("OpenAI API URL is not set");
}
if (!apiKey) {
throw new Error("OpenAI API key is not set");
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
model: "text-davinci-003",
prompt,
max_tokens: maxTokens,
temperature,
top_p: topP,
n,
stream,
stop,
}),
});
if (!response.ok) {
throw new Error(`OpenAI API error: ${response.statusText}`);
}
const data: OpenAICompletionResponse = await response.json();
return data.choices[0].text.trim();
} catch (error) {
console.error("Error:", error);
throw error;
}
}

View File

@ -10,6 +10,14 @@ export default defineConfig({
index: resolve(__dirname, "src/index.ts"),
object: resolve(__dirname, "src/object/index.ts"),
dataqueue: resolve(__dirname, "src/dataqueue/index.ts"),
strings: resolve(__dirname, "src/strings/index.ts"),
mime: resolve(__dirname, "src/mime/index.ts"),
base64: resolve(__dirname, "src/base64/index.ts"),
promise: resolve(__dirname, "src/promise/index.ts"),
dom: resolve(__dirname, "src/dom/index.ts"),
i18n: resolve(__dirname, "src/i18n/index.ts"),
logger: resolve(__dirname, "src/logger/index.ts"),
llm: resolve(__dirname, "src/llm/index.ts"),
},
formats: ["es"],
fileName: (format, entryname) => {