@trenskow/json-compressor 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,4 +26,3 @@ inflate(JSON.parse(json)); // Returns copy of original instance (with circular r
26
26
  # License
27
27
 
28
28
  See license in LICENSE.
29
-
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ //
2
+ // index.d.ts
3
+ // @trenskow/json-compressor
4
+ //
5
+ // Created by Kristian Trenskow on 2025/12/19
6
+ // For license see LICENSE.
7
+ //
8
+
9
+ export function deflate(json: any): any;
10
+ export function inflate(json: any): any;
package/lib/index.js CHANGED
@@ -105,7 +105,7 @@ const deflate = (json) => {
105
105
 
106
106
  };
107
107
 
108
- const _inflate = (data, index, resolved) => {
108
+ const _inflate = (json, index, resolved) => {
109
109
 
110
110
  if (index in indices) {
111
111
  return indices[index];
@@ -115,19 +115,19 @@ const _inflate = (data, index, resolved) => {
115
115
  return resolved[parseInt(index.slice(1, -1), 10)];
116
116
  }
117
117
 
118
- const value = data[index];
118
+ const value = json[index];
119
119
 
120
120
  if (Array.isArray(value)) {
121
121
 
122
122
  if (value[0] === 'a') {
123
- return _inflate.array(data, index, value.slice(1), resolved);
123
+ return _inflate.array(json, index, value.slice(1), resolved);
124
124
  }
125
125
 
126
126
  if (value[0] === 'o') {
127
- return _inflate.object(data, index, value.slice(1), resolved);
127
+ return _inflate.object(json, index, value.slice(1), resolved);
128
128
  }
129
129
 
130
- return data;
130
+ return json;
131
131
 
132
132
  }
133
133
 
@@ -135,21 +135,21 @@ const _inflate = (data, index, resolved) => {
135
135
 
136
136
  };
137
137
 
138
- _inflate.array = (data, index, value, resolved) => {
138
+ _inflate.array = (json, index, value, resolved) => {
139
139
 
140
140
  const result = [];
141
141
 
142
142
  resolved[index] = result;
143
143
 
144
144
  for (let i = 0; i < value.length; i++) {
145
- result.push(_inflate(data, value[i], resolved));
145
+ result.push(_inflate(json, value[i], resolved));
146
146
  }
147
147
 
148
148
  return result;
149
149
 
150
150
  };
151
151
 
152
- _inflate.object = (data, index, value, resolved) => {
152
+ _inflate.object = (json, index, value, resolved) => {
153
153
 
154
154
  if (value.length % 2 !== 0) {
155
155
  return value;
@@ -160,28 +160,28 @@ _inflate.object = (data, index, value, resolved) => {
160
160
  resolved[index] = result;
161
161
 
162
162
  for (let i = 0; i < value.length; i += 2) {
163
- result[_inflate(data, value[i], resolved)] = _inflate(data, value[i + 1], resolved);
163
+ result[_inflate(json, value[i], resolved)] = _inflate(json, value[i + 1], resolved);
164
164
  }
165
165
 
166
166
  return result;
167
167
 
168
168
  };
169
169
 
170
- const inflate = (data) => {
170
+ const inflate = (json) => {
171
171
 
172
- if (!Array.isArray(data)) {
173
- return data;
172
+ if (!Array.isArray(json)) {
173
+ return json;
174
174
  }
175
175
 
176
- if (data.length < 2) {
177
- return data;
176
+ if (json.length < 2) {
177
+ return json;
178
178
  }
179
179
 
180
- if (!Array.isArray(data[0])) {
181
- return data;
180
+ if (!Array.isArray(json[0])) {
181
+ return json;
182
182
  }
183
183
 
184
- return _inflate(data, 0, {});
184
+ return _inflate(json, 0, {});
185
185
 
186
186
  };
187
187
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/json-compressor",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "A simple JSON to JSON compressor for JavaScript.",
5
5
  "keywords": [
6
6
  "json",
@@ -19,18 +19,19 @@
19
19
  "author": "Kristian Trenskow <this.is@kristians.email>",
20
20
  "type": "module",
21
21
  "main": "index.js",
22
+ "types": "index.d.ts",
22
23
  "scripts": {
23
24
  "test": "node ./node_modules/mocha/bin/mocha.js ./test/index.js"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@eslint/eslintrc": "^3.3.3",
27
28
  "@eslint/js": "^9.39.2",
28
- "chai": "^6.2.1",
29
+ "chai": "^6.2.2",
29
30
  "eslint": "^9.39.2",
30
31
  "globals": "^16.5.0",
31
32
  "mocha": "^11.7.5"
32
33
  },
33
34
  "dependencies": {
34
- "@trenskow/equals": "^0.1.2"
35
+ "@trenskow/equals": "^0.1.3"
35
36
  }
36
37
  }