{"id":29151199,"url":"https://github.com/karpeleslab/klbfw","last_synced_at":"2026-02-25T02:32:41.715Z","repository":{"id":57123990,"uuid":"228743198","full_name":"KarpelesLab/klbfw","owner":"KarpelesLab","description":"KarpelesLab framework module for frontend code","archived":false,"fork":false,"pushed_at":"2025-05-01T04:25:45.000Z","size":269,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-01T00:08:50.042Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KarpelesLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-12-18T02:42:07.000Z","updated_at":"2025-05-01T04:25:48.000Z","dependencies_parsed_at":"2025-03-24T07:33:52.681Z","dependency_job_id":"25dd65f9-12c7-4539-8d8a-3147a23de87b","html_url":"https://github.com/KarpelesLab/klbfw","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/KarpelesLab/klbfw","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fklbfw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fklbfw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fklbfw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fklbfw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KarpelesLab","download_url":"https://codeload.github.com/KarpelesLab/klbfw/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fklbfw/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262870877,"owners_count":23377314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-01T00:08:53.357Z","updated_at":"2026-02-25T02:32:41.671Z","avatar_url":"https://github.com/KarpelesLab.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# klbfw\n\nKarpeles Lab Frontend Framework - A JavaScript library for communicating with KLB API.\n\nThis library provides a unified interface for interacting with KLB API services from both browser and Node.js environments.\n\n## Features\n\n- **Cross-environment compatibility**: Works in both browser and Node.js environments\n- **REST API client**: Simple and consistent interface for API requests\n- **File upload**: Supports file uploads in any environment with both direct PUT and AWS S3 multipart protocols\n- **Context handling**: Manages authentication, locale, and other contextual information\n- **Cookie management**: Cross-platform cookie handling that works in SSR mode\n- **Internationalization**: Easy access to i18n data\n\n## Installation\n\n```bash\nnpm install @karpeleslab/klbfw\n```\n\nFor Node.js environments with file upload support, install optional dependencies:\n\n```bash\nnpm install @karpeleslab/klbfw node-fetch @xmldom/xmldom\n```\n\n## Development\n\n```bash\n# Install dependencies\nnpm install\n\n# Run tests\nnpm test\n\n# Run tests with coverage\nnpm run test:coverage\n\n# Run integration tests (requires KLB API server)\nnpm run test:integration\n```\n\n## Version 0.2.0 Changes\n\n- **Modern JavaScript**: Refactored to use ES6+ features (arrow functions, const/let, template literals)\n- **Improved Documentation**: Added comprehensive JSDoc comments for all modules and functions\n- **Better Code Organization**: Restructured code for improved readability and maintainability\n- **Cross-Platform Support**: Enhanced environment detection and compatibility\n- **Standardized Naming**: Consistent use of camelCase with backward compatibility for legacy APIs\n- **Enhanced Error Handling**: More robust error handling and reporting\n\n# API\n\n## REST API Methods\n\n### rest(api, method, params, context)\n\nPerforms a REST query and returns a promise to the response.\n\n### rest_get(name, params) / restGet(name, params)\n\nSimplified version of rest() that uses HTTP GET. Takes a REST API endpoint name and optional parameters, returning a Promise with the response.\n\nNote: Starting from version 0.2.0, camelCase method names are also available (e.g., `restGet` instead of `rest_get`).\n\n### upload\n\nThe upload module provides cross-platform file upload capabilities, supporting both browser and Node.js environments.\n\n#### Browser Usage\n\n```javascript\n// Open file picker and upload selected files\nupload.init('Misc/Debug:testUpload')()\n  .then(result =\u003e console.log('Upload complete', result));\n\n// Open file picker with custom parameters and notification callback\nupload.init('Support/Ticket:upload', {image_variation: 'alias=mini\u0026strip\u0026scale_crop=300x200'}, (result) =\u003e {\n  if (result.status == 'complete') console.log(result.final);\n});\n\n// Upload a specific File object\nupload.append('Misc/Debug:testUpload', fileObject)\n  .then(result =\u003e console.log('Upload complete', result));\n\n// Track progress\nupload.onprogress = (status) =\u003e {\n  console.log('Progress:', status.running.map(i =\u003e i.status));\n};\n\n// Cancel an upload\nupload.cancelItem(uploadId);\n```\n\n#### Node.js Usage\n\n```javascript\n// For Node.js environments, first install dependencies:\n// npm install node-fetch @xmldom/xmldom\n\n// Initialize upload with specific file paths\nupload.init('Misc/Debug:testUpload')(['./file1.txt', './file2.jpg'])\n  .then(result =\u003e console.log('Upload complete', result));\n\n// Or create a custom file object with path\nconst file = {\n  name: 'test.txt',\n  size: 1024,\n  type: 'text/plain',\n  path: '/path/to/file.txt'\n};\nupload.append('Misc/Debug:testUpload', file)\n  .then(result =\u003e console.log('Upload complete', result));\n```\n\n#### Upload Management\n\nThe upload module provides methods to manage active uploads:\n\n- `upload.getStatus()`: Get current upload status (queue, running, failed)\n- `upload.cancelItem(uploadId)`: Cancel an upload\n- `upload.pauseItem(uploadId)`: Pause an active upload\n- `upload.resumeItem(uploadId)`: Resume a paused upload\n- `upload.retryItem(uploadId)`: Retry a failed upload\n- `upload.deleteItem(uploadId)`: Remove an upload from the queue or failed list\n\n## Query Parameter Methods\n\n### GET\n\nObject containing all URL query parameters parsed from the request.\n\n### Get(key)\n\nRetrieves a specific query parameter value by key. If no key is provided, returns the entire GET object.\n\n### flushGet()\n\nClears the GET parameters by resetting the internal GET object to an empty object.\n\n## URL and Path Methods\n\n### getPrefix()\n\nReturns the language/etc prefix part of the URL, for example `/l/en-US`. The prefix should be inserted before the path in the URL.\n\n### getUrl()\n\nReturns the active URL.\n\n### getPath()\n\nReturns the non-prefixed request path.\n\n### trimPrefix(url)\n\nProcesses a URL to separate the prefix parts from the main path. Returns an array with two elements: an object containing the identified prefixes and the remaining path.\n\n## Context and State Methods\n\n### getSettings()\n\nReturns active settings if any.\n\n### getRealm()\n\nReturns realm information.\n\n### getContext()\n\nReturns current context.\n\n### setContext(ctx)\n\nModifies the current context.\n\n### getInitialState()\n\nReturns the initial state passed from SSR execution (or null if no SSR was performed).\n\n### getMode()\n\nReturns the current rendering mode `ssr`, `js` etc.\n\n### getHostname()\n\nReturns the hostname part of the current URL.\n\n### getRegistry()\n\nReturns data from the registry.\n\n### getLocale()\n\nReturns the currently active locale, for example `en-US`.\n\n### getUserGroup()\n\nReturns `g` from context, which is the current active user group.\n\n### getCurrency()\n\nReturns the currently selected currency, such as `USD`.\n\n### getToken()\n\nReturns the CSRF token.\n\n### getUuid()\n\nReturns the UUID of the request.\n\n### getI18N(language)\n\nRetrieves internationalization (i18n) data for a specified language. If no language is provided, uses the current locale.\n\n## Cookie Methods\n\nThese methods are required as using things like `document.cookie` will not work in SSR mode. The methods described here will work when SSR is enabled, and will cause cookies to be added to the HTTP response.\n\n### getCookie(cookie)\n\nGet the value of a specific cookie.\n\n### setCookie(cookie, value)\n\nSets value for a cookie.\n\n### hasCookie(cookie)\n\nChecks for presence of a given cookie.\n\n## Cross-Platform Support\n\nAs of version 0.2.0, klbfw includes improved environment detection and cross-platform utilities to support both browser and Node.js environments.\n\n### Environment Detection\n\nThe library automatically detects the current environment:\n\n```javascript\nconst env = {\n  isBrowser: typeof window !== 'undefined' \u0026\u0026 typeof document !== 'undefined',\n  isNode: typeof process !== 'undefined' \u0026\u0026 process.versions \u0026\u0026 process.versions.node\n};\n```\n\n### Cross-Platform Utilities\n\nSeveral utilities have been designed to work across environments:\n\n- **Fetch**: Uses the browser's native `fetch` or `node-fetch` in Node.js\n- **XML Parsing**: Uses the browser's `DOMParser` or `xmldom` in Node.js\n- **File Reading**: Uses `FileReader` in the browser or `fs` in Node.js\n- **Event Dispatching**: Uses `CustomEvent` in the browser or `EventEmitter` in Node.js\n\n### Node.js Requirements\n\nTo use klbfw with full functionality in Node.js, install the optional dependencies:\n\n```bash\nnpm install node-fetch @xmldom/xmldom\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarpeleslab%2Fklbfw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarpeleslab%2Fklbfw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarpeleslab%2Fklbfw/lists"}