Skip to content

Commit 2c50a45

Browse files
committed
Add Prettier
1 parent 4cb3441 commit 2c50a45

14 files changed

+294
-204
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{html,less,css,yml}]
15+
indent_size = 2

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
package-lock.json
3+
CHANGELOG.md

README.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@ models.sync({
2222
id: '1',
2323
attributes: { name: 'Toby' },
2424
relationships: {
25-
dog: { data: { type: 'dogs', id: '1' }}
26-
}
25+
dog: { data: { type: 'dogs', id: '1' } },
26+
},
2727
},
28-
included: [{
29-
type: 'dogs',
30-
id: '1',
31-
attributes: { name: 'Rosie' }
32-
}]
28+
included: [
29+
{
30+
type: 'dogs',
31+
id: '1',
32+
attributes: { name: 'Rosie' },
33+
},
34+
],
3335
});
3436

3537
// Resource data is transformed into easy-to-consume models
3638
const human = models.find('humans', '1');
37-
human.name // Toby
38-
human.dog // { type: 'dogs', id: '1', name: 'Rosie' }
39+
human.name; // Toby
40+
human.dog; // { type: 'dogs', id: '1', name: 'Rosie' }
3941
```
4042

4143
### Syncing JSON:API Data
@@ -54,7 +56,7 @@ You can also sync an individual resource using the `syncResource` method:
5456
const model = models.syncResource({
5557
type: 'users',
5658
id: '1',
57-
attributes: { name: 'Toby' }
59+
attributes: { name: 'Toby' },
5860
});
5961
```
6062

