shadowly 1.2.0 → 1.3.0
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 +29 -1
- package/dist/index.d.ts +15 -2
- package/dist/index.js +32 -40
- package/package.json +9 -1
- package/src/index.ts +53 -20
- package/tsconfig.json +7 -6
package/README.md
CHANGED
|
@@ -104,6 +104,26 @@ const items = new Shadowly<typeof import("./array.json")>("./array.json")
|
|
|
104
104
|
const prices = items.map((item) => item.get("price").value());
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
+
배열에서는 `add`, `insert`, `remove`로 값을 수정할 수도 있습니다.
|
|
108
|
+
|
|
109
|
+
`add` 함수는 배열의 맨 뒤에 값을 추가합니다.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import Shadowly from 'shadowly';
|
|
113
|
+
|
|
114
|
+
new Shadowly<typeof import("./array.json")>("./array.json")
|
|
115
|
+
.add({ name: "apple", price: 1000 });
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`insert` 함수는 특정 index에 값을 삽입합니다.
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import Shadowly from 'shadowly';
|
|
122
|
+
|
|
123
|
+
new Shadowly<typeof import("./array.json")>("./array.json")
|
|
124
|
+
.insert(1, { name: "banana", price: 1500 });
|
|
125
|
+
```
|
|
126
|
+
|
|
107
127
|
### JSON에 값 쓰기
|
|
108
128
|
|
|
109
129
|
`set` 함수는 특정 키에 씁니다.
|
|
@@ -130,7 +150,7 @@ new Shadowly("./object.json")
|
|
|
130
150
|
*/
|
|
131
151
|
```
|
|
132
152
|
|
|
133
|
-
`remove` 함수는 특정
|
|
153
|
+
`remove` 함수는 특정 키 또는 배열 index를 지웁니다.
|
|
134
154
|
|파라메터|타입|설명|
|
|
135
155
|
|------|--------|-------|
|
|
136
156
|
|key|string or number|키 이름입니다.|
|
|
@@ -151,6 +171,14 @@ new Shadowly("./object.json")
|
|
|
151
171
|
*/
|
|
152
172
|
```
|
|
153
173
|
|
|
174
|
+
```typescript
|
|
175
|
+
import Shadowly from 'shadowly';
|
|
176
|
+
|
|
177
|
+
// 배열의 1번 index 요소를 지웁니다.
|
|
178
|
+
new Shadowly<typeof import("./array.json")>("./array.json")
|
|
179
|
+
.remove(1);
|
|
180
|
+
```
|
|
181
|
+
|
|
154
182
|
### 그 외
|
|
155
183
|
|
|
156
184
|
`back` 함수는 한 번 뒤로 갑니다.
|
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,19 @@ export default class Shadowly<TRoot, TNode = TRoot> {
|
|
|
53
53
|
* @returns 찾은 요소들로 이동한 Shadowly 인스턴스 배열
|
|
54
54
|
*/
|
|
55
55
|
findAll(predicate: ArrayPredicate<TNode>, thisArg?: any): Shadowly<TRoot, ArrayElement<TNode>>[];
|
|
56
|
+
/**
|
|
57
|
+
* 배열의 맨 뒤에 값을 추가합니다.
|
|
58
|
+
* @param value 추가할 값
|
|
59
|
+
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
60
|
+
*/
|
|
61
|
+
add(value: ArrayElement<TNode>): this;
|
|
62
|
+
/**
|
|
63
|
+
* 배열의 특정 index에 값을 삽입합니다.
|
|
64
|
+
* @param index 삽입할 위치
|
|
65
|
+
* @param value 삽입할 값
|
|
66
|
+
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
67
|
+
*/
|
|
68
|
+
insert(index: number, value: ArrayElement<TNode>): this;
|
|
56
69
|
/**
|
|
57
70
|
* 현재 key에 값을 씁니다.
|
|
58
71
|
* @param value 쓸 값
|
|
@@ -60,8 +73,8 @@ export default class Shadowly<TRoot, TNode = TRoot> {
|
|
|
60
73
|
*/
|
|
61
74
|
set(value: TNode): this;
|
|
62
75
|
/**
|
|
63
|
-
* key를 삭제합니다.
|
|
64
|
-
* @param key 삭제할 key
|
|
76
|
+
* key 또는 배열 index를 삭제합니다.
|
|
77
|
+
* @param key 삭제할 key 또는 index
|
|
65
78
|
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
66
79
|
*/
|
|
67
80
|
remove<K extends RemoveKey<TNode>>(key: K): this;
|
package/dist/index.js
CHANGED
|
@@ -1,39 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const fs = __importStar(require("node:fs"));
|
|
1
|
+
import * as fs from "node:fs";
|
|
37
2
|
class ShadowlyError extends Error {
|
|
38
3
|
code;
|
|
39
4
|
constructor(code, message) {
|
|
@@ -54,7 +19,7 @@ function isValidJson(text) {
|
|
|
54
19
|
return false;
|
|
55
20
|
}
|
|
56
21
|
}
|
|
57
|
-
class Shadowly {
|
|
22
|
+
export default class Shadowly {
|
|
58
23
|
DB_PATH;
|
|
59
24
|
path;
|
|
60
25
|
content;
|
|
@@ -151,6 +116,34 @@ class Shadowly {
|
|
|
151
116
|
}
|
|
152
117
|
return result;
|
|
153
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* 배열의 맨 뒤에 값을 추가합니다.
|
|
121
|
+
* @param value 추가할 값
|
|
122
|
+
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
123
|
+
*/
|
|
124
|
+
add(value) {
|
|
125
|
+
if (!Array.isArray(this.content))
|
|
126
|
+
throw new ShadowlyError("ETYPE", "Current value is not an array.");
|
|
127
|
+
this.content.push(value);
|
|
128
|
+
this.persist();
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 배열의 특정 index에 값을 삽입합니다.
|
|
133
|
+
* @param index 삽입할 위치
|
|
134
|
+
* @param value 삽입할 값
|
|
135
|
+
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
136
|
+
*/
|
|
137
|
+
insert(index, value) {
|
|
138
|
+
if (!Array.isArray(this.content))
|
|
139
|
+
throw new ShadowlyError("ETYPE", "Current value is not an array.");
|
|
140
|
+
const array = this.content;
|
|
141
|
+
if (!Number.isInteger(index) || index < 0 || index > array.length)
|
|
142
|
+
throw new ShadowlyError("ERANGE", "Index is out of range.");
|
|
143
|
+
array.splice(index, 0, value);
|
|
144
|
+
this.persist();
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
154
147
|
/**
|
|
155
148
|
* 현재 key에 값을 씁니다.
|
|
156
149
|
* @param value 쓸 값
|
|
@@ -165,8 +158,8 @@ class Shadowly {
|
|
|
165
158
|
return this;
|
|
166
159
|
}
|
|
167
160
|
/**
|
|
168
|
-
* key를 삭제합니다.
|
|
169
|
-
* @param key 삭제할 key
|
|
161
|
+
* key 또는 배열 index를 삭제합니다.
|
|
162
|
+
* @param key 삭제할 key 또는 index
|
|
170
163
|
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
171
164
|
*/
|
|
172
165
|
remove(key) {
|
|
@@ -221,4 +214,3 @@ class Shadowly {
|
|
|
221
214
|
fs.writeFileSync(r.DB_PATH, JSON.stringify(r.content, null, 2), "utf-8");
|
|
222
215
|
}
|
|
223
216
|
}
|
|
224
|
-
exports.default = Shadowly;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shadowly",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "TypeScript JSON Database",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"database",
|
|
@@ -20,6 +20,14 @@
|
|
|
20
20
|
"author": "Pro203S",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"main": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
23
31
|
"scripts": {
|
|
24
32
|
"build": "tsc"
|
|
25
33
|
},
|
package/src/index.ts
CHANGED
|
@@ -169,11 +169,11 @@ export default class Shadowly<TRoot, TNode = TRoot> {
|
|
|
169
169
|
* @param thisArg callback의 this로 사용할 값
|
|
170
170
|
* @returns 찾은 요소들로 이동한 Shadowly 인스턴스 배열
|
|
171
171
|
*/
|
|
172
|
-
findAll(
|
|
173
|
-
predicate: ArrayPredicate<TNode>,
|
|
174
|
-
thisArg?: any
|
|
175
|
-
): Shadowly<TRoot, ArrayElement<TNode>>[] {
|
|
176
|
-
if (!Array.isArray(this.content))
|
|
172
|
+
findAll(
|
|
173
|
+
predicate: ArrayPredicate<TNode>,
|
|
174
|
+
thisArg?: any
|
|
175
|
+
): Shadowly<TRoot, ArrayElement<TNode>>[] {
|
|
176
|
+
if (!Array.isArray(this.content))
|
|
177
177
|
throw new ShadowlyError("ETYPE", "Current value is not an array.");
|
|
178
178
|
|
|
179
179
|
const callback = predicate as (
|
|
@@ -193,14 +193,47 @@ export default class Shadowly<TRoot, TNode = TRoot> {
|
|
|
193
193
|
this.get(index as GetKey<TNode>) as Shadowly<TRoot, ArrayElement<TNode>>
|
|
194
194
|
);
|
|
195
195
|
}
|
|
196
|
-
|
|
197
|
-
return result;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
*
|
|
202
|
-
* @param value
|
|
203
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
196
|
+
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 배열의 맨 뒤에 값을 추가합니다.
|
|
202
|
+
* @param value 추가할 값
|
|
203
|
+
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
204
|
+
*/
|
|
205
|
+
add(value: ArrayElement<TNode>): this {
|
|
206
|
+
if (!Array.isArray(this.content))
|
|
207
|
+
throw new ShadowlyError("ETYPE", "Current value is not an array.");
|
|
208
|
+
|
|
209
|
+
(this.content as ArrayElement<TNode>[]).push(value);
|
|
210
|
+
this.persist();
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 배열의 특정 index에 값을 삽입합니다.
|
|
216
|
+
* @param index 삽입할 위치
|
|
217
|
+
* @param value 삽입할 값
|
|
218
|
+
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
219
|
+
*/
|
|
220
|
+
insert(index: number, value: ArrayElement<TNode>): this {
|
|
221
|
+
if (!Array.isArray(this.content))
|
|
222
|
+
throw new ShadowlyError("ETYPE", "Current value is not an array.");
|
|
223
|
+
|
|
224
|
+
const array = this.content as ArrayElement<TNode>[];
|
|
225
|
+
if (!Number.isInteger(index) || index < 0 || index > array.length)
|
|
226
|
+
throw new ShadowlyError("ERANGE", "Index is out of range.");
|
|
227
|
+
|
|
228
|
+
array.splice(index, 0, value);
|
|
229
|
+
this.persist();
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* 현재 key에 값을 씁니다.
|
|
235
|
+
* @param value 쓸 값
|
|
236
|
+
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
204
237
|
*/
|
|
205
238
|
set(value: TNode): this {
|
|
206
239
|
this.content = value;
|
|
@@ -214,13 +247,13 @@ export default class Shadowly<TRoot, TNode = TRoot> {
|
|
|
214
247
|
}
|
|
215
248
|
|
|
216
249
|
/**
|
|
217
|
-
* key를 삭제합니다.
|
|
218
|
-
* @param key 삭제할 key
|
|
219
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
220
|
-
*/
|
|
221
|
-
remove<K extends RemoveKey<TNode>>(key: K): this {
|
|
222
|
-
const cur: any = this.content;
|
|
223
|
-
|
|
250
|
+
* key 또는 배열 index를 삭제합니다.
|
|
251
|
+
* @param key 삭제할 key 또는 index
|
|
252
|
+
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
253
|
+
*/
|
|
254
|
+
remove<K extends RemoveKey<TNode>>(key: K): this {
|
|
255
|
+
const cur: any = this.content;
|
|
256
|
+
|
|
224
257
|
if (Array.isArray(cur)) {
|
|
225
258
|
const idx = key as unknown as number;
|
|
226
259
|
if (Number.isInteger(idx) && idx >= 0 && idx < cur.length) cur.splice(idx, 1);
|
package/tsconfig.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"declaration": true,
|
|
8
9
|
"strict": true,
|
|
9
10
|
"esModuleInterop": true,
|
|
10
11
|
"resolveJsonModule": true,
|