Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kitsu-core

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kitsu-core

Core serialisation and deserialsation functions for the kitsu JSON:API client

  • 8.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.8K
decreased by-24.14%
Maintainers
1
Weekly downloads
 
Created
Source

Kitsu Core

npm npm bundlephobia deps

travis packagephobia contributors

coverage maintainability technical debt issues

support me on paypal.me

Core JSON:API serialisation and deserialisation components

Features

  • JSON-API 1.0 compliant
  • Automatically links relationships to data
  • Works in Node and on the web

Node / Browser Support

PackagePackage
Size*
NodeChromeFirefoxSafariEdge
kitsu-core≤ 1.2 kb10+65+65+11.1+17+

* 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

Install

Yarn / NPM

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(...)

CDNs

<!-- jsDelivr -->
<script src='https://cdn.jsdelivr.net/npm/kitsu-core'></script>

<!-- unpkg -->
<script src='https://unpkg.com/kitsu-core'></script>
kitsuCore.camel(...)

API

Table of Contents

deattribute

packages/kitsu-core/src/deattribute/index.js:29-38

Hoists attributes to be top-level

Parameters
Examples

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

deserialise

packages/kitsu-core/src/deserialise/index.js:56-72

Deserialises a JSON-API response

Parameters
Examples

Deserialise 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

error

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.

Parameters

filterIncludes

packages/kitsu-core/src/filterIncludes/index.js:12-21

Filters includes for the specific relationship

Parameters
  • included Object The response included object
  • opts Object
    • opts.id string The relationship ID
    • opts.type string The relationship type

Returns Array The matched includes

linkRelationships

packages/kitsu-core/src/linkRelationships/index.js:55-74

Links relationships to included data

Parameters
  • data Object The response data object
  • included Object The response included object

query

packages/kitsu-core/src/query/index.js:21-32

Constructs a URL query string for JSON:API parameters

Parameters
  • params Object Parameters to parse
  • prefix string Prefix for nested parameters - used internally (default null) (optional, default null)

Returns string URL query string

serialise

packages/kitsu-core/src/serialise/index.js:96-121

Serialises an object into a JSON-API structure

Parameters
  • model string Request model
  • obj Object The data (optional, default {})
  • method string Request type (optional, default 'POST')
Examples

Due to its usage in kitsu, it MUST be called with this set in 6.0.x

import { serialise, camel, kebab } from 'kitsu-core'
import plural from 'pluralize'

const output = serialise.apply({ camel, resCase: kebab, plural }, [ model, obj, 'PATCH' ])

Returns Object The serialised data

camel

packages/kitsu-core/src/camel/index.js:14-14

Converts kebab-case and snake_case into camelCase

Parameters
Examples

Convert kebab-case

camel('hello-world') // 'helloWorld'

Convert snake_case

camel('hello_world') // 'helloWorld'

Returns string camelCase formatted string

kebab

packages/kitsu-core/src/kebab/index.js:11-11

Converts camelCase into kebab-case

Parameters
Examples
kebab('helloWorld') // 'hello-world'

Returns string kebab-case formatted string

snake

packages/kitsu-core/src/snake/index.js:11-11

Converts camelCase into snake_case

Parameters
Examples
snake('helloWorld') // 'hello_world'

Returns string snake_case formatted string

Contributing

See CONTRIBUTING

Releases

See CHANGELOG

License

All code released under MIT

Keywords

FAQs

Package last updated on 26 Apr 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc