@20syldev/api 4.0.0 → 4.1.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.
Files changed (45) hide show
  1. package/README.md +3 -3
  2. package/docs/changelog.md +333 -0
  3. package/package.json +5 -4
  4. package/src/app.ts +7 -3
  5. package/src/config/versions.ts +22 -10
  6. package/src/constants.ts +19 -0
  7. package/src/middleware/cors.ts +1 -1
  8. package/src/modules/v4/algorithms.ts +43 -1
  9. package/src/modules/v4/chat.ts +24 -1
  10. package/src/modules/v4/dice.ts +39 -0
  11. package/src/modules/v4/encode.ts +170 -0
  12. package/src/modules/v4/geo.ts +53 -0
  13. package/src/modules/v4/palette.ts +103 -0
  14. package/src/modules/v4/placeholder.ts +122 -0
  15. package/src/modules/v4/statistics.ts +55 -0
  16. package/src/modules/v4/text.ts +300 -0
  17. package/src/modules/v4/tic_tac_toe.ts +33 -1
  18. package/src/modules/v4/validate.ts +55 -0
  19. package/src/modules/v4.ts +2 -0
  20. package/src/routes/delete.ts +72 -0
  21. package/src/routes/get.ts +47 -0
  22. package/src/routes/index.ts +2 -2
  23. package/src/routes/patch.ts +45 -0
  24. package/src/utils/version.ts +5 -0
  25. package/tests/integration/api.test.ts +395 -0
  26. package/tests/tsconfig.json +3 -0
  27. package/tests/unit/algorithms.test.ts +120 -0
  28. package/tests/unit/color.test.ts +33 -0
  29. package/tests/unit/convert.test.ts +42 -0
  30. package/tests/unit/dice.test.ts +57 -0
  31. package/tests/unit/domain.test.ts +47 -0
  32. package/tests/unit/encode.test.ts +108 -0
  33. package/tests/unit/geo.test.ts +45 -0
  34. package/tests/unit/hash.test.ts +37 -0
  35. package/tests/unit/hyperplanning.test.ts +77 -0
  36. package/tests/unit/levenshtein.test.ts +34 -0
  37. package/tests/unit/palette.test.ts +53 -0
  38. package/tests/unit/personal.test.ts +65 -0
  39. package/tests/unit/statistics.test.ts +57 -0
  40. package/tests/unit/text.test.ts +107 -0
  41. package/tests/unit/time.test.ts +67 -0
  42. package/tests/unit/token.test.ts +61 -0
  43. package/tests/unit/username.test.ts +34 -0
  44. package/tests/unit/validate.test.ts +71 -0
  45. package/tsconfig.test.json +9 -0
