Skip to content

Commit 08362a8

Browse files
committed
chore(release): update documentation
1 parent 8576749 commit 08362a8

2 files changed

Lines changed: 97 additions & 31 deletions

File tree

packages/kitsu-core/README.md

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

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

29-
#
29+
#
3030

3131
## Features
3232

@@ -97,19 +97,22 @@ kitsuCore.camel(...)
9797
- [serialise](#serialise)
9898
- [Parameters](#parameters-6)
9999
- [Examples](#examples-2)
100-
- [camel](#camel)
100+
- [splitModel](#splitmodel)
101101
- [Parameters](#parameters-7)
102102
- [Examples](#examples-3)
103-
- [kebab](#kebab)
103+
- [camel](#camel)
104104
- [Parameters](#parameters-8)
105105
- [Examples](#examples-4)
106-
- [snake](#snake)
106+
- [kebab](#kebab)
107107
- [Parameters](#parameters-9)
108108
- [Examples](#examples-5)
109+
- [snake](#snake)
110+
- [Parameters](#parameters-10)
111+
- [Examples](#examples-6)
109112

110113
### deattribute
111114

112-
[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")
115+
[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")
113116

114117
Hoists attributes to be top-level
115118

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

154157
### deserialise
155158

156-
[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")
159+
[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")
157160

158161
Deserialises a JSON-API response
159162

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

206209
### error
207210

208-
[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")
211+
[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")
209212

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

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

219222
### filterIncludes
220223

221-
[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")
224+
[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")
222225

223226
Filters includes for the specific relationship
224227

225228
#### Parameters
226229

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

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

234237
### linkRelationships
235238

236-
[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")
239+
[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")
237240

238241
Links relationships to included data
239242

240243
#### Parameters
241244

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

245248
### query
246249

247-
[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")
250+
[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")
248251

249252
Constructs a URL query string for JSON:API parameters
250253

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

258261
### serialise
259262

260-
[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")
263+
[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")
261264

262265
Serialises an object into a JSON-API structure
263266

264267
#### Parameters
265268

266269
- `model` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Request model
267270
- `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The data (optional, default `{}`)
268-
- `method` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Request type (optional, default `'POST'`)
271+
- `method` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Request type (PATCH, POST, DELETE) (optional, default `'POST'`)
272+
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional configuration for camelCase and pluralisation handling (optional, default `{}`)
273+
- `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
274+
- `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)
269275

270276
#### Examples
271277

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

274280

275281
```javascript
276-
import { serialise, camel, kebab } from 'kitsu-core'
277-
import plural from 'pluralize'
282+
import { serialise, camel } from 'kitsu-core'
283+
import pluralize from 'pluralize'
284+
285+
const model = 'anime'
286+
const obj = { id: '1', slug: 'shirobako' }
287+
288+
// { data: { id: '1', type: 'anime', attributes: { slug: 'shirobako' } } }
289+
const output = serialise(model, obj, 'PATCH', { camelCaseTypes: camel, pluralTypes: pluralize })
290+
```
291+
292+
Basic usage (no case conversion or pluralisation)
293+
294+
295+
```javascript
296+
import { serialise } from 'kitsu-core'
278297

279-
const output = serialise.apply({ camel, resCase: kebab, plural }, [ model, obj, 'PATCH' ])
298+
const model = 'anime'
299+
const obj = { id: '1', slug: 'shirobako' }
300+
301+
// { data: { id: '1', type: 'anime', attributes: { slug: 'shirobako' } } }
302+
const output = serialise(model, obj, 'PATCH')
280303
```
281304

282305
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The serialised data
283306

307+
### splitModel
308+
309+
[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")
310+
311+
Split model name from the model's resource URL
312+
313+
#### Parameters
314+
315+
- `url` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** URL path for the model
316+
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
317+
- `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
318+
- `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)
319+
320+
#### Examples
321+
322+
```javascript
323+
splitModel('posts/1/comments')
324+
// [ 'comments', 'posts/1/comments' ]
325+
```
326+
327+
With pluralModel option
328+
329+
330+
```javascript
331+
import plural from 'pluralize'
332+
splitModel('posts/1/comment', { pluralModel: plural })
333+
// [ 'comment', 'posts/1/comments' ]
334+
```
335+
336+
With resourceCase option
337+
338+
339+
```javascript
340+
import { kebab, snake } from 'kitsu-core'
341+
splitModel('libraryEntries', { resourceCase: kebab })
342+
// [ 'libraryEntries', 'library-entries' ]
343+
344+
splitModel('libraryEntries', { resourceCase: snake })
345+
// [ 'libraryEntries', 'library_entries' ]
346+
```
347+
348+
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
349+
284350
### camel
285351

286-
[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")
352+
[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")
287353

288354
Converts kebab-case and snake_case into camelCase
289355

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

312378
### kebab
313379

314-
[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")
380+
[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")
315381

316382
Converts camelCase into kebab-case
317383

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

330396
### snake
331397

332-
[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")
398+
[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")
333399

334400
Converts camelCase into snake_case
335401

packages/kitsu/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<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>
2828

29-
#
29+
#
3030

3131
## Features
3232

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

193193
### Kitsu
194194

195-
[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")
195+
[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")
196196

197197
Creates a new `kitsu` instance
198198

@@ -239,7 +239,7 @@ const api = new Kitsu({
239239

240240
#### plural
241241

242-
[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")
242+
[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")
243243

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

262262
#### headers
263263

264-
[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")
264+
[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")
265265

266266
Get the current headers or add additional headers
267267

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

293293
#### interceptors
294294

295-
[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")
295+
[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")
296296

297297
Axios Interceptors (alias of `axios.interceptors`)
298298

@@ -340,7 +340,7 @@ api.interceptors.request.eject(myInterceptor)
340340

341341
#### get
342342

343-
[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")
343+
[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")
344344

345345
Fetch resources (alias `fetch`)
346346

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

453453
#### patch
454454

455-
[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")
455+
[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")
456456

457457
Update a resource (alias `update`)
458458

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

479479
#### post
480480

481-
[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")
481+
[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")
482482

483483
Create a new resource (alias `create`)
484484

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

512512
#### delete
513513

514-
[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")
514+
[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")
515515

516516
Remove a resource (alias `remove`)
517517

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

535535
#### self
536536

537-
[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")
537+
[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")
538538

539539
Get the authenticated user's data
540540

0 commit comments

Comments
 (0)