Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1e19a37

Browse files
committed
style: 💄 run Prettier
1 parentdecdfd2 commit1e19a37

File tree

3 files changed

+33
-60
lines changed

3 files changed

+33
-60
lines changed

‎src/__bench__/bench.encodeUtf8.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,14 @@ const benchmark = {
114114
return(data:any)=>encoder.encode(data);
115115
},
116116
},
117-
...(hasBuffer ?[{
118-
name:'Buffer.from()',
119-
setup:()=>(data:any)=>newUint8Array(Buffer.from(data,'utf8')),
120-
}] :[]),
117+
...(hasBuffer
118+
?[
119+
{
120+
name:'Buffer.from()',
121+
setup:()=>(data:any)=>newUint8Array(Buffer.from(data,'utf8')),
122+
},
123+
]
124+
:[]),
121125
{
122126
name:'Writer.utf8()',
123127
setup:()=>{

‎src/__tests__/Reader.spec.ts‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -805,14 +805,7 @@ describe('Reader', () => {
805805
});
806806

807807
test('roundtrip with Writer',()=>{
808-
consttestStrings=[
809-
'simple',
810-
'café',
811-
'日本語',
812-
'😀',
813-
'мир',
814-
'Hello мир 世界 🌍',
815-
];
808+
consttestStrings=['simple','café','日本語','😀','мир','Hello мир 世界 🌍'];
816809

817810
for(conststroftestStrings){
818811
constwriter=newWriter();
@@ -855,7 +848,7 @@ describe('Reader', () => {
855848

856849
test('reads ASCII with special characters',()=>{
857850
conststr='Hello!@#123';
858-
constdata=newUint8Array(str.split('').map(c=>c.charCodeAt(0)));
851+
constdata=newUint8Array(str.split('').map((c)=>c.charCodeAt(0)));
859852
constreader=newReader(data);
860853
constresult=reader.ascii(str.length);
861854
expect(result).toBe(str);
@@ -866,15 +859,15 @@ describe('Reader', () => {
866859
for(leti=32;i<127;i++){
867860
str+=String.fromCharCode(i);
868861
}
869-
constdata=newUint8Array(str.split('').map(c=>c.charCodeAt(0)));
862+
constdata=newUint8Array(str.split('').map((c)=>c.charCodeAt(0)));
870863
constreader=newReader(data);
871864
constresult=reader.ascii(str.length);
872865
expect(result).toBe(str);
873866
});
874867

875868
test('stress test: very long ASCII string',()=>{
876869
constlongStr='a'.repeat(100000);
877-
constdata=newUint8Array(longStr.split('').map(c=>c.charCodeAt(0)));
870+
constdata=newUint8Array(longStr.split('').map((c)=>c.charCodeAt(0)));
878871
constreader=newReader(data);
879872
constresult=reader.ascii(longStr.length);
880873
expect(result).toBe(longStr);
@@ -899,7 +892,7 @@ describe('Reader', () => {
899892
constview=newDataView(buffer);
900893
view.setUint8(0,42);
901894
view.setUint16(1,0x1234);
902-
view.setUint32(3,0xDEADBEEF);
895+
view.setUint32(3,0xdeadbeef);
903896
constasciiStr='test';
904897
constuint8=newUint8Array(buffer);
905898
for(leti=0;i<asciiStr.length;i++){
@@ -909,7 +902,7 @@ describe('Reader', () => {
909902
constreader=newReader(uint8);
910903
expect(reader.u8()).toBe(42);
911904
expect(reader.u16()).toBe(0x1234);
912-
expect(reader.u32()).toBe(0xDEADBEEF);
905+
expect(reader.u32()).toBe(0xdeadbeef);
913906
expect(reader.ascii(4)).toBe('test');
914907
});
915908

‎src/__tests__/Writer.spec.ts‎

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ describe('Writer', () => {
195195
describe('u16',()=>{
196196
test('writes 16-bit unsigned integer',()=>{
197197
constwriter=newWriter();
198-
writer.u16(0xABCD);
198+
writer.u16(0xabcd);
199199
expect(writer.x).toBe(2);
200200
// Check the values written (assuming little-endian or system endianness)
201201
constvalue=writer.view.getUint16(0);
202-
expect(value).toBe(0xABCD);
202+
expect(value).toBe(0xabcd);
203203
});
204204
});
205205

@@ -233,10 +233,10 @@ describe('Writer', () => {
233233
describe('u64',()=>{
234234
test('writes 64-bit unsigned integer as number',()=>{
235235
constwriter=newWriter();
236-
writer.u64(0x1234567890ABCDEF);
236+
writer.u64(0x1234567890abcdef);
237237
expect(writer.x).toBe(8);
238238
constvalue=writer.view.getBigUint64(0);
239-
expect(value).toBe(BigInt(0x1234567890ABCDEF));
239+
expect(value).toBe(BigInt(0x1234567890abcdef));
240240
});
241241

242242
test('writes 64-bit unsigned integer as bigint',()=>{
@@ -267,9 +267,9 @@ describe('Writer', () => {
267267
describe('u8u16',()=>{
268268
test('writes byte and 16-bit word',()=>{
269269
constwriter=newWriter();
270-
writer.u8u16(0xFF,0x1234);
270+
writer.u8u16(0xff,0x1234);
271271
expect(writer.x).toBe(3);
272-
expect(writer.uint8[0]).toBe(0xFF);
272+
expect(writer.uint8[0]).toBe(0xff);
273273
expect(writer.uint8[1]).toBe(0x12);
274274
expect(writer.uint8[2]).toBe(0x34);
275275
});
@@ -278,27 +278,27 @@ describe('Writer', () => {
278278
describe('u8u32',()=>{
279279
test('writes byte and 32-bit dword',()=>{
280280
constwriter=newWriter();
281-
writer.u8u32(0xAA,0x12345678);
281+
writer.u8u32(0xaa,0x12345678);
282282
expect(writer.x).toBe(5);
283-
expect(writer.uint8[0]).toBe(0xAA);
283+
expect(writer.uint8[0]).toBe(0xaa);
284284
});
285285
});
286286

287287
describe('u8u64',()=>{
288288
test('writes byte and 64-bit qword',()=>{
289289
constwriter=newWriter();
290-
writer.u8u64(0xFF,0x123456789ABCDEF0);
290+
writer.u8u64(0xff,0x123456789abcdef0);
291291
expect(writer.x).toBe(9);
292-
expect(writer.uint8[0]).toBe(0xFF);
292+
expect(writer.uint8[0]).toBe(0xff);
293293
});
294294
});
295295

296296
describe('u8f32',()=>{
297297
test('writes byte and 32-bit float',()=>{
298298
constwriter=newWriter();
299-
writer.u8f32(0xAA,1.5);
299+
writer.u8f32(0xaa,1.5);
300300
expect(writer.x).toBe(5);
301-
expect(writer.uint8[0]).toBe(0xAA);
301+
expect(writer.uint8[0]).toBe(0xaa);
302302
constvalue=writer.view.getFloat32(1);
303303
expect(value).toBeCloseTo(1.5);
304304
});
@@ -307,9 +307,9 @@ describe('Writer', () => {
307307
describe('u8f64',()=>{
308308
test('writes byte and 64-bit float',()=>{
309309
constwriter=newWriter();
310-
writer.u8f64(0xBB,3.14159);
310+
writer.u8f64(0xbb,3.14159);
311311
expect(writer.x).toBe(9);
312-
expect(writer.uint8[0]).toBe(0xBB);
312+
expect(writer.uint8[0]).toBe(0xbb);
313313
constvalue=writer.view.getFloat64(1);
314314
expect(value).toBeCloseTo(3.14159);
315315
});
@@ -557,14 +557,7 @@ describe('Writer', () => {
557557

558558
test('encodes to same bytes as TextEncoder',()=>{
559559
constwriter=newWriter();
560-
consttestStrings=[
561-
'Hello',
562-
'café',
563-
'你好',
564-
'👍',
565-
'Привет',
566-
'mixed: Hello мир 世界 🌍',
567-
];
560+
consttestStrings=['Hello','café','你好','👍','Привет','mixed: Hello мир 世界 🌍'];
568561

569562
for(conststroftestStrings){
570563
writer.newBuffer(str.length*4+1);
@@ -579,12 +572,7 @@ describe('Writer', () => {
579572

580573
test('handles consecutive writes',()=>{
581574
constwriter=newWriter();
582-
conststrings=[
583-
'Hello ',
584-
'мир ',
585-
'世界 ',
586-
'👍',
587-
];
575+
conststrings=['Hello ','мир ','世界 ','👍'];
588576
lettotalLength=0;
589577
for(conststrofstrings){
590578
constlen=writer.utf8(str);
@@ -617,13 +605,7 @@ describe('Writer', () => {
617605

618606
test('stress test: alternating small and large strings',()=>{
619607
constwriter=newWriter(10);// Small initial buffer
620-
conststrings=[
621-
'a',
622-
'😀'.repeat(1000),
623-
'test',
624-
'中国'.repeat(500),
625-
'!',
626-
];
608+
conststrings=['a','😀'.repeat(1000),'test','中国'.repeat(500),'!'];
627609

628610
for(conststrofstrings){
629611
writer.ensureCapacity(str.length*4);
@@ -647,13 +629,7 @@ describe('Writer', () => {
647629

648630
test('matches TextEncoder output',()=>{
649631
constwriter=newWriter();
650-
consttestStrings=[
651-
'simple',
652-
'café',
653-
'日本語',
654-
'😀',
655-
'мир',
656-
];
632+
consttestStrings=['simple','café','日本語','😀','мир'];
657633

658634
for(conststroftestStrings){
659635
writer.newBuffer(str.length*4+1);
@@ -671,7 +647,7 @@ describe('Writer', () => {
671647
writer.u8(42);
672648
writer.u16(0x1234);
673649
writer.utf8('test');
674-
writer.u32(0xDEADBEEF);
650+
writer.u32(0xdeadbeef);
675651
expect(writer.x).toBeGreaterThan(0);
676652
});
677653

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp