Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
kitsu-core
Advanced tools
Core serialisation and deserialsation functions for the kitsu JSON:API client
Core JSON:API serialisation and deserialisation components
Migration guide for v9 and previous major releases
Package | Package Size* | Node | Chrome | Firefox | Safari | Edge |
---|---|---|---|---|---|---|
kitsu-core † | ≤ 1.4 kb | 10+ | 79+ | 68+ | 12.1+ | 18+ |
* Including all dependencies, minified & gzipped
† Changes in Node 12 and newer require the full path to be used if using ES Modules: kitsu-core/index.mjs
yarn add kitsu-core
npm install kitsu-core
import { camel } from 'kitsu-core' // ES Modules and Babel
const { camel } = require('kitsu-core') // CommonJS and Browserify
camel(...)
<!-- jsDelivr -->
<script src='https://cdn.jsdelivr.net/npm/kitsu-core'></script>
<!-- unpkg -->
<script src='https://unpkg.com/kitsu-core'></script>
kitsuCore.camel(...)
packages/kitsu-core/src/deattribute/index.js:29-51
Hoists attributes to be top-level
Deattribute an array of resources
// JSON:API 'data' field
const data = [
{
id: '1',
type: 'users',
attributes: { slug: 'wopian' }
}
]
const output = deattribute(data) // [ { id: '1', type: 'users', slug: 'wopian' } ]
Deattribute a resource
// JSON:API 'data' field
const data = {
id: '1',
type: 'users',
attributes: { slug: 'wopian' }
}
const output = deattribute(data) // { id: '1', type: 'users', slug: 'wopian' }
Returns (Object | Array) Deattributed resource data
packages/kitsu-core/src/deserialise/index.js:57-74
Deserialises a JSON-API response
obj
Object The responseDeserialise with a basic data object
deserialise({
data: {
id: '1',
attributes: { liked: true }
},
meta: { hello: 'world' }
}) // { data: { id: '1', liked: true }, meta: { hello: 'world' } }
Deserialise with relationships
deserialise({
data: {
id: '1',
relationships: {
user: {
data: {
type: 'users',
id: '2' }
}
}
},
included: [
{
type: 'users',
id: '2',
attributes: { slug: 'wopian' }
}
]
}) // { data: { id: '1', user: { type: 'users', id: '2', slug: 'wopian' } } }
Returns Object The deserialised response
packages/kitsu-core/src/error/index.js:7-13
Uniform error handling for Axios, JSON:API and internal package errors. Mutated Error object is rethrown to the caller.
packages/kitsu-core/src/filterIncludes/index.js:12-25
Filters includes for the specific relationship
Returns Array The matched includes
packages/kitsu-core/src/linkRelationships/index.js:75-96
Links relationships to included data
data
Object The response data objectincluded
Object The response included object (optional, default []
)packages/kitsu-core/src/query/index.js:21-32
Constructs a URL query string for JSON:API parameters
params
Object Parameters to parseprefix
string Prefix for nested parameters - used internally (default null
) (optional, default null
)Returns string URL query string
packages/kitsu-core/src/serialise/index.js:119-152
Serialises an object into a JSON-API structure
model
string Request modelobj
Object The data (optional, default {}
)method
string Request type (PATCH, POST, DELETE) (optional, default 'POST'
)options
Object Optional configuration for camelCase and pluralisation handling (optional, default {}
)
options.camelCaseTypes
Function Convert library-entries and library_entries to libraryEntries (default no conversion). To use parameter, import camel from kitsu-coreoptions.pluralTypes
Function Pluralise types (default no pluralisation). To use parameter, import pluralize (or another pluralisation npm package)Setting camelCaseTypes and pluralTypes options (example shows options used by kitsu
by default)
import { serialise, camel } from 'kitsu-core'
import pluralize from 'pluralize'
const model = 'anime'
const obj = { id: '1', slug: 'shirobako' }
// { data: { id: '1', type: 'anime', attributes: { slug: 'shirobako' } } }
const output = serialise(model, obj, 'PATCH', { camelCaseTypes: camel, pluralTypes: pluralize })
Basic usage (no case conversion or pluralisation)
import { serialise } from 'kitsu-core'
const model = 'anime'
const obj = { id: '1', slug: 'shirobako' }
// { data: { id: '1', type: 'anime', attributes: { slug: 'shirobako' } } }
const output = serialise(model, obj, 'PATCH')
Returns Object The serialised data
packages/kitsu-core/src/splitModel/index.js:29-39
Split model name from the model's resource URL
url
string URL path for the modeloptions
Object
options.resourceCase
Function Convert libraryEntries to library-entries or library_entries (default no conversion). To use parameter, import kebab or snake from kitsu-coreoptions.pluralModel
Function Pluralise models (default no pluralisation). To use parameter, import pluralize (or another pluralisation npm package)splitModel('posts/1/comments')
// [ 'comments', 'posts/1/comments' ]
With pluralModel option
import plural from 'pluralize'
splitModel('posts/1/comment', { pluralModel: plural })
// [ 'comment', 'posts/1/comments' ]
With resourceCase option
import { kebab, snake } from 'kitsu-core'
splitModel('libraryEntries', { resourceCase: kebab })
// [ 'libraryEntries', 'library-entries' ]
splitModel('libraryEntries', { resourceCase: snake })
// [ 'libraryEntries', 'library_entries' ]
Returns Array Array containing the model name and the resource URL with pluralisation applied
packages/kitsu-core/src/camel/index.js:14-14
Converts kebab-case and snake_case into camelCase
s
string String to convertConvert kebab-case
camel('hello-world') // 'helloWorld'
Convert snake_case
camel('hello_world') // 'helloWorld'
Returns string camelCase formatted string
packages/kitsu-core/src/kebab/index.js:11-11
Converts camelCase into kebab-case
s
string camelCase stringkebab('helloWorld') // 'hello-world'
Returns string kebab-case formatted string
packages/kitsu-core/src/snake/index.js:11-11
Converts camelCase into snake_case
s
string camelCase stringsnake('helloWorld') // 'hello_world'
Returns string snake_case formatted string
See CONTRIBUTING
See CHANGELOG
All code released under MIT
FAQs
Simple, lightweight & framework agnostic JSON:API (de)serialsation components
The npm package kitsu-core receives a total of 6,250 weekly downloads. As such, kitsu-core popularity was classified as popular.
We found that kitsu-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.