@sapphire/string-store 1.1.0-next.7c2bed20 → 1.1.0-next.db356eb0
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 +118 -26
- package/dist/cjs/index.cjs +394 -56
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +244 -37
- package/dist/esm/index.d.mts +244 -37
- package/dist/esm/index.mjs +384 -57
- package/dist/esm/index.mjs.map +1 -1
- package/dist/iife/index.global.js +394 -56
- package/dist/iife/index.global.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ locations such as Discord's `custom_id` field in message components.
|
|
|
22
22
|
|
|
23
23
|
- Written in TypeScript
|
|
24
24
|
- Bundled with esbuild so it can be used in NodeJS and browsers
|
|
25
|
-
- Offers CommonJS, ESM and UMD bundles
|
|
25
|
+
- Offers CommonJS, ESM, and UMD bundles
|
|
26
26
|
- Fully tested
|
|
27
27
|
|
|
28
28
|
## Installation
|
|
@@ -39,7 +39,7 @@ npm install @sapphire/string-store
|
|
|
39
39
|
|
|
40
40
|
```ts
|
|
41
41
|
// Require the store classes
|
|
42
|
-
const { SchemaStore, Schema } = require('@sapphire/string-store');
|
|
42
|
+
const { SchemaStore, Schema, t } = require('@sapphire/string-store');
|
|
43
43
|
|
|
44
44
|
const Id = {
|
|
45
45
|
AgeUpdate: 0,
|
|
@@ -66,9 +66,9 @@ const buffer = store.serialize(Id.AgeUpdate, { age: 20 }).toString();
|
|
|
66
66
|
> [!Tip]
|
|
67
67
|
> The serialized string is encoded in UTF-16, meaning it can store 16 bits per character. Each type stores a different number of bits, for example, a single character can store:
|
|
68
68
|
> - 16 booleans
|
|
69
|
-
> - 8 2-bit integers (0-3)
|
|
70
|
-
> - 4 4-bit integers (0-15)
|
|
71
|
-
> - 2 8-bit integers (0-255)
|
|
69
|
+
> - 8 2-bit unsigned integers (0-3)
|
|
70
|
+
> - 4 4-bit unsigned integers (0-15)
|
|
71
|
+
> - 2 8-bit unsigned integers (0-255)
|
|
72
72
|
> - 1 16-bit integer (0-65535)
|
|
73
73
|
>
|
|
74
74
|
> As a use-case, Discord's `custom_id` field in message components can store up to **100** UTF-16 characters, which means it has a storage of **1600 bits**, below you can see the supported types and their storage in bits. Keep in mind that the schema ID is stored as a [16-bit](#int16) integer, and that the property names are **not** stored.
|
|
@@ -82,7 +82,7 @@ Adds an array with a dynamic length to the schema.
|
|
|
82
82
|
```ts
|
|
83
83
|
// A schema with a single field `names` that is an array of strings:
|
|
84
84
|
|
|
85
|
-
const schema = new Schema(Id.Planets).array('names',
|
|
85
|
+
const schema = new Schema(Id.Planets).array('names', t.string);
|
|
86
86
|
// → Schema<Id.Planets, { names: string[] }>
|
|
87
87
|
```
|
|
88
88
|
|
|
@@ -90,13 +90,13 @@ To track the length of the array, it will serialize a [16-bit](#int16) unsigned
|
|
|
90
90
|
|
|
91
91
|
### `fixedLengthArray`
|
|
92
92
|
|
|
93
|
-
An alternative to [`array`](#array) that has a fixed length
|
|
94
|
-
but it will save space by not storing the length of the array.
|
|
93
|
+
An alternative to [`array`](#array) that has a fixed length. This variant requires the exact number of elements to be
|
|
94
|
+
serialized, but it will save space by not storing the length of the array.
|
|
95
95
|
|
|
96
96
|
```ts
|
|
97
97
|
// A schema with a single field `names` that is an array of exactly 3 strings:
|
|
98
98
|
|
|
99
|
-
const schema = new Schema(Id.Planets).fixedLengthArray('names',
|
|
99
|
+
const schema = new Schema(Id.Planets).fixedLengthArray('names', t.string, 3);
|
|
100
100
|
// → Schema<Id.Planets, { names: [string, string, string] }>
|
|
101
101
|
```
|
|
102
102
|
|
|
@@ -137,92 +137,184 @@ const schema = new Schema(Id.Planet).bit('isHabitable');
|
|
|
137
137
|
|
|
138
138
|
### `int2`
|
|
139
139
|
|
|
140
|
-
Adds a 2-bit integer to the schema. It can store values from
|
|
140
|
+
Adds a 2-bit signed integer to the schema. It can store values from -2 to 1, inclusive.
|
|
141
141
|
|
|
142
142
|
```ts
|
|
143
|
-
// A schema with a single field `type` that is a 2-bit integer:
|
|
143
|
+
// A schema with a single field `type` that is a 2-bit signed integer:
|
|
144
144
|
|
|
145
145
|
const schema = new Schema(Id.Planet).int2('type');
|
|
146
|
+
// → Schema<Id.Planets, { type: -2 | -1 | 0 | 1 }>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### `uint2`
|
|
150
|
+
|
|
151
|
+
Adds a 2-bit unsigned integer to the schema. It can store values from 0 to 3, inclusive.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
// A schema with a single field `type` that is a 2-bit unsigned integer:
|
|
155
|
+
|
|
156
|
+
const schema = new Schema(Id.Planet).uint2('type');
|
|
146
157
|
// → Schema<Id.Planets, { type: 0 | 1 | 2 | 3 }>
|
|
147
158
|
```
|
|
148
159
|
|
|
149
160
|
### `int4`
|
|
150
161
|
|
|
151
|
-
Adds a 4-bit integer to the schema. It can store values from
|
|
162
|
+
Adds a 4-bit signed integer to the schema. It can store values from -8 to 7, inclusive.
|
|
152
163
|
|
|
153
164
|
```ts
|
|
154
|
-
// A schema with a single field `type` that is a 4-bit integer:
|
|
165
|
+
// A schema with a single field `type` that is a 4-bit signed integer:
|
|
155
166
|
|
|
156
167
|
const schema = new Schema(Id.Planet).int4('type');
|
|
168
|
+
// → Schema<Id.Planets, { type: -8..=7 }>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### `uint4`
|
|
172
|
+
|
|
173
|
+
Adds a 4-bit unsigned integer to the schema. It can store values from 0 to 15, inclusive.
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
// A schema with a single field `type` that is a 4-bit unsigned integer:
|
|
177
|
+
|
|
178
|
+
const schema = new Schema(Id.Planet).uint4('type');
|
|
157
179
|
// → Schema<Id.Planets, { type: 0..=15 }>
|
|
158
180
|
```
|
|
159
181
|
|
|
160
182
|
### `int8`
|
|
161
183
|
|
|
162
|
-
Adds an 8-bit integer to the schema. It can store values from
|
|
184
|
+
Adds an 8-bit signed integer to the schema. It can store values from -128 to 127, inclusive.
|
|
163
185
|
|
|
164
186
|
```ts
|
|
165
|
-
// A schema with a single field `type` that is an 8-bit integer:
|
|
187
|
+
// A schema with a single field `type` that is an 8-bit signed integer:
|
|
166
188
|
|
|
167
189
|
const schema = new Schema(Id.Planet).int8('type');
|
|
190
|
+
// → Schema<Id.Planets, { type: -128..=127 }>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### `uint8`
|
|
194
|
+
|
|
195
|
+
Adds an 8-bit unsigned integer to the schema. It can store values from 0 to 255, inclusive.
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
// A schema with a single field `type` that is an 8-bit unsigned integer:
|
|
199
|
+
|
|
200
|
+
const schema = new Schema(Id.Planet).uint8('type');
|
|
168
201
|
// → Schema<Id.Planets, { type: 0..=255 }>
|
|
169
202
|
```
|
|
170
203
|
|
|
171
204
|
### `int16`
|
|
172
205
|
|
|
173
|
-
Adds a 16-bit integer to the schema. It can store values from
|
|
206
|
+
Adds a 16-bit signed integer to the schema. It can store values from -32768 to 32767, inclusive.
|
|
174
207
|
|
|
175
208
|
```ts
|
|
176
|
-
// A schema with a single field `type` that is a 16-bit integer:
|
|
209
|
+
// A schema with a single field `type` that is a 16-bit signed integer:
|
|
177
210
|
|
|
178
211
|
const schema = new Schema(Id.Planet).int16('type');
|
|
212
|
+
// → Schema<Id.Planets, { type: -32768..=32767 }>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### `uint16`
|
|
216
|
+
|
|
217
|
+
Adds a 16-bit unsigned integer to the schema. It can store values from 0 to 65535, inclusive.
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
// A schema with a single field `type` that is a 16-bit unsigned integer:
|
|
221
|
+
|
|
222
|
+
const schema = new Schema(Id.Planet).uint16('type');
|
|
179
223
|
// → Schema<Id.Planets, { type: 0..=65535 }>
|
|
180
224
|
```
|
|
181
225
|
|
|
182
226
|
### `int32`
|
|
183
227
|
|
|
184
|
-
Adds a 32-bit integer to the schema. It can store values from
|
|
228
|
+
Adds a 32-bit signed integer to the schema. It can store values from 2,147,483,648 to 2,147,483,647, inclusive.
|
|
185
229
|
|
|
186
230
|
```ts
|
|
187
|
-
// A schema with a single field `type` that is a 32-bit integer:
|
|
231
|
+
// A schema with a single field `type` that is a 32-bit signed integer:
|
|
188
232
|
|
|
189
233
|
const schema = new Schema(Id.Planet).int32('type');
|
|
234
|
+
// → Schema<Id.Planets, { type: 2_147_483_648..=2_147_483_647 }>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### `uint32`
|
|
238
|
+
|
|
239
|
+
Adds a 32-bit unsigned integer to the schema. It can store values from 0 to 4,294,967,295, inclusive.
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
// A schema with a single field `type` that is a 32-bit unsigned integer:
|
|
243
|
+
|
|
244
|
+
const schema = new Schema(Id.Planet).uint32('type');
|
|
190
245
|
// → Schema<Id.Planets, { type: 0..=4294967295 }>
|
|
191
246
|
```
|
|
192
247
|
|
|
193
248
|
### `int64`
|
|
194
249
|
|
|
195
|
-
Adds a 64-bit integer to the schema. It can store values from
|
|
250
|
+
Adds a 64-bit signed integer to the schema. It can store values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, inclusive.
|
|
251
|
+
|
|
252
|
+
**Note**: values smaller than `Number.MIN_SAFE_INTEGER` or larger than `Number.MAX_SAFE_INTEGER` will lose precision, if you need to store larger numbers, consider using [`bigInt64`](#bigint64).
|
|
196
253
|
|
|
197
254
|
```ts
|
|
198
|
-
// A schema with a single field `type` that is a 64-bit integer:
|
|
255
|
+
// A schema with a single field `type` that is a 64-bit signed integer:
|
|
199
256
|
|
|
200
257
|
const schema = new Schema(Id.Planet).int64('type');
|
|
201
|
-
// → Schema<Id.Planets, { type:
|
|
258
|
+
// → Schema<Id.Planets, { type: -9_223_372_036_854_775_808..=9_223_372_036_854_775_807 }>
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### `uint64`
|
|
262
|
+
|
|
263
|
+
Adds a 64-bit unsigned integer to the schema. It can store values from 0 to 18,446,744,073,709,551,615, inclusive.
|
|
264
|
+
|
|
265
|
+
**Note**: values larger than 9,007,199,254,740,991 (`Number.MAX_SAFE_INTEGER`) will lose precision, if you need to store larger numbers, use [`bigUint64`](#bigUint64).
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
// A schema with a single field `type` that is a 64-bit unsigned integer:
|
|
269
|
+
|
|
270
|
+
const schema = new Schema(Id.Planet).uint64('type');
|
|
271
|
+
// → Schema<Id.Planets, { type: 0..=18_446_744_073_709_551_615 }>
|
|
202
272
|
```
|
|
203
273
|
|
|
204
274
|
**Note**: values larger than `Number.MAX_SAFE_INTEGER` will be truncated.
|
|
205
275
|
|
|
206
276
|
### `bigInt32`
|
|
207
277
|
|
|
208
|
-
Alternative to [`int32`](#int32) that uses `BigInt`.
|
|
278
|
+
Alternative to [`int32`](#int32) that uses `BigInt`. It can store values from 2,147,483,648 to 2,147,483,647, inclusive.
|
|
209
279
|
|
|
210
280
|
```ts
|
|
211
281
|
// A schema with a single field `type` that is a 32-bit integer:
|
|
212
282
|
|
|
213
283
|
const schema = new Schema(Id.Planet).bigInt32('type');
|
|
284
|
+
// → Schema<Id.Planets, { type: 2_147_483_648n..=2_147_483_647n }>
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### `bigUint32`
|
|
288
|
+
|
|
289
|
+
Alternative to [`uint32`](#uint32) that uses `BigInt`. It can store values from 0 to 4,294,967,295, inclusive.
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
// A schema with a single field `type` that is a 32-bit integer:
|
|
293
|
+
|
|
294
|
+
const schema = new Schema(Id.Planet).bigUint32('type');
|
|
214
295
|
// → Schema<Id.Planets, { type: 0n..=4294967295n }>
|
|
215
296
|
```
|
|
216
297
|
|
|
217
298
|
### `bigInt64`
|
|
218
299
|
|
|
219
|
-
Alternative to [`int64`](#int64) that uses `BigInt`.
|
|
300
|
+
Alternative to [`int64`](#int64) that uses `BigInt`. It can store values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, inclusive.
|
|
220
301
|
|
|
221
302
|
```ts
|
|
222
303
|
// A schema with a single field `type` that is a 64-bit integer:
|
|
223
304
|
|
|
224
305
|
const schema = new Schema(Id.Planet).bigInt64('type');
|
|
225
|
-
// → Schema<Id.Planets, { type:
|
|
306
|
+
// → Schema<Id.Planets, { type: -9_223_372_036_854_775_808n..=9_223_372_036_854_775_807n }>
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### `bigUint64`
|
|
310
|
+
|
|
311
|
+
Alternative to [`uint64`](#uint64) that uses `BigInt`. It can store values from 0 to 18,446,744,073,709,551,615, inclusive.
|
|
312
|
+
|
|
313
|
+
```ts
|
|
314
|
+
// A schema with a single field `type` that is a 64-bit integer:
|
|
315
|
+
|
|
316
|
+
const schema = new Schema(Id.Planet).bigUint64('type');
|
|
317
|
+
// → Schema<Id.Planets, { type: 0n..=18_446_744_073_709_551_615n }>
|
|
226
318
|
```
|
|
227
319
|
|
|
228
320
|
### `float32`
|
|
@@ -262,7 +354,7 @@ const schema = new Schema(Id.User).snowflake('id');
|
|
|
262
354
|
|
|
263
355
|
Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
|
|
264
356
|
|
|
265
|
-
We accept donations through Open Collective, Ko-fi, PayPal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.
|
|
357
|
+
We accept donations through Open Collective, Ko-fi, PayPal, Patreon, and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.
|
|
266
358
|
|
|
267
359
|
| Donate With | Address |
|
|
268
360
|
| :-------------: | :-------------------------------------------------: |
|