Skip to content

Commit

Permalink
chore(release): update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
wopian committed May 7, 2020
1 parent 8576749 commit 08362a8
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 31 deletions.
108 changes: 87 additions & 21 deletions packages/kitsu-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<p align=center>Core <a href=http://jsonapi.org>JSON:API</a> serialisation and deserialisation components</p>

#
#

## Features

Expand Down Expand Up @@ -97,19 +97,22 @@ kitsuCore.camel(...)
- [serialise](#serialise)
- [Parameters](#parameters-6)
- [Examples](#examples-2)
- [camel](#camel)
- [splitModel](#splitmodel)
- [Parameters](#parameters-7)
- [Examples](#examples-3)
- [kebab](#kebab)
- [camel](#camel)
- [Parameters](#parameters-8)
- [Examples](#examples-4)
- [snake](#snake)
- [kebab](#kebab)
- [Parameters](#parameters-9)
- [Examples](#examples-5)
- [snake](#snake)
- [Parameters](#parameters-10)
- [Examples](#examples-6)

### deattribute

[packages/kitsu-core/src/deattribute/index.js:29-38](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu-core/src/deattribute/index.js#L29-L38 "Source code on GitHub")
[packages/kitsu-core/src/deattribute/index.js:29-38](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu-core/src/deattribute/index.js#L29-L38 "Source code on GitHub")

Hoists attributes to be top-level

Expand Down Expand Up @@ -153,7 +156,7 @@ Returns **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/

### deserialise

[packages/kitsu-core/src/deserialise/index.js:56-72](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu-core/src/deserialise/index.js#L56-L72 "Source code on GitHub")
[packages/kitsu-core/src/deserialise/index.js:57-74](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu-core/src/deserialise/index.js#L57-L74 "Source code on GitHub")

Deserialises a JSON-API response

Expand Down Expand Up @@ -205,7 +208,7 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G

### error

[packages/kitsu-core/src/error/index.js:7-13](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu-core/src/error/index.js#L7-L13 "Source code on GitHub")
[packages/kitsu-core/src/error/index.js:7-13](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu-core/src/error/index.js#L7-L13 "Source code on GitHub")

Uniform error handling for Axios, JSON:API and internal package errors. Mutated Error object is rethrown to the caller.

Expand All @@ -218,33 +221,33 @@ Uniform error handling for Axios, JSON:API and internal package errors. Mutated

### filterIncludes

[packages/kitsu-core/src/filterIncludes/index.js:12-25](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu-core/src/filterIncludes/index.js#L12-L25 "Source code on GitHub")
[packages/kitsu-core/src/filterIncludes/index.js:12-25](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu-core/src/filterIncludes/index.js#L12-L25 "Source code on GitHub")

Filters includes for the specific relationship

#### Parameters

- `included` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The response included object
- `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `opts.id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The relationship ID
- `opts.type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The relationship type

Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** The matched includes

### linkRelationships

[packages/kitsu-core/src/linkRelationships/index.js:55-74](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu-core/src/linkRelationships/index.js#L55-L74 "Source code on GitHub")
[packages/kitsu-core/src/linkRelationships/index.js:75-96](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu-core/src/linkRelationships/index.js#L75-L96 "Source code on GitHub")

Links relationships to included data

#### Parameters

- `data` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The response data object
- `included` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The response included object
- `included` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The response included object (optional, default `[]`)

### query

[packages/kitsu-core/src/query/index.js:21-32](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu-core/src/query/index.js#L21-L32 "Source code on GitHub")
[packages/kitsu-core/src/query/index.js:21-32](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu-core/src/query/index.js#L21-L32 "Source code on GitHub")

Constructs a URL query string for JSON:API parameters

Expand All @@ -257,33 +260,96 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G

### serialise

[packages/kitsu-core/src/serialise/index.js:103-134](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu-core/src/serialise/index.js#L103-L134 "Source code on GitHub")
[packages/kitsu-core/src/serialise/index.js:119-152](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu-core/src/serialise/index.js#L119-L152 "Source code on GitHub")

Serialises an object into a JSON-API structure

#### Parameters

- `model` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Request model
- `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The data (optional, default `{}`)
- `method` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Request type (optional, default `'POST'`)
- `method` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Request type (PATCH, POST, DELETE) (optional, default `'POST'`)
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional configuration for camelCase and pluralisation handling (optional, default `{}`)
- `options.camelCaseTypes` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Convert library-entries and library_entries to libraryEntries (default no conversion). To use parameter, import camel from kitsu-core
- `options.pluralTypes` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Pluralise types (default no pluralisation). To use parameter, import pluralize (or another pluralisation npm package)

#### Examples

Due to its usage in kitsu, it **MUST** be called with **this** set in 6.0.x
Setting camelCaseTypes and pluralTypes options (example shows options used by `kitsu` by default)


```javascript
import { serialise, camel, kebab } from 'kitsu-core'
import plural from 'pluralize'
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)


```javascript
import { serialise } from 'kitsu-core'

const output = serialise.apply({ camel, resCase: kebab, plural }, [ model, obj, 'PATCH' ])
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](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The serialised data

### splitModel

[packages/kitsu-core/src/splitModel/index.js:29-39](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu-core/src/splitModel/index.js#L29-L39 "Source code on GitHub")

Split model name from the model's resource URL

#### Parameters

- `url` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** URL path for the model
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `options.resourceCase` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Convert libraryEntries to library-entries or library_entries (default no conversion). To use parameter, import kebab or snake from kitsu-core
- `options.pluralModel` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Pluralise models (default no pluralisation). To use parameter, import pluralize (or another pluralisation npm package)

#### Examples

```javascript
splitModel('posts/1/comments')
// [ 'comments', 'posts/1/comments' ]
```

With pluralModel option


```javascript
import plural from 'pluralize'
splitModel('posts/1/comment', { pluralModel: plural })
// [ 'comment', 'posts/1/comments' ]
```

With resourceCase option


```javascript
import { kebab, snake } from 'kitsu-core'
splitModel('libraryEntries', { resourceCase: kebab })
// [ 'libraryEntries', 'library-entries' ]

splitModel('libraryEntries', { resourceCase: snake })
// [ 'libraryEntries', 'library_entries' ]
```

Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array containing the model name and the resource URL with pluralisation applied

### camel

[packages/kitsu-core/src/camel/index.js:14-14](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu-core/src/camel/index.js#L14-L14 "Source code on GitHub")
[packages/kitsu-core/src/camel/index.js:14-14](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu-core/src/camel/index.js#L14-L14 "Source code on GitHub")

Converts kebab-case and snake_case into camelCase

Expand Down Expand Up @@ -311,7 +377,7 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G

### kebab

[packages/kitsu-core/src/kebab/index.js:11-11](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu-core/src/kebab/index.js#L11-L11 "Source code on GitHub")
[packages/kitsu-core/src/kebab/index.js:11-11](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu-core/src/kebab/index.js#L11-L11 "Source code on GitHub")

Converts camelCase into kebab-case

Expand All @@ -329,7 +395,7 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G

### snake

[packages/kitsu-core/src/snake/index.js:11-11](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu-core/src/snake/index.js#L11-L11 "Source code on GitHub")
[packages/kitsu-core/src/snake/index.js:11-11](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu-core/src/snake/index.js#L11-L11 "Source code on GitHub")

Converts camelCase into snake_case

Expand Down
20 changes: 10 additions & 10 deletions packages/kitsu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<p align=center>A simple, lightweight & framework agnostic <a href=http://jsonapi.org>JSON:API</a> client for <a href=https://kitsu.io>Kitsu.io</a> and other APIs</p>

#
#

## Features

Expand Down Expand Up @@ -192,7 +192,7 @@ If you're working with [Kitsu.io]'s API, their [API docs][kitsu.io api docs] lis

### Kitsu

[packages/kitsu/src/index.js:30-324](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu/src/index.js#L30-L324 "Source code on GitHub")
[packages/kitsu/src/index.js:30-342](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu/src/index.js#L30-L342 "Source code on GitHub")

Creates a new `kitsu` instance

Expand Down Expand Up @@ -239,7 +239,7 @@ const api = new Kitsu({

#### plural

[packages/kitsu/src/index.js:52-53](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu/src/index.js#L52-L53 "Source code on GitHub")
[packages/kitsu/src/index.js:52-53](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu/src/index.js#L52-L53 "Source code on GitHub")

- **See: <https://www.npmjs.com/package/pluralize> for documentation
**
Expand All @@ -261,7 +261,7 @@ api.plural.plural('paper') //=> 'paper'

#### headers

[packages/kitsu/src/index.js:67-67](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu/src/index.js#L67-L67 "Source code on GitHub")
[packages/kitsu/src/index.js:67-67](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu/src/index.js#L67-L67 "Source code on GitHub")

Get the current headers or add additional headers

Expand Down Expand Up @@ -292,7 +292,7 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G

#### interceptors

[packages/kitsu/src/index.js:111-111](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu/src/index.js#L111-L111 "Source code on GitHub")
[packages/kitsu/src/index.js:111-111](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu/src/index.js#L111-L111 "Source code on GitHub")

Axios Interceptors (alias of `axios.interceptors`)

Expand Down Expand Up @@ -340,7 +340,7 @@ api.interceptors.request.eject(myInterceptor)

#### get

[packages/kitsu/src/index.js:184-203](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu/src/index.js#L184-L203 "Source code on GitHub")
[packages/kitsu/src/index.js:184-203](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu/src/index.js#L184-L203 "Source code on GitHub")

Fetch resources (alias `fetch`)

Expand Down Expand Up @@ -452,7 +452,7 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G

#### patch

[packages/kitsu/src/index.js:219-233](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu/src/index.js#L219-L233 "Source code on GitHub")
[packages/kitsu/src/index.js:219-239](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu/src/index.js#L219-L239 "Source code on GitHub")

Update a resource (alias `update`)

Expand All @@ -478,7 +478,7 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G

#### post

[packages/kitsu/src/index.js:256-269](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu/src/index.js#L256-L269 "Source code on GitHub")
[packages/kitsu/src/index.js:262-281](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu/src/index.js#L262-L281 "Source code on GitHub")

Create a new resource (alias `create`)

Expand Down Expand Up @@ -511,7 +511,7 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G

#### delete

[packages/kitsu/src/index.js:282-294](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu/src/index.js#L282-L294 "Source code on GitHub")
[packages/kitsu/src/index.js:294-312](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu/src/index.js#L294-L312 "Source code on GitHub")

Remove a resource (alias `remove`)

Expand All @@ -534,7 +534,7 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G

#### self

[packages/kitsu/src/index.js:316-323](https://github.com/wopian/kitsu/blob/72acbe7a81cc60718cbaaa4cc99c6b0dcf8b58de/packages/kitsu/src/index.js#L316-L323 "Source code on GitHub")
[packages/kitsu/src/index.js:334-341](https://github.com/wopian/kitsu/blob/8576749f2211c86ac5fcbada6328efdf023c8eb4/packages/kitsu/src/index.js#L334-L341 "Source code on GitHub")

Get the authenticated user's data

Expand Down

0 comments on commit 08362a8

Please sign in to comment.