Skip to content

Commit 1accdbb

Browse files
committed
refactor(kitsu-core): change camel, kebab and snake to named exports
Unifies all exports to the same syntax (previously these were the only default exported functions)
1 parent ddcbe09 commit 1accdbb

9 files changed

Lines changed: 41 additions & 24 deletions

File tree

packages/kitsu-core/MIGRATING.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22

33
## Migrating to `10.0.0`
44

5-
### Serialising
6-
7-
`serialise` has been refactored to match the v9 `deserialise` behaviour. This was intended for the v9 release, however it slipped though the net and resulted in broken relationship serialisation in v9.
8-
9-
Relationships given to the `serialise` function are now always an object containing either a `data` object or a `data` array. This allows for optional top-level relationship `links` and `meta` objects to be serialised into the JSON:API format.
10-
11-
Exemptions:
12-
- `links` that are not objects or do not contain `self` or `related` will become attributes as normal
13-
- `meta` that are not objects will become attributes as normal
14-
155
### Exports
166

177
The compiled output of `kitsu-core` has been changed from `lib` to `dist`.
@@ -29,6 +19,31 @@ import { serialise } from 'kitsu-core/serialise' // Node 12+
2919
import { serialise } from 'kitsu-core/dist/serialise'
3020
```
3121

22+
### `camel`, `kebab`` and `snake`
23+
24+
These exports are now named exports instead of default exports.
25+
26+
```js
27+
// Legacy behaviour, any of:
28+
import { camel } from 'kitsu-core'
29+
import camel from 'kitsu-core/lib/camel'
30+
31+
// New behaviour, any of:
32+
import { camel } from 'kitsu-core'
33+
import { camel } from 'kitsu-core/camel'
34+
import { camel } from 'kitsu-core/dist/camel'
35+
```
36+
37+
### Serialising
38+
39+
`serialise` has been refactored to match the v9 `deserialise` behaviour. This was intended for the v9 release, however it slipped though the net and resulted in broken relationship serialisation in v9.
40+
41+
Relationships given to the `serialise` function are now always an object containing either a `data` object or a `data` array. This allows for optional top-level relationship `links` and `meta` objects to be serialised into the JSON:API format.
42+
43+
Exemptions:
44+
- `links` that are not objects or do not contain `self` or `related` will become attributes as normal
45+
- `meta` that are not objects will become attributes as normal
46+
3247
#### Legacy Input
3348

3449
```js

packages/kitsu-core/rollup.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export default [
5454
linkRelationships: 'src/linkRelationships/index.js',
5555
query: 'src/query/index.js',
5656
serialise: 'src/serialise/index.js',
57-
snake: 'src/snake/index.js'
57+
snake: 'src/snake/index.js',
58+
splitModel: 'src/splitModel/index.js'
5859
},
5960
external,
6061
plugins: pluginsMain,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
* @example <caption>Convert snake_case</caption>
1212
* camel('hello_world') // 'helloWorld'
1313
*/
14-
export default input => input.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g, match => match.slice(1).toUpperCase())
14+
export const camel = input => input.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g, match => match.slice(1).toUpperCase())

packages/kitsu-core/src/camel/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import camel from './'
1+
import { camel } from './'
22

33
describe('kitsu-core', () => {
44
describe('camel', () => {

packages/kitsu-core/src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
2+
export * from './camel'
13
export * from './deattribute'
24
export * from './deserialise'
35
export * from './error'
46
export * from './filterIncludes'
7+
export * from './kebab'
58
export * from './linkRelationships'
69
export * from './query'
710
export * from './serialise'
11+
export * from './snake'
812
export * from './splitModel'
9-
export { default as camel } from './camel'
10-
export { default as kebab } from './kebab'
11-
export { default as snake } from './snake'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
* @example
99
* kebab('helloWorld') // 'hello-world'
1010
*/
11-
export default input => input.charAt(0).toLowerCase() + input.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, match => '-' + match.toLowerCase())
11+
export const kebab = input => input.charAt(0).toLowerCase() + input.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, match => '-' + match.toLowerCase())

packages/kitsu-core/src/kebab/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import kebab from './'
1+
import { kebab } from './'
22

33
describe('kitsu-core', () => {
44
describe('kebab', () => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
* @example
99
* snake('helloWorld') // 'hello_world'
1010
*/
11-
export default input => input.charAt(0).toLowerCase() + input.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, match => '_' + match.toLowerCase())
11+
export const snake = input => input.charAt(0).toLowerCase() + input.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, match => '_' + match.toLowerCase())
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import kebab from './'
1+
import { snake } from './'
22

33
describe('kitsu-core', () => {
4-
describe('kebab', () => {
4+
describe('snake', () => {
55
it('snake_cases a camelCase string', () => {
66
expect.assertions(1)
7-
expect(kebab('helloWorld')).toBe('hello_world')
7+
expect(snake('helloWorld')).toBe('hello_world')
88
})
99

1010
it('snake_cases a CamelCase string', () => {
1111
expect.assertions(1)
12-
expect(kebab('HelloWorld')).toBe('hello_world')
12+
expect(snake('HelloWorld')).toBe('hello_world')
1313
})
1414

1515
it('snake_cases a snake_case string', () => {
1616
expect.assertions(1)
17-
expect(kebab('hello-world')).toBe('hello-world')
17+
expect(snake('hello-world')).toBe('hello-world')
1818
})
1919
})
2020
})

0 commit comments

Comments
 (0)