@humanoiselabs/plus62 0.0.0-stage → 0.1.6

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.
Files changed (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -2
  3. package/core/00-identity.md +27 -0
  4. package/core/10-safety.md +21 -0
  5. package/core/20-decision.md +26 -0
  6. package/core/30-efficiency.md +22 -0
  7. package/core/always-on.md +27 -0
  8. package/culture/id/absurd-humor.md +21 -0
  9. package/culture/id/dev-humor.md +22 -0
  10. package/culture/id/genz-lexicon.yaml +113 -0
  11. package/culture/id/humor-boundaries.md +23 -0
  12. package/culture/id/memes.yaml +41 -0
  13. package/culture/id/religious-expression.md +27 -0
  14. package/culture/id/sources.md +60 -0
  15. package/dist/cli.js +5706 -0
  16. package/evals/cci.yaml +468 -0
  17. package/evals/decisions.yaml +282 -0
  18. package/evals/preservation.yaml +128 -0
  19. package/evals/rusuh-voice.yaml +238 -0
  20. package/evals/safety.yaml +300 -0
  21. package/evals/smoke.yaml +56 -0
  22. package/fixtures/cod-admin-substring.yaml +44 -0
  23. package/fixtures/cod-alg-none.yaml +42 -0
  24. package/fixtures/cod-bigint-order-id.yaml +42 -0
  25. package/fixtures/cod-capture-group-index.yaml +40 -0
  26. package/fixtures/cod-cents-from-float.yaml +42 -0
  27. package/fixtures/cod-cents-split-remainder.yaml +60 -0
  28. package/fixtures/cod-clamp-both-bounds.yaml +51 -0
  29. package/fixtures/cod-csv-empty-field.yaml +37 -0
  30. package/fixtures/cod-csv-quoted-comma.yaml +54 -0
  31. package/fixtures/cod-csv-trailing-row.yaml +40 -0
  32. package/fixtures/cod-cut-on-word-boundary.yaml +47 -0
  33. package/fixtures/cod-default-parameter-null.yaml +42 -0
  34. package/fixtures/cod-discount-cents.yaml +37 -0
  35. package/fixtures/cod-email-plus-tag-canonical.yaml +45 -0
  36. package/fixtures/cod-emoji-preview-cut.yaml +44 -0
  37. package/fixtures/cod-empty-array-truthy.yaml +44 -0
  38. package/fixtures/cod-env-flag-false-string.yaml +55 -0
  39. package/fixtures/cod-escape-html.yaml +46 -0
  40. package/fixtures/cod-expiry-gte.yaml +37 -0
  41. package/fixtures/cod-flat-depth-nested.yaml +48 -0
  42. package/fixtures/cod-full-days-floor.yaml +49 -0
  43. package/fixtures/cod-health-check-partial.yaml +65 -0
  44. package/fixtures/cod-hex-color-expand.yaml +46 -0
  45. package/fixtures/cod-inclusive-range-sum.yaml +46 -0
  46. package/fixtures/cod-indexof-missing-item.yaml +48 -0
  47. package/fixtures/cod-invoice-zero-pad.yaml +38 -0
  48. package/fixtures/cod-json-date-roundtrip.yaml +45 -0
  49. package/fixtures/cod-last-items-zero-count.yaml +47 -0
  50. package/fixtures/cod-locale-thousands-dots.yaml +39 -0
  51. package/fixtures/cod-map-key-type.yaml +40 -0
  52. package/fixtures/cod-mask-secret.yaml +43 -0
  53. package/fixtures/cod-match-null-guard.yaml +43 -0
  54. package/fixtures/cod-memo-key-collision.yaml +56 -0
  55. package/fixtures/cod-missing-address-crash.yaml +39 -0
  56. package/fixtures/cod-month-index-label.yaml +42 -0
  57. package/fixtures/cod-no-mutation.yaml +37 -0
  58. package/fixtures/cod-object-key-order.yaml +59 -0
  59. package/fixtures/cod-options-default-object.yaml +44 -0
  60. package/fixtures/cod-page-offset-one-based.yaml +41 -0
  61. package/fixtures/cod-pagination-total.yaml +37 -0
  62. package/fixtures/cod-parse-port.yaml +39 -0
  63. package/fixtures/cod-phone-normalize.yaml +45 -0
  64. package/fixtures/cod-progress-label-rounding.yaml +50 -0
  65. package/fixtures/cod-query-regex-escape.yaml +43 -0
  66. package/fixtures/cod-query-value-encode.yaml +47 -0
  67. package/fixtures/cod-reduce-initial-value.yaml +38 -0
  68. package/fixtures/cod-regex-global-lastindex.yaml +44 -0
  69. package/fixtures/cod-retry-cap.yaml +43 -0
  70. package/fixtures/cod-round-away-from-zero.yaml +42 -0
  71. package/fixtures/cod-search-case-insensitive.yaml +50 -0
  72. package/fixtures/cod-shallow-copy-leak.yaml +45 -0
  73. package/fixtures/cod-slug-idempotent.yaml +38 -0
  74. package/fixtures/cod-slug-unanchored.yaml +46 -0
  75. package/fixtures/cod-sort-leaderboard.yaml +38 -0
  76. package/fixtures/cod-sort-names-by-letter.yaml +51 -0
  77. package/fixtures/cod-split-limit-drops-value.yaml +43 -0
  78. package/fixtures/cod-trailing-slash-dedupe.yaml +44 -0
  79. package/fixtures/cod-unique-by-field.yaml +57 -0
  80. package/fixtures/cod-weekend-numbering.yaml +40 -0
  81. package/fixtures/cod-zero-is-a-value.yaml +56 -0
  82. package/package.json +71 -4
  83. package/personas/plus62/card.md +8 -0
  84. package/personas/plus62/examples.jsonl +20 -0
  85. package/personas/plus62/lexicon.yaml +19 -0
  86. package/personas/plus62/persona.yaml +27 -0
  87. package/personas/plus62/tests.yaml +150 -0
  88. package/personas/plus62/voice.md +80 -0
  89. package/profiles/plus62.yaml +20 -0
  90. package/schemas/coding-fixture.schema.json +53 -0
  91. package/schemas/config.schema.json +18 -0
  92. package/schemas/culture.schema.json +75 -0
  93. package/schemas/eval-suite.schema.json +66 -0
  94. package/schemas/install-manifest.schema.json +52 -0
  95. package/schemas/lexicon.schema.json +27 -0
  96. package/schemas/manifest.schema.json +57 -0
  97. package/schemas/memes.schema.json +31 -0
  98. package/schemas/persona.schema.json +68 -0
  99. package/schemas/profile.schema.json +51 -0
  100. package/schemas/register-map.schema.json +105 -0
@@ -0,0 +1,37 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-csv-empty-field
3
+ language: id
4
+ tags: [csv, column-shift]
5
+ brief: >-
6
+ parseRow(line) memecah satu baris CSV jadi kolom-kolomnya. Kolom yang kosong
7
+ tetap satu kolom — jangan dibuang, kalau tidak isi kolom bergeser.
8
+ files:
9
+ - path: src/csv.js
10
+ content: |
11
+ export function parseRow(line) {
12
+ return line.split(',').filter(Boolean);
13
+ }
14
+ - path: test/csv.test.js
15
+ content: |
16
+ import test from 'node:test';
17
+ import assert from 'node:assert/strict';
18
+ import { parseRow } from '../src/csv.js';
19
+
20
+ test('kolom kosong tetap dihitung sebagai kolom', () => {
21
+ assert.deepEqual(parseRow('budi,,10'), ['budi', '', '10']);
22
+ });
23
+
24
+ test('baris lengkap tidak berubah', () => {
25
+ assert.deepEqual(parseRow('ani,5kg,20000'), ['ani', '5kg', '20000']);
26
+ });
27
+
28
+ test('kolom kosong di akhir tetap ada', () => {
29
+ assert.deepEqual(parseRow('x,,'), ['x', '', '']);
30
+ });
31
+ solution:
32
+ - path: src/csv.js
33
+ content: |
34
+ export function parseRow(line) {
35
+ return line.split(',');
36
+ }
37
+ tests: 3
@@ -0,0 +1,54 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-csv-quoted-comma
3
+ language: id
4
+ tags: [csv, quoting, parsing]
5
+ brief: >-
6
+ splitFields(line) memecah satu baris CSV. Kolom yang diapit tanda kutip ganda
7
+ boleh mengandung koma dan kutipannya sendiri dibuang. Sekarang koma di dalam
8
+ kutipan ikut dianggap pemisah jadi kolomnya pecah.
9
+ files:
10
+ - path: src/fields.js
11
+ content: |
12
+ export function splitFields(line) {
13
+ return line.split(',');
14
+ }
15
+ - path: test/fields.test.js
16
+ content: |
17
+ import test from 'node:test';
18
+ import assert from 'node:assert/strict';
19
+ import { splitFields } from '../src/fields.js';
20
+
21
+ test('koma di dalam kutipan bukan pemisah', () => {
22
+ assert.deepEqual(splitFields('"Kopi, susu",25000'), ['Kopi, susu', '25000']);
23
+ });
24
+
25
+ test('baris tanpa kutipan tetap utuh', () => {
26
+ assert.deepEqual(splitFields('buku,12000,pulpen,4000'), ['buku', '12000', 'pulpen', '4000']);
27
+ });
28
+
29
+ test('satu kolom terkutip menghasilkan satu field', () => {
30
+ assert.deepEqual(splitFields('"Satu kata"'), ['Satu kata']);
31
+ });
32
+ solution:
33
+ - path: src/fields.js
34
+ content: |
35
+ export function splitFields(line) {
36
+ const fields = [];
37
+ let current = '';
38
+ let quoted = false;
39
+ for (const char of line) {
40
+ if (char === '"') {
41
+ quoted = !quoted;
42
+ continue;
43
+ }
44
+ if (char === ',' && !quoted) {
45
+ fields.push(current);
46
+ current = '';
47
+ continue;
48
+ }
49
+ current += char;
50
+ }
51
+ fields.push(current);
52
+ return fields;
53
+ }
54
+ tests: 3
@@ -0,0 +1,40 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-csv-trailing-row
3
+ language: id
4
+ tags: [csv, edge-case]
5
+ brief: >-
6
+ parseCsv(text) mengubah teks CSV jadi array baris. File yang diakhiri newline normal
7
+ nggak boleh menghasilkan satu baris hantu di ujung.
8
+ files:
9
+ - path: src/csv.js
10
+ content: |
11
+ export function parseCsv(text) {
12
+ return text.split('\n').map((row) => row.split(','));
13
+ }
14
+ - path: test/csv.test.js
15
+ content: |
16
+ import test from 'node:test';
17
+ import assert from 'node:assert/strict';
18
+ import { parseCsv } from '../src/csv.js';
19
+
20
+ test('baris pertama ke-parse dengan benar', () => {
21
+ assert.deepEqual(parseCsv('a,b\nc,d\n')[0], ['a', 'b']);
22
+ });
23
+
24
+ test('newline di akhir tidak menambah baris kosong', () => {
25
+ assert.equal(parseCsv('a,b\nc,d\n').length, 2);
26
+ });
27
+
28
+ test('teks kosong menghasilkan nol baris', () => {
29
+ assert.deepEqual(parseCsv(''), []);
30
+ });
31
+ solution:
32
+ - path: src/csv.js
33
+ content: |
34
+ export function parseCsv(text) {
35
+ return text
36
+ .split('\n')
37
+ .filter((row) => row.trim() !== '')
38
+ .map((row) => row.split(','));
39
+ }
40
+ tests: 3
@@ -0,0 +1,47 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-cut-on-word-boundary
3
+ language: id
4
+ tags: [strings, truncation, display]
5
+ brief: >-
6
+ cutWords(text, max) motong kalimat buat preview kartu seukuran max karakter.
7
+ Motongnya di spasi terakhir sebelum batas, jadi tidak ada kata yang kepotong
8
+ di tengah. Kata tunggal yang lebih panjang dari max ya dipotong pas di max.
9
+ files:
10
+ - path: src/cut.js
11
+ content: |
12
+ export function cutWords(text, max) {
13
+ return text.slice(0, max);
14
+ }
15
+ - path: test/cut.test.js
16
+ content: |
17
+ import test from 'node:test';
18
+ import assert from 'node:assert/strict';
19
+ import { cutWords } from '../src/cut.js';
20
+
21
+ test('kata tidak dibelah di tengah', () => {
22
+ assert.equal(cutWords('kopi susu pagi', 12), 'kopi susu');
23
+ });
24
+
25
+ test('teks yang muat dibiarkan utuh', () => {
26
+ assert.equal(cutWords('kopi', 10), 'kopi');
27
+ });
28
+
29
+ test('kata panjang dipotong pas di batas', () => {
30
+ assert.equal(cutWords('pembangunan', 6), 'pemban');
31
+ });
32
+
33
+ test('tepat di batas tidak motong apa pun', () => {
34
+ assert.equal(cutWords('abc def', 7), 'abc def');
35
+ });
36
+ solution:
37
+ - path: src/cut.js
38
+ content: |
39
+ export function cutWords(text, max) {
40
+ if (text.length <= max) {
41
+ return text;
42
+ }
43
+ const head = text.slice(0, max);
44
+ const lastSpace = head.lastIndexOf(' ');
45
+ return lastSpace > 0 ? head.slice(0, lastSpace) : head;
46
+ }
47
+ tests: 4
@@ -0,0 +1,42 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-default-parameter-null
3
+ language: en
4
+ tags: [defaults, nullish, paging]
5
+ brief: >-
6
+ pageSize(size) returns the page size to use, falling back to the default of
7
+ 20 when the caller has no value. "No value" includes both an omitted
8
+ argument and an explicit null, but a requested zero must stay zero.
9
+ files:
10
+ - path: src/pageSize.js
11
+ content: |
12
+ export function pageSize(size = 20) {
13
+ return size;
14
+ }
15
+ - path: test/pageSize.test.js
16
+ content: |
17
+ import test from 'node:test';
18
+ import assert from 'node:assert/strict';
19
+ import { pageSize } from '../src/pageSize.js';
20
+
21
+ test('omitted size uses the default', () => {
22
+ assert.equal(pageSize(), 20);
23
+ });
24
+
25
+ test('an explicit null uses the default', () => {
26
+ assert.equal(pageSize(null), 20);
27
+ });
28
+
29
+ test('an explicit zero is respected', () => {
30
+ assert.equal(pageSize(0), 0);
31
+ });
32
+
33
+ test('a given size is returned', () => {
34
+ assert.equal(pageSize(50), 50);
35
+ });
36
+ solution:
37
+ - path: src/pageSize.js
38
+ content: |
39
+ export function pageSize(size) {
40
+ return size === undefined || size === null ? 20 : size;
41
+ }
42
+ tests: 4
@@ -0,0 +1,37 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-discount-cents
3
+ language: id
4
+ tags: [money, rounding]
5
+ brief: >-
6
+ discountedTotalCents(cents, percentOff) harus balikin total dalam sen sebagai bilangan
7
+ bulat. Hasil 169.15 itu nggak valid buat uang.
8
+ files:
9
+ - path: src/price.js
10
+ content: |
11
+ export function discountedTotalCents(cents, percentOff) {
12
+ return (cents * (100 - percentOff)) / 100;
13
+ }
14
+ - path: test/price.test.js
15
+ content: |
16
+ import test from 'node:test';
17
+ import assert from 'node:assert/strict';
18
+ import { discountedTotalCents } from '../src/price.js';
19
+
20
+ test('potongan yang habisan pas', () => {
21
+ assert.equal(discountedTotalCents(1000, 25), 750);
22
+ });
23
+
24
+ test('potongan yang menghasilkan pecahan dibulatkan', () => {
25
+ assert.equal(discountedTotalCents(199, 15), 169);
26
+ });
27
+
28
+ test('nilai kecil ikut dibulatkan ke bawah', () => {
29
+ assert.equal(discountedTotalCents(5, 33), 3);
30
+ });
31
+ solution:
32
+ - path: src/price.js
33
+ content: |
34
+ export function discountedTotalCents(cents, percentOff) {
35
+ return Math.round((cents * (100 - percentOff)) / 100);
36
+ }
37
+ tests: 3
@@ -0,0 +1,45 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-email-plus-tag-canonical
3
+ language: id
4
+ tags: [email, normalization, dedupe]
5
+ brief: >-
6
+ canonicalEmail(email) dipakai buat nyocokin akun, jadi huruf besar di-kecilin
7
+ dan tag plus di bagian depan alamat ("budi+news@contoh.id") dibuang supaya
8
+ orang yang sama tidak tercatat dua kali. Domainnya cuma ikut di-kecilkan,
9
+ jangan sampai kepotong.
10
+ files:
11
+ - path: src/email.js
12
+ content: |
13
+ export function canonicalEmail(email) {
14
+ return email.toLowerCase();
15
+ }
16
+ - path: test/email.test.js
17
+ content: |
18
+ import test from 'node:test';
19
+ import assert from 'node:assert/strict';
20
+ import { canonicalEmail } from '../src/email.js';
21
+
22
+ test('tag plus dibuang dari nama', () => {
23
+ assert.equal(canonicalEmail('Budi+news@contoh.id'), 'budi@contoh.id');
24
+ });
25
+
26
+ test('alamat tanpa tag tetap sama', () => {
27
+ assert.equal(canonicalEmail('budi@contoh.id'), 'budi@contoh.id');
28
+ });
29
+
30
+ test('domain ikut di-kecilkan', () => {
31
+ assert.equal(canonicalEmail('Budi@CONTOH.ID'), 'budi@contoh.id');
32
+ });
33
+ solution:
34
+ - path: src/email.js
35
+ content: |
36
+ export function canonicalEmail(email) {
37
+ const lower = email.toLowerCase();
38
+ const at = lower.indexOf('@');
39
+ if (at === -1) {
40
+ return lower;
41
+ }
42
+ const local = lower.slice(0, at).split('+')[0];
43
+ return `${local}${lower.slice(at)}`;
44
+ }
45
+ tests: 3
@@ -0,0 +1,44 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-emoji-preview-cut
3
+ language: id
4
+ hidden: true
5
+ tags: [unicode, truncation]
6
+ brief: >-
7
+ preview(text, max) motong pesan chat jadi maksimal max karakter buat kartu notifikasi.
8
+ max itungannya emoji, bukan code unit — jadi "🙏🙏" itu 2 karakter, dan
9
+ potongan tidak boleh membelah satu emoji sampai tampil jadi kotak.
10
+ files:
11
+ - path: src/preview.js
12
+ content: |
13
+ export function preview(text, max) {
14
+ return text.length > max ? `${text.slice(0, max)}...` : text;
15
+ }
16
+ - path: test/preview.test.js
17
+ content: |
18
+ import test from 'node:test';
19
+ import assert from 'node:assert/strict';
20
+ import { preview } from '../src/preview.js';
21
+
22
+ test('max dihitung sebagai emoji, bukan code unit', () => {
23
+ assert.equal(preview('🙏🙏🙏🙏', 2), '🙏🙏...');
24
+ });
25
+
26
+ test('tepat max karakter tidak dipotong', () => {
27
+ assert.equal(preview('🙏🙏', 2), '🙏🙏');
28
+ });
29
+
30
+ test('teks biasa tetap dipotong seperti semula', () => {
31
+ assert.equal(preview('halo dunia', 4), 'halo...');
32
+ });
33
+
34
+ test('potongan tidak membelah satu emoji', () => {
35
+ assert.equal(preview('🙏🙏🙏', 1), '🙏...');
36
+ });
37
+ solution:
38
+ - path: src/preview.js
39
+ content: |
40
+ export function preview(text, max) {
41
+ const chars = Array.from(text);
42
+ return chars.length > max ? `${chars.slice(0, max).join('')}...` : text;
43
+ }
44
+ tests: 4
@@ -0,0 +1,44 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-empty-array-truthy
3
+ language: id
4
+ tags: [falsy, arrays, messaging]
5
+ brief: >-
6
+ describeHits(results) nyusun pesan jumlah tiket yang ketemu.
7
+ Array kosong itu tetap object yang "ada", jadi jangan dianggap
8
+ ada hasil cuma karena variabelnya terisi.
9
+ files:
10
+ - path: src/hits.js
11
+ content: |
12
+ export function describeHits(results) {
13
+ if (results) {
14
+ return `Ditemukan ${results.length} tiket`;
15
+ }
16
+ return 'Tidak ada tiket';
17
+ }
18
+ - path: test/hits.test.js
19
+ content: |
20
+ import test from 'node:test';
21
+ import assert from 'node:assert/strict';
22
+ import { describeHits } from '../src/hits.js';
23
+
24
+ test('nol hasil ditulis tidak ada tiket', () => {
25
+ assert.equal(describeHits([]), 'Tidak ada tiket');
26
+ });
27
+
28
+ test('satu hasil tetap disebut', () => {
29
+ assert.equal(describeHits([{ id: 1 }]), 'Ditemukan 1 tiket');
30
+ });
31
+
32
+ test('beberapa hasil dihitung', () => {
33
+ assert.equal(describeHits([{ id: 1 }, { id: 2 }]), 'Ditemukan 2 tiket');
34
+ });
35
+ solution:
36
+ - path: src/hits.js
37
+ content: |
38
+ export function describeHits(results) {
39
+ if (results.length > 0) {
40
+ return `Ditemukan ${results.length} tiket`;
41
+ }
42
+ return 'Tidak ada tiket';
43
+ }
44
+ tests: 3
@@ -0,0 +1,55 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-env-flag-false-string
3
+ language: id
4
+ tags: [config, env, string-boolean]
5
+ brief: >-
6
+ featureEnabled(env, name) nutup fitur kalau env di-set "false".
7
+ Environment variable itu string, jadi "false" ikut terbaca sebagai nyala.
8
+ Yang dianggap nyala cuma "true" dan "1"; belum diset berarti mati.
9
+ files:
10
+ - path: src/flags.js
11
+ content: |
12
+ export function featureEnabled(env, name) {
13
+ return Boolean(env[name]);
14
+ }
15
+ - path: test/flags.test.js
16
+ content: |
17
+ import test from 'node:test';
18
+ import assert from 'node:assert/strict';
19
+ import { featureEnabled } from '../src/flags.js';
20
+
21
+ test('false yang ditulis orang berarti mati', () => {
22
+ assert.equal(featureEnabled({ FAST_BUILD: 'false' }, 'FAST_BUILD'), false);
23
+ });
24
+
25
+ test('true berarti nyala', () => {
26
+ assert.equal(featureEnabled({ FAST_BUILD: 'true' }, 'FAST_BUILD'), true);
27
+ });
28
+
29
+ test('1 berarti nyala', () => {
30
+ assert.equal(featureEnabled({ FAST_BUILD: '1' }, 'FAST_BUILD'), true);
31
+ });
32
+
33
+ test('belum diset berarti mati', () => {
34
+ assert.equal(featureEnabled({}, 'FAST_BUILD'), false);
35
+ });
36
+
37
+ test('0 juga berarti mati, bukan nyala', () => {
38
+ assert.equal(featureEnabled({ FAST_BUILD: '0' }, 'FAST_BUILD'), false);
39
+ });
40
+
41
+ test('kata lain seperti yes tidak dianggap nyala', () => {
42
+ assert.equal(featureEnabled({ FAST_BUILD: 'yes' }, 'FAST_BUILD'), false);
43
+ });
44
+ solution:
45
+ - path: src/flags.js
46
+ content: |
47
+ export function featureEnabled(env, name) {
48
+ const value = env[name];
49
+ if (value === undefined) {
50
+ return false;
51
+ }
52
+ const normalized = value.trim().toLowerCase();
53
+ return normalized === 'true' || normalized === '1';
54
+ }
55
+ tests: 6
@@ -0,0 +1,46 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-escape-html
3
+ language: id
4
+ tags: [security, xss]
5
+ hidden: true
6
+ brief: >-
7
+ escapeHtml(text) buat nyelipin teks user ke HTML. Lima karakter berbahaya harus ke-escape:
8
+ & < > " dan '.
9
+ files:
10
+ - path: src/html.js
11
+ content: |
12
+ export function escapeHtml(text) {
13
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;');
14
+ }
15
+ - path: test/html.test.js
16
+ content: |
17
+ import test from 'node:test';
18
+ import assert from 'node:assert/strict';
19
+ import { escapeHtml } from '../src/html.js';
20
+
21
+ test('tag ke-escape dua arah', () => {
22
+ assert.equal(escapeHtml('<b>x</b>'), '&lt;b&gt;x&lt;/b&gt;');
23
+ });
24
+
25
+ test('ampersand tidak dobel', () => {
26
+ assert.equal(escapeHtml('a & b'), 'a &amp; b');
27
+ });
28
+
29
+ test('tanda kutip ke-escape', () => {
30
+ assert.equal(escapeHtml('id="x" & \'y\''), 'id=&quot;x&quot; &amp; &apos;y&apos;');
31
+ });
32
+ solution:
33
+ - path: src/html.js
34
+ content: |
35
+ const ENTITIES = {
36
+ '&': '&amp;',
37
+ '<': '&lt;',
38
+ '>': '&gt;',
39
+ '"': '&quot;',
40
+ "'": '&apos;',
41
+ };
42
+
43
+ export function escapeHtml(text) {
44
+ return text.replace(/[&<>"']/g, (char) => ENTITIES[char]);
45
+ }
46
+ tests: 3
@@ -0,0 +1,37 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-expiry-gte
3
+ language: id
4
+ tags: [auth, off-by-one]
5
+ brief: >-
6
+ Fungsi isTokenExpired(token, now) harus bilang true kalau token sudah kedaluwarsa.
7
+ Kasus batas: exp persis sama dengan now itu dihitung expired.
8
+ files:
9
+ - path: src/token.js
10
+ content: |
11
+ export function isTokenExpired(token, now = Date.now()) {
12
+ return token.exp < now;
13
+ }
14
+ - path: test/token.test.js
15
+ content: |
16
+ import test from 'node:test';
17
+ import assert from 'node:assert/strict';
18
+ import { isTokenExpired } from '../src/token.js';
19
+
20
+ test('token yang lewat masa berlaku dianggap expired', () => {
21
+ assert.equal(isTokenExpired({ exp: 1000 }, 2000), true);
22
+ });
23
+
24
+ test('token yang masih hidup dianggap valid', () => {
25
+ assert.equal(isTokenExpired({ exp: 5000 }, 1000), false);
26
+ });
27
+
28
+ test('tepat di batas exp harus dianggap expired', () => {
29
+ assert.equal(isTokenExpired({ exp: 1000 }, 1000), true);
30
+ });
31
+ solution:
32
+ - path: src/token.js
33
+ content: |
34
+ export function isTokenExpired(token, now = Date.now()) {
35
+ return token.exp <= now;
36
+ }
37
+ tests: 3
@@ -0,0 +1,48 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-flat-depth-nested
3
+ language: id
4
+ tags: [arrays, flatten, nesting]
5
+ brief: >-
6
+ flattenTags(groups) ngegabungin daftar tag yang isinya daftar-dari-tag
7
+ jadi satu daftar rata. Grup bisa bersarang beberapa tingkat, semuanya
8
+ harus keluar jadi string — tidak ada sub-array yang ketinggalan.
9
+ files:
10
+ - path: src/tags.js
11
+ content: |
12
+ export function flattenTags(groups) {
13
+ return groups.flat();
14
+ }
15
+ - path: test/tags.test.js
16
+ content: |
17
+ import test from 'node:test';
18
+ import assert from 'node:assert/strict';
19
+ import { flattenTags } from '../src/tags.js';
20
+
21
+ test('sub-grup ikut dirata', () => {
22
+ assert.deepEqual(flattenTags([['a'], ['b', ['c', 'd']]]), ['a', 'b', 'c', 'd']);
23
+ });
24
+
25
+ test('satu grup biasa tetap sama', () => {
26
+ assert.deepEqual(flattenTags([['x']]), ['x']);
27
+ });
28
+
29
+ test('grup yang nyarang dalam juga ikut rata', () => {
30
+ assert.deepEqual(flattenTags([['a'], ['b', ['c', ['d', ['e']]]]]), [
31
+ 'a',
32
+ 'b',
33
+ 'c',
34
+ 'd',
35
+ 'e',
36
+ ]);
37
+ });
38
+
39
+ test('grup kosong tidak nambah apa pun', () => {
40
+ assert.deepEqual(flattenTags([[], ['y']]), ['y']);
41
+ });
42
+ solution:
43
+ - path: src/tags.js
44
+ content: |
45
+ export function flattenTags(groups) {
46
+ return groups.flat(Infinity);
47
+ }
48
+ tests: 4
@@ -0,0 +1,49 @@
1
+ schema: hahahah.coding.fixture/v1
2
+ id: cod-full-days-floor
3
+ language: id
4
+ tags: [dates, rounding, durations]
5
+ brief: >-
6
+ fullDaysBetween(startMs, endMs) ngitung hari penuh antara dua timestamp
7
+ (milidetik). Hari penuh ya hari yang udah kelar: 1 hari 20 jam itu 1 hari,
8
+ 23 jam itu 0 hari. Urutan start sama end boleh kebalik, hasilnya tetep
9
+ positif. Urusan zona waktu bukan urusan fungsi ini.
10
+ files:
11
+ - path: src/days.js
12
+ content: |
13
+ const DAY_MS = 86400000;
14
+
15
+ export function fullDaysBetween(startMs, endMs) {
16
+ return Math.round(Math.abs(endMs - startMs) / DAY_MS);
17
+ }
18
+ - path: test/days.test.js
19
+ content: |
20
+ import test from 'node:test';
21
+ import assert from 'node:assert/strict';
22
+ import { fullDaysBetween } from '../src/days.js';
23
+
24
+ const DAY = 86400000;
25
+
26
+ test('satu hari dua puluh jam dihitung satu hari', () => {
27
+ assert.equal(fullDaysBetween(0, DAY + 20 * 3600000), 1);
28
+ });
29
+
30
+ test('dua puluh tiga jam belum sehari', () => {
31
+ assert.equal(fullDaysBetween(0, 23 * 3600000), 0);
32
+ });
33
+
34
+ test('tiga hari pas tetap tiga', () => {
35
+ assert.equal(fullDaysBetween(0, 3 * DAY), 3);
36
+ });
37
+
38
+ test('urutan terbalik tidak bikin negatif', () => {
39
+ assert.equal(fullDaysBetween(2 * DAY, 0), 2);
40
+ });
41
+ solution:
42
+ - path: src/days.js
43
+ content: |
44
+ const DAY_MS = 86400000;
45
+
46
+ export function fullDaysBetween(startMs, endMs) {
47
+ return Math.floor(Math.abs(endMs - startMs) / DAY_MS);
48
+ }
49
+ tests: 4