@@ -0,0 +1,67 @@
1
+ import { test, describe } from 'node:test';
2
+ import { strict as assert } from 'node:assert';
3
+ import time from '../../src/modules/v4/time.js';
4
+
5
+ describe('time', () => {
6
+ test('live returns full set of formats', () => {
7
+ const result = time('live');
8
+ const fields = [
9
+ 'iso',
10
+ 'utc',
11
+ 'timestamp',
12
+ 'locale',
13
+ 'date',
14
+ 'time',
15
+ 'year',
16
+ 'month',
17
+ 'day',
18
+ 'hour',
19
+ 'minute',
20
+ 'second',
21
+ 'ms',
22
+ 'dayOfWeek',
23
+ 'dayOfYear',
24
+ 'weekNumber',
25
+ 'timezone',
26
+ 'timezoneOffset',
27
+ ];
28
+ for (const f of fields) {
29
+ assert.ok(f in result, `missing field: ${f}`);
30
+ }
31
+ });
32
+
33
+ test('iso is parseable', () => {
34
+ const result = time('live');
35
+ assert.ok(!isNaN(Date.parse(result.iso as string)));
36
+ });
37
+
38
+ test('format=year returns only date', () => {
39
+ const result = time('live', undefined, undefined, 'year');
40
+ assert.ok('date' in result);
41
+ assert.equal(typeof result.date, 'number');
42
+ });
43
+
44
+ test('random within range', () => {
45
+ const result = time('random', '2020-01-01', '2020-12-31');
46
+ const ts = result.timestamp as number;
47
+ assert.ok(ts >= new Date('2020-01-01').getTime());
48
+ assert.ok(ts <= new Date('2020-12-31').getTime());
49
+ });
50
+
51
+ test('throws on invalid type', () => {
52
+ assert.throws(() => time('foo'), /valid type/);
53
+ });
54
+
55
+ test('throws on invalid format', () => {
56
+ assert.throws(() => time('live', undefined, undefined, 'fakeformat'), /valid format/);
57
+ });
58
+
59
+ test('throws on invalid timezone', () => {
60
+ assert.throws(() => time('live', undefined, undefined, undefined, 'Mars/Olympus'), /valid timezone/);
61
+ });
62
+
63
+ test('Europe/Paris timezone', () => {
64
+ const result = time('live', undefined, undefined, undefined, 'Europe/Paris');
65
+ assert.equal(result.timezone, 'Europe/Paris');
66
+ });
67
+ });
@@ -0,0 +1,61 @@
1
+ import { test, describe } from 'node:test';
2
+ import { strict as assert } from 'node:assert';
3
+ import token from '../../src/modules/v4/token.js';
4
+
5
+ describe('token', () => {
6
+ test('alpha length', () => {
7
+ const t = token(24, 'alpha');
8
+ assert.equal(t.length, 24);
9
+ assert.match(t, /^[a-zA-Z]+$/);
10
+ });
11
+
12
+ test('alphanum length', () => {
13
+ const t = token(32, 'alphanum');
14
+ assert.equal(t.length, 32);
15
+ assert.match(t, /^[a-zA-Z0-9]+$/);
16
+ });
17
+
18
+ test('hex contains only hex chars', () => {
19
+ const t = token(16, 'hex');
20
+ assert.equal(t.length, 16);
21
+ assert.match(t, /^[0-9a-f]+$/);
22
+ });
23
+
24
+ test('num contains only digits', () => {
25
+ const t = token(20, 'num');
26
+ assert.match(t, /^\d+$/);
27
+ });
28
+
29
+ test('urlsafe chars only', () => {
30
+ const t = token(40, 'urlsafe');
31
+ assert.match(t, /^[a-zA-Z0-9_-]+$/);
32
+ });
33
+
34
+ test('uuid type produces hex', () => {
35
+ const t = token(32, 'uuid');
36
+ assert.equal(t.length, 32);
37
+ });
38
+
39
+ test('default type alphanum', () => {
40
+ const t = token(20);
41
+ assert.match(t, /^[a-zA-Z0-9]+$/);
42
+ });
43
+
44
+ test('throws below minimum length', () => {
45
+ assert.throws(() => token(5, 'alpha'), /greater than or equal to 12/);
46
+ });
47
+
48
+ test('throws above maximum length', () => {
49
+ assert.throws(() => token(5000, 'alpha'), /4096/);
50
+ });
51
+
52
+ test('throws on invalid type', () => {
53
+ assert.throws(() => token(20, 'martian'), /Invalid token type/);
54
+ });
55
+
56
+ test('two tokens are different (entropy check)', () => {
57
+ const a = token(32, 'alphanum');
58
+ const b = token(32, 'alphanum');
59
+ assert.notEqual(a, b);
60
+ });
61
+ });
@@ -0,0 +1,34 @@
1
+ import { test, describe } from 'node:test';
2
+ import { strict as assert } from 'node:assert';
3
+ import username from '../../src/modules/v4/username.js';
4
+
5
+ describe('username', () => {
6
+ test('returns expected fields', () => {
7
+ const result = username();
8
+ assert.ok('username' in result);
9
+ assert.ok('number' in result);
10
+ assert.ok('adjective' in result);
11
+ assert.ok('animal' in result);
12
+ assert.ok('job' in result);
13
+ });
14
+
15
+ test('username is a non-empty string', () => {
16
+ const result = username();
17
+ assert.equal(typeof result.username, 'string');
18
+ assert.ok((result.username as string).length > 0);
19
+ });
20
+
21
+ test('number is between 0 and 99', () => {
22
+ const result = username();
23
+ const n = result.number as number;
24
+ assert.ok(n >= 0 && n <= 99);
25
+ });
26
+
27
+ test('produces varied usernames', () => {
28
+ const seen = new Set<string>();
29
+ for (let i = 0; i < 10; i++) {
30
+ seen.add(username().username as string);
31
+ }
32
+ assert.ok(seen.size > 1);
33
+ });
34
+ });
@@ -0,0 +1,71 @@
1
+ import { test, describe } from 'node:test';
2
+ import { strict as assert } from 'node:assert';
3
+ import { luhn, iban, email } from '../../src/modules/v4/validate.js';
4
+
5
+ describe('validate', () => {
6
+ describe('luhn', () => {
7
+ test('valid Visa test card', () => {
8
+ const result = luhn('4111111111111111');
9
+ assert.equal(result.valid, true);
10
+ });
11
+
12
+ test('invalid card number', () => {
13
+ const result = luhn('4111111111111112');
14
+ assert.equal(result.valid, false);
15
+ });
16
+
17
+ test('strips spaces and dashes', () => {
18
+ const result = luhn('4111-1111 1111-1111');
19
+ assert.equal(result.valid, true);
20
+ assert.equal(result.value, '4111111111111111');
21
+ });
22
+
23
+ test('throws on non-digit', () => {
24
+ assert.throws(() => luhn('4111ABC11111111'), /only digits/);
25
+ });
26
+
27
+ test('throws on too short', () => {
28
+ assert.throws(() => luhn('411111'), /between 12 and 19/);
29
+ });
30
+ });
31
+
32
+ describe('iban', () => {
33
+ test('valid French IBAN', () => {
34
+ const result = iban('FR1420041010050500013M02606');
35
+ assert.equal(result.valid, true);
36
+ assert.equal(result.country, 'FR');
37
+ });
38
+
39
+ test('invalid checksum', () => {
40
+ const result = iban('FR1420041010050500013M02607');
41
+ assert.equal(result.valid, false);
42
+ });
43
+
44
+ test('strips spaces', () => {
45
+ const result = iban('FR14 2004 1010 0505 0001 3M02 606');
46
+ assert.equal(result.valid, true);
47
+ });
48
+
49
+ test('throws on bad format', () => {
50
+ assert.throws(() => iban('1234'), /Invalid IBAN format/);
51
+ });
52
+ });
53
+
54
+ describe('email', () => {
55
+ test('valid email', () => {
56
+ assert.equal(email('hello@example.com').valid, true);
57
+ });
58
+
59
+ test('rejects missing domain', () => {
60
+ assert.equal(email('hello@').valid, false);
61
+ });
62
+
63
+ test('rejects missing @', () => {
64
+ assert.equal(email('helloexample.com').valid, false);
65
+ });
66
+
67
+ test('rejects spaces', () => {
68
+ assert.equal(email('hello world@example.com').valid, false);
69
+ });
70
+ });
71
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": ".",
5
+ "noEmit": true,
6
+ "types": ["node"]
7
+ },
8
+ "include": ["src", "tests"]
9
+ }