UNPKG

@small-web/kitten

Version:

Type-safe global Kitten namespace.

71 lines (44 loc) 2.87 kB
# Type-safe Kitten globals Adds type safety to global `kitten` object in [Kitten](https://kitten.small-web.org). ## Install ```shell npm install @small-web/kitten ``` ## Use [Kitten](https://kitten.small-web.org) has a global `kitten` namespace that makes it easy to get started building Small Web sites and apps with it. If you’re building something quick, that might be all you need. e.g., In a quick Hello World example, your _index.page.js_ might look like this: ```js export default () => kitten.html` <h1>Hello, world!</h1> ` ``` While that works, if you use [JSDoc](https://jsdoc.app/) to implement type checking for your larger projects, and you use an editor with language intelligence (like [Helix](https://helix-editor.com)) and have static type checking turned on (e.g., as shown below or in a [jsconfig.json](https://code.visualstudio.com/docs/languages/jsconfig) file) you will get a “Cannot find name ‘kitten’” error. ```js // @ts-check export default () => kitten.html` ← Cannot find name 'kitten' <h1>Hello, world!</h1> ` ``` To fix that, simply install the module and import the default export and it will behave exactly like the default global `kitten` namespace but with type safety and language intelligence while authoring. ```js // @ts-check import kitten from '@small-web/kitten' export default () => kitten.html` <h1>Hello, world!</h1> ` ``` > 💡 You can also import specific exports from the package, e.g., `import { html } from '@small-web/kitten'`. > 🔗 For more help in using this module, please see the [Kitten Type Safety Tutorial](https://kitten.small-web.org/tutorials/type-safety/). ## Database type safety Kitten by default has at least two [databases](https://kitten.small-web.org/reference/#database) per project: An internal database called `_db` and a custom one for you to use in your project called `db`. This package provides a type-safe `_db` export for the internal database as the structure is well known. If you want type safety for your custom project database, please create and use a type-safe database app module. > 🔗 For a more in-depth look into database type safety, please see the [Database App Modules Kitten Tutorial](https://kitten.small-web.org/tutorials/database-app-modules/). ## Like this? Fund us! [Small Technology Foundation](https://small-tech.org) is a tiny, independent not-for-profit. We exist in part thanks to patronage by people like you. If you share [our vision](https://small-tech.org/about/#small-technology) and want to support our work, please [become a patron or donate to us](https://small-tech.org/fund-us) today and help us continue to exist. ## License Copyright © 2023-present [Aral Balkan](https://ar.al), [Small Technology Foundation](https://small-tech.org) Released under [AGPL 3.0](https://www.gnu.org/licenses/agpl-3.0.en.html).