Skip to content

Commit 9a60aa4

Browse files
committed
Modify api for convertCaseCacheSize option
1 parent 14626ac commit 9a60aa4

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Diff for: README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@ Serializer.register(type, options);
6565

6666
To avoid repeating the same options for each type, it's possible to add global options on `JSONAPISerializer` instance:
6767

68-
When using convertCase, a LRU cache is utilized for optimization. The default size of the cache is 5000 per conversion type. The size of the cache can be set by passing in a second parameter to the instance. Passing in 0 will result in a LRU cache of infinite size.
68+
When using convertCase, a LRU cache is utilized for optimization. The default size of the cache is 5000 per conversion type. The size of the cache can be set with the `convertCaseCacheSize` option. Passing in 0 will result in a LRU cache of infinite size.
6969

7070
```javascript
7171
var JSONAPISerializer = require("json-api-serializer");
7272
var Serializer = new JSONAPISerializer({
7373
convertCase: "kebab-case",
74-
unconvertCase: "camelCase"
75-
}, 0);
74+
unconvertCase: "camelCase",
75+
convertCaseCacheSize: 0
76+
});
7677
```
7778

7879
## Usage

Diff for: lib/JSONAPISerializer.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ const { validateOptions, validateDynamicTypeOptions, validateError } = require('
2626
*
2727
* @class JSONAPISerializer
2828
* @param {object} [opts] Global options.
29-
* @param {number} [convertCaseCacheSize=5000] Size of cache used for convertCase, 0 results in an infinitely sized cache
3029
*/
3130
module.exports = class JSONAPISerializer {
32-
constructor(opts, convertCaseCacheSize = 5000) {
31+
constructor(opts) {
3332
this.opts = opts || {};
3433
this.schemas = {};
3534

35+
// Size of cache used for convertCase, 0 results in an infinitely sized cache
36+
const { convertCaseCacheSize = 5000 } = this.opts;
3637
// Cache of strings to convert to their converted values per conversion type
3738
this.convertCaseMap = {
3839
camelCase: new LRU(convertCaseCacheSize),

0 commit comments

Comments
 (0)