{"id":26093163,"url":"https://github.com/noxlovette/svarog","last_synced_at":"2025-03-09T11:55:44.553Z","repository":{"id":280686557,"uuid":"942808726","full_name":"noxlovette/Svarog","owner":"noxlovette","description":"A collection of small but userful tools for a Svelte application","archived":false,"fork":false,"pushed_at":"2025-03-04T19:25:56.000Z","size":70,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T19:35:04.159Z","etag":null,"topics":["jwt","markdown","svelte","tools","turnstile","validation"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/noxlovette.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}},"created_at":"2025-03-04T17:54:21.000Z","updated_at":"2025-03-04T19:26:00.000Z","dependencies_parsed_at":"2025-03-04T19:46:26.202Z","dependency_job_id":null,"html_url":"https://github.com/noxlovette/Svarog","commit_stats":null,"previous_names":["noxlovette/svarog"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noxlovette%2FSvarog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noxlovette%2FSvarog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noxlovette%2FSvarog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noxlovette%2FSvarog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noxlovette","download_url":"https://codeload.github.com/noxlovette/Svarog/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242685874,"owners_count":20169243,"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":["jwt","markdown","svelte","tools","turnstile","validation"],"created_at":"2025-03-09T11:55:43.732Z","updated_at":"2025-03-09T11:55:44.542Z","avatar_url":"https://github.com/noxlovette.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Svarog Toolbox\n\n[![npm version](https://badge.fury.io/js/svarog.svg)](https://badge.fury.io/js/svarog)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA comprehensive collection of TypeScript utilities for modern web development, focusing on API interactions, authentication, form handling, validation, and more. Designed to streamline development workflows with well-documented, type-safe functions.\n\n## Installation\n\n```bash\nnpm install svarog\n```\n\nor\n\n```bash\npnpm add svarog\n```\n\n## Features\n\n- 🔄 **API Utilities**: Standardized API response handling with type-safe results\n- 🔐 **Authentication**: JWT validation and token refresh mechanisms\n- 🍪 **Cookie Management**: Utilities for handling HTTP cookies\n- 📝 **Form Handling**: Enhanced form processing with validation and submission handling\n- ✅ **Validation**: Comprehensive form validation functions\n- 📄 **Markdown Processing**: Powerful markdown parsing with customizable options\n- 🕒 **Date \u0026 Time Formatting**: Flexible date/time display options\n- 🔄 **Turnstile Integration**: Cloudflare Turnstile verification support\n- 🔍 **SEO Component**: Comprehensive SEO metadata management for Svelte applications\n\n## Usage Examples\n\n### API Response Handling\n\n```typescript\nimport { handleApiResponse, isSuccessResponse } from 'svarog/api';\n\n// Get user profile\nasync function fetchUserProfile(userId: string) {\n\tconst response = await fetch(`/api/users/${userId}`);\n\tconst result = await handleApiResponse\u003cUserProfile\u003e(response);\n\n\tif (isSuccessResponse(result)) {\n\t\treturn result.data;\n\t} else {\n\t\tconsole.error(`Error ${result.status}: ${result.message}`);\n\t\treturn null;\n\t}\n}\n```\n\n### Form Validation\n\n```typescript\nimport {\n\tvalidateEmail,\n\tvalidatePassword,\n\tvalidateMinLength,\n\tcomposeValidators\n} from 'svarog/validation';\n\n// Create a composite validator\nconst validateUsername = composeValidators(validateMinLength(3), (value) =\u003e\n\t!/^[a-zA-Z0-9_]+$/.test(value)\n\t\t? 'Username can only contain letters, numbers, and underscores'\n\t\t: null\n);\n\n// Use in form submit handler\nfunction handleSubmit(event) {\n\tconst email = emailInput.value;\n\tconst password = passwordInput.value;\n\n\tconst emailError = validateEmail(email);\n\tconst passwordError = validatePassword(password);\n\n\tif (emailError || passwordError) {\n\t\t// Handle validation errors\n\t\treturn;\n\t}\n\n\t// Proceed with form submission\n}\n```\n\n### Enhanced Form Handling in SvelteKit\n\n```typescript\nimport { enhanceForm } from 'svarog/form';\n\n// In your Svelte component\nconst enhance = enhanceForm({\n  messages: {\n    success: 'Your profile was updated successfully',\n    defaultError: 'Could not update profile'\n  },\n  isLoadingStore: loadingStore,\n  notificationStore: toastStore\n});\n\n// Use in your form\n\u003cform method=\"POST\" use:enhance\u003e\n  \u003c!-- form fields --\u003e\n\u003c/form\u003e\n```\n\n### Date Formatting\n\n```typescript\nimport { formatDate, formatDateTime, formatRelativeTime } from 'svarog/time';\n\n// Format a date with custom options\nformatDate(new Date(), {\n\tyear: true,\n\tmonth: 'long',\n\tday: true\n}); // \"March 6, 2025\"\n\n// Format relative time\nformatRelativeTime(new Date(Date.now() - 3600000)); // \"1 hour ago\"\n```\n\n### Markdown Processing\n\n```typescript\nimport { parseMarkdown, extractFrontmatter } from 'svarog/markdown';\n\n// Parse markdown with custom options\nconst html = await parseMarkdown(markdownContent, {\n\tgfm: true,\n\thighlight: true,\n\ttoc: true,\n\theadingAnchors: true\n});\n\n// Extract and use frontmatter\nconst [metadata, content] = extractFrontmatter(markdownWithFrontmatter);\n```\n\n### JWT Authentication\n\n```typescript\nimport { getUserFromToken, requireAuth } from 'svarog/token';\n\n// In a SvelteKit load function\nexport async function load({ event }) {\n\t// Get authenticated user or null\n\tconst user = await getUserFromToken(event);\n\n\treturn {\n\t\tuser\n\t};\n}\n\n// For protected routes\nexport async function load({ event }) {\n\t// This will redirect to login if not authenticated\n\tconst user = await requireAuth(event);\n\n\treturn {\n\t\tuser\n\t};\n}\n```\n\n### SEO Component for Svelte\n\n```svelte\n\u003cscript\u003e\n\timport SEO from 'svarog/seo';\n\u003c/script\u003e\n\n\u003cSEO\n\ttitle=\"Dashboard | Svarog\"\n\tdescription=\"View your application data and analytics.\"\n\tkeywords=\"dashboard, analytics, data visualization\"\n/\u003e\n```\n\nWith advanced configuration:\n\n```svelte\n\u003cSEO\n\ttitle=\"Project Management | Svarog\"\n\tdescription=\"Manage your projects and track progress efficiently.\"\n\tcanonical=\"https://example.com/projects\"\n\ttwitterSite=\"svarogapp\"\n\tog={{\n\t\ttype: 'article',\n\t\tlocale: 'en_US'\n\t}}\n\tschema={{\n\t\ttype: 'WebPage',\n\t\tpublishDate: '2025-01-15',\n\t\tauthorName: 'Your Organization',\n\t\tauthorUrl: 'https://example.com'\n\t}}\n/\u003e\n```\n\nCreate reusable SEO configurations:\n\n```typescript\nimport { createSEOConfig } from 'svarog/seo';\n\n// In a shared config file\nexport const seoConfig = createSEOConfig({\n\tsiteName: 'Svarog',\n\tbaseUrl: 'https://example.com',\n\tdefaultImage: 'https://example.com/images/og.png'\n});\n\n// In a page component\nimport { seoConfig } from '$lib/config';\n\nconst pageSEO = seoConfig({\n\ttitle: 'Dashboard',\n\tdescription: 'View your application data'\n});\n```\n\n## API Reference\n\nThe package is organized into several modules:\n\n- **api**: Type-safe API response handling utilities\n- **cookies**: HTTP cookie management functions\n- **form**: Enhanced form handling for SvelteKit\n- **markdown**: Markdown parsing and processing tools\n- **time**: Date and time formatting functions\n- **token**: JWT authentication utilities\n- **turnstile**: Cloudflare Turnstile verification\n- **validation**: Form validation functions\n- **seo**: SEO metadata component for Svelte applications\n\nEach module is thoroughly documented with JSDoc comments. For detailed API reference, please refer to the source code or the generated documentation.\n\n### SEO Component Props\n\n| Prop          | Type     | Default                                       | Description                                 |\n| ------------- | -------- | --------------------------------------------- | ------------------------------------------- |\n| `title`       | `string` | `\"Svarog\"`                                    | Page title (displayed in browser tab)       |\n| `description` | `string` | `\"A customizable web application framework.\"` | Page description for search engines         |\n| `keywords`    | `string` | `\"web, application, framework, ...\"`          | Keywords for search engines                 |\n| `robots`      | `string` | `\"index, follow\"`                             | Robots directive for search engines         |\n| `canonical`   | `string` | `undefined`                                   | Canonical URL for the page                  |\n| `ogTitle`     | `string` | `title`                                       | Open Graph title (for social media sharing) |\n| `ogUrl`       | `string` | `\"https://example.com\"`                       | URL for the Open Graph object               |\n| `ogImage`     | `string` | `\"https://example.com/images/og.png\"`         | Image URL for social media shares           |\n| `twitterCard` | `string` | `\"summary_large_image\"`                       | Twitter card type                           |\n| `twitterSite` | `string` | `undefined`                                   | Twitter username (without @)                |\n| `og`          | `object` | `{}`                                          | Open Graph configuration object             |\n| `schema`      | `object` | `{}`                                          | Schema.org structured data configuration    |\n\n## TypeScript Support\n\nThis package is written in TypeScript and includes comprehensive type definitions for all exported functions and interfaces.\n\n## License\n\nMIT\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoxlovette%2Fsvarog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoxlovette%2Fsvarog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoxlovette%2Fsvarog/lists"}