@@ -67,7 +69,7 @@ const model = models.find('users', '1');
6769
const model = models.find({ type: 'users', id: '1' });
6870
const models = models.find([
6971
{ type: 'users', id: '1' },
70-
{ type: 'users', id: '2' }
72+
{ type: 'users', id: '2' },
7173
]);
7274
```
7375

@@ -79,19 +81,19 @@ const models = models.findAll('users');
7981

8082
### Working with Models
8183

82-
Models are a *superset* of JSON:API resource objects, meaning they contain all of the members you would expect (`type`, `id`, `attributes`, `relationships`, `meta`, `links`) plus some additional functionality.
84+
Models are a _superset_ of JSON:API resource objects, meaning they contain all of the members you would expect (`type`, `id`, `attributes`, `relationships`, `meta`, `links`) plus some additional functionality.
8385

8486
Getters are automatically defined for all fields, allowing you to easily access their contents. Relationship fields are automatically resolved to their related models (if present within the store):
8587

8688
```ts
87-
model.name // => model.attributes.name
88-
model.dog // => models.find(model.relationships.dog.data)
89+
model.name; // => model.attributes.name
90+
model.dog; // => models.find(model.relationships.dog.data)
8991
```
9092

9193
To easily retrieve a resource identifier object for the model, the `identifier` method is available. This is useful when constructing relationships in JSON:API request documents.
9294

9395
```ts
94-
model.identifier() // { type: 'users', id: '1' }
96+
model.identifier(); // { type: 'users', id: '1' }
9597
```
9698

9799
### Forgetting Models
@@ -112,7 +114,7 @@ import { Model } from 'json-api-models';
112114
class User extends Model<'users'> {
113115
public declare name: string;
114116
public declare age: number;
115-
117+
116118
get firstName() {
117119
return this.name.split(' ')[0];
118120
}
@@ -133,9 +135,9 @@ You can define typecasts for attributes on your custom models:
133135

134136
```ts
135137
class User extends Model<'users'> {
136-
declare public name: string;
137-
declare public createdAt: Date;
138-
138+
public declare name: string;
139+
public declare createdAt: Date;
140+
139141
protected casts = {
140142
createdAt: Date,
141143
};
@@ -158,16 +160,17 @@ function api(url, options = {}) {
158160
options.headers['Content-Type'] = 'application/vnd.api+json';
159161
}
160162

161-
return fetch('http://example.org/api/' + url, options)
162-
.then(async response => {
163-
if (response.status === 204) {
163+
return fetch('http://example.org/api/' + url, options).then(
164+
async (response) => {
165+
if (response.status === 204) {
164166
return { response };
165167
} else {
166168
const document = await response.json();
167169
const data = models.sync(document);
168170
return { response, document, data };
169171
}
170-
});
172+
}
173+
);
171174
}
172175

173176
api('users/1').then(({ data }) => {
@@ -185,9 +188,9 @@ api(user.links.self, {
185188
body: {
186189
data: {
187190
...user.identifier(),
188-
attributes: { name: 'Changed' }
189-
}
190-
}
191+
attributes: { name: 'Changed' },
192+
},
193+
},
191194
});
192195
```
193196

@@ -199,7 +202,7 @@ Building query strings for your JSON:API requests can be tedious, and sometimes
199202
import { Query } from 'json-api-models';
200203

201204
const query = new Query({
202-
'include': 'foo',
205+
include: 'foo',
203206
'fields[users]': 'name',
204207
});
205208

jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
preset: 'ts-jest',
3-
testEnvironment: 'node',
4-
};
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
};

package.json

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,54 @@
11
{
2-
"name": "json-api-models",
3-
"description": "A lightweight layer for working with JSON:API data.",
4-
"version": "0.1.0-beta.8",
5-
"author": "Toby Zerner",
6-
"license": "MIT",
7-
"main": "./dist/index.cjs.js",
8-
"module": "./dist/index.es.js",
9-
"unpkg": "./dist/index.js",
10-
"types": "./dist/index.d.ts",
11-
"files": [
12-
"src",
13-
"dist",
14-
"README.md",
15-
"!**/.DS_Store"
16-
],
17-
"scripts": {
18-
"test": "jest",
19-
"build": "rollup -c",
20-
"build:watch": "rollup -cw",
21-
"release": "release-it --npm.tag=latest"
22-
},
23-
"devDependencies": {
24-
"@release-it/keep-a-changelog": "^2.3.0",
25-
"@rollup/plugin-typescript": "^8.2.5",
26-
"@types/jest": "^26.0.20",
27-
"jest": "^26.6.3",
28-
"release-it": "^14.11.5",
29-
"rollup": "^2.56.3",
30-
"rollup-plugin-terser": "^7.0.2",
31-
"ts-jest": "^26.4.4",
32-
"tslib": "^2.3.1",
33-
"typescript": "^4.6.3"
34-
},
35-
"release-it": {
36-
"github": {
37-
"release": true
2+
"name": "json-api-models",
3+
"description": "A lightweight layer for working with JSON:API data.",
4+
"version": "0.1.0-beta.8",
5+
"author": "Toby Zerner",
6+
"license": "MIT",
7+
"main": "./dist/index.cjs.js",
8+
"module": "./dist/index.es.js",
9+
"unpkg": "./dist/index.js",
10+
"types": "./dist/index.d.ts",
11+
"files": [
12+
"src",
13+
"dist",
14+
"README.md",
15+
"!**/.DS_Store"
16+
],
17+
"scripts": {
18+
"test": "jest",
19+
"build": "rollup -c",
20+
"build:watch": "rollup -cw",
21+
"release": "release-it --npm.tag=latest"
3822
},
39-
"plugins": {
40-
"@release-it/keep-a-changelog": {
41-
"filename": "CHANGELOG.md",
42-
"addUnreleased": true,
43-
"addVersionUrl": true
44-
}
23+
"devDependencies": {
24+
"@release-it/keep-a-changelog": "^2.3.0",
25+
"@rollup/plugin-typescript": "^8.2.5",
26+
"@types/jest": "^26.0.20",
27+
"jest": "^26.6.3",
28+
"prettier": "^2.6.2",
29+
"release-it": "^14.11.5",
30+
"rollup": "^2.56.3",
31+
"rollup-plugin-terser": "^7.0.2",
32+
"ts-jest": "^26.4.4",
33+
"tslib": "^2.3.1",
34+
"typescript": "^4.6.3"
4535
},
46-
"hooks": {
47-
"after:bump": "npm run build"
36+
"release-it": {
37+
"github": {
38+
"release": true
39+
},
40+
"plugins": {
41+
"@release-it/keep-a-changelog": {
42+
"filename": "CHANGELOG.md",
43+
"addUnreleased": true,
44+
"addVersionUrl": true
45+
}
46+
},
47+
"hooks": {
48+
"after:bump": "npm run build"
49+
}
50+
},
51+
"prettier": {
52+
"singleQuote": true
4853
}
49-
}
5054
}

rollup.config.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@ import typescript from '@rollup/plugin-typescript';
33
import { terser } from 'rollup-plugin-terser';
44

55
export default {
6-
input: 'src/index.ts',
7-
output: [
8-
{
9-
file: pkg.main,
10-
format: 'cjs'
11-
},
12-
{
13-
file: pkg.module,
14-
format: 'es'
15-
},
16-
{
17-
file: pkg.unpkg,
18-
format: 'iife',
19-
name: 'JsonApiModels'
20-
}
21-
],
22-
plugins: [
23-
typescript({ tsconfig: './tsconfig.json' }),
24-
terser()
25-
]
6+
input: 'src/index.ts',
7+
output: [
8+
{
9+
file: pkg.main,
10+
format: 'cjs',
11+
},
12+
{
13+
file: pkg.module,
14+
format: 'es',
15+
},
16+
{
17+
file: pkg.unpkg,
18+
format: 'iife',
19+
name: 'JsonApiModels',
20+
},
21+
],
22+
plugins: [typescript({ tsconfig: './tsconfig.json' }), terser()],
2623
};

0 commit comments

Comments
 (0)