Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
deserialise
✓ import { deserialise } from 'kitsu-core';
✗ const deserialise = require('kitsu-core').deserialise;
Prefer ES Module imports in modern Node.js and browser environments; CommonJS requires named property access. The library is optimized for ESM.
serialise
✓ import { serialise } from 'kitsu-core';
✗ import serialise from 'kitsu-core';
All primary functions and utilities are named exports. There is no default export from 'kitsu-core'.
camel
✓ import { camel } from 'kitsu-core';
✗ import * as kitsuCore from 'kitsu-core'; kitsuCore.camel(...);
Directly import specific utility functions like `camel` for optimal tree-shaking and bundle size.
JsonApiDocument
✓ import type { JsonApiDocument } from 'kitsu-core';
✗ import { JsonApiDocument } from 'kitsu-core';
For TypeScript, use `import type` for type-only imports to improve clarity and potential bundler optimizations, especially since v10.1.4 improved fine-grained type exports.
This code snippet demonstrates how to use `kitsu-core` to deserialize a JSON:API response into a plain JavaScript object, apply camel-casing to keys, serialize an object back into JSON:API format, and utilize the opt-in data hoisting feature for relationships.
import { deserialise, serialise, camel } from 'kitsu-core';
// Example JSON:API response structure
const jsonApiResponse = {
data: {
type: 'articles',
id: '1',
attributes: {
'title-post': 'JSON:API is great!',
'content-body': 'This is some content.'
},
relationships: {
author: {
data: { type: 'users', id: '9' }
},
comments: {
data: [
{ type: 'comments', id: '5' },
{ type: 'comments', id: '12' }
]
}
}
},
included: [
{
type: 'users',
id: '9',
attributes: {
'full-name': 'John Doe'
}
},
{
type: 'comments',
id: '5',
attributes: {
body: 'First comment'
}
},
{
type: 'comments',
id: '12',
attributes: {
body: 'Second comment'
},
relationships: {
author: {
data: { type: 'users', id: '9' }
}
}
}
]
};
async function runKitsuCoreExample() {
console.log('Original JSON:API Response:', JSON.stringify(jsonApiResponse, null, 2));
// Deserialise the JSON:API response into a plain JavaScript object, applying camelCaseKeys
const deserializedData = await deserialise(jsonApiResponse, { camelCaseKeys: true });
console.log('\nDeserialized Data (camelCaseKeys: true):', JSON.stringify(deserializedData, null, 2));
// Example of using the standalone camel utility
const camelCasedKey = camel('my-kebab-case-key');
console.log('\nCamel cased key:', camelCasedKey); // myKebabCaseKey
// Prepare data for serialization (e.g., after modifying it)
const articleToSerialize = {
id: '1',
type: 'articles',
titlePost: 'Updated Title',
contentBody: 'New content here.',
author: {
id: '9',
type: 'users'
},
comments: [
{ id: '5', type: 'comments' },
{ id: '12', type: 'comments' }
]
};
// Serialize a plain JavaScript object back into JSON:API format
const serializedData = await serialise(articleToSerialize, 'articles', { camelCaseKeys: true });
console.log('\nSerialized Data (camelCaseKeys: true):', JSON.stringify(serializedData, null, 2));
// Demonstrate data hoisting (introduced in v11.1.0)
const hoistedData = await deserialise(jsonApiResponse, {
camelCaseKeys: true,
hoist: ['author'] // Hoist the 'author' relationship directly onto the article object
});
console.log('\nDeserialized Data with Author Hoisted (opt-in since v11.1.0):', JSON.stringify(hoistedData, null, 2));
}
runKitsuCoreExample();
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use CommonJS `require()` syntax in an ES Module (ESM) context (e.g., in a file with `.mjs` extension or when `"type": "module"` is set in `package.json`).
fixChange `const { symbol } = require('kitsu-core');` to `import { symbol } from 'kitsu-core';`. Ensure your project's module configuration in `package.json` and `tsconfig.json` (if applicable) aligns with your chosen module system. TS2307: Cannot find module 'kitsu-core' or its corresponding type declarations.
TypeScript compiler cannot locate the type definitions for `kitsu-core`, or there's a mismatch in module resolution settings between `tsconfig.json` and the installed package version. This can be exacerbated by changes in v10.1.4 regarding fine-grained type exports.
fixEnsure `kitsu-core` is correctly installed. Verify `tsconfig.json` includes `"compilerOptions": { "moduleResolution": "Node16", "module": "Node16", "allowSyntheticDefaultImports": true }` or `"Bundler"` for modern setups. Consider updating TypeScript and `kitsu-core` to their latest versions. Deserialized data does not have expected relationships linked, or relationships are present but not resolved to full objects.
The input JSON:API response is malformed, missing required `included` data, or does not strictly adhere to the JSON:API 1.0 specification for relationships and compound documents.
fixCarefully inspect your JSON:API response to ensure it includes all related resources in the `included` array and that `relationships.data` objects correctly reference these resources by `type` and `id`.
Audit
Dependencies
No dependency data recorded yet.