mhs-lang 0.0.0-stage → 2.0.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 (51) hide show
  1. package/README.md +90 -2
  2. package/assets/logo.png +0 -0
  3. package/bin/mhs.js +171 -0
  4. package/examples/__pycache__/alat_py.cpython-312.pyc +0 -0
  5. package/examples/alat_py.py +7 -0
  6. package/examples/demo_lengkap.mhs +19 -0
  7. package/examples/halo.mhs +20 -0
  8. package/examples/python_native.mhs +16 -0
  9. package/examples/rumus_elektronika.mhs +10 -0
  10. package/examples/tes_semua_modul.mhs +48 -0
  11. package/examples/utama_impor.mhs +11 -0
  12. package/package.json +33 -4
  13. package/src/index.js +186 -0
  14. package/src/modules/berkas.js +19 -0
  15. package/src/modules/data_json.js +9 -0
  16. package/src/modules/index.js +29 -0
  17. package/src/modules/jaringan.js +28 -0
  18. package/src/modules/koleksi.js +43 -0
  19. package/src/modules/kripto.js +9 -0
  20. package/src/modules/matematika.js +55 -0
  21. package/src/modules/modul_acak.js +36 -0
  22. package/src/modules/pola.js +13 -0
  23. package/src/modules/sistem.js +13 -0
  24. package/src/modules/uji.js +52 -0
  25. package/src/modules/waktu.js +49 -0
  26. package/src/py_bridge.js +111 -0
  27. package/src/py_modules/__pycache__/berkas.cpython-312.pyc +0 -0
  28. package/src/py_modules/__pycache__/data_json.cpython-312.pyc +0 -0
  29. package/src/py_modules/__pycache__/jaringan.cpython-312.pyc +0 -0
  30. package/src/py_modules/__pycache__/koleksi.cpython-312.pyc +0 -0
  31. package/src/py_modules/__pycache__/kripto.cpython-312.pyc +0 -0
  32. package/src/py_modules/__pycache__/matematika.cpython-312.pyc +0 -0
  33. package/src/py_modules/__pycache__/modul_acak.cpython-312.pyc +0 -0
  34. package/src/py_modules/__pycache__/pola.cpython-312.pyc +0 -0
  35. package/src/py_modules/__pycache__/sistem.cpython-312.pyc +0 -0
  36. package/src/py_modules/__pycache__/uji.cpython-312.pyc +0 -0
  37. package/src/py_modules/__pycache__/waktu.cpython-312.pyc +0 -0
  38. package/src/py_modules/berkas.py +26 -0
  39. package/src/py_modules/data_json.py +14 -0
  40. package/src/py_modules/jaringan.py +15 -0
  41. package/src/py_modules/koleksi.py +24 -0
  42. package/src/py_modules/kripto.py +18 -0
  43. package/src/py_modules/matematika.py +30 -0
  44. package/src/py_modules/modul_acak.py +14 -0
  45. package/src/py_modules/pola.py +17 -0
  46. package/src/py_modules/sistem.py +11 -0
  47. package/src/py_modules/uji.py +39 -0
  48. package/src/py_modules/waktu.py +19 -0
  49. package/src/py_transpiler.js +231 -0
  50. package/src/stdlib.js +164 -0
  51. package/src/transpiler.js +401 -0
@@ -0,0 +1,29 @@
1
+ const matematika = require('./matematika');
2
+ const modul_acak = require('./modul_acak');
3
+ const waktu = require('./waktu');
4
+ const berkas = require('./berkas');
5
+ const sistem = require('./sistem');
6
+ const data_json = require('./data_json');
7
+ const pola = require('./pola');
8
+ const koleksi = require('./koleksi');
9
+ const kripto = require('./kripto');
10
+ const jaringan = require('./jaringan');
11
+ const uji = require('./uji');
12
+
13
+ const STD_MODULES = {
14
+ matematika,
15
+ acak: modul_acak,
16
+ modul_acak,
17
+ waktu,
18
+ berkas,
19
+ sistem,
20
+ data_json,
21
+ json_id: data_json,
22
+ pola,
23
+ koleksi,
24
+ kripto,
25
+ jaringan,
26
+ uji,
27
+ };
28
+
29
+ module.exports = { STD_MODULES };
@@ -0,0 +1,28 @@
1
+ const { URL } = require('url');
2
+ const { execFileSync } = require('child_process');
3
+
4
+ function urai_url(urlStr) {
5
+ const u = new URL(urlStr);
6
+ return {
7
+ protokol: u.protocol,
8
+ host: u.host,
9
+ jalur: u.pathname,
10
+ kueri: Object.fromEntries(u.searchParams.entries()),
11
+ };
12
+ }
13
+
14
+ function ambil(urlStr) {
15
+ const script = `
16
+ const u = ${JSON.stringify(urlStr)};
17
+ const mod = u.startsWith('https') ? require('https') : require('http');
18
+ mod.get(u, (res) => {
19
+ let data = '';
20
+ res.on('data', (c) => data += c);
21
+ res.on('end', () => console.log(JSON.stringify({ status: res.statusCode, isi: data })));
22
+ }).on('error', (e) => { console.error(e.message); process.exit(1); });
23
+ `;
24
+ const out = execFileSync(process.execPath, ['-e', script], { encoding: 'utf8' });
25
+ return JSON.parse(out);
26
+ }
27
+
28
+ module.exports = { urai_url, ambil };
@@ -0,0 +1,43 @@
1
+ function hitung(daftar) {
2
+ const hasil = {};
3
+ for (const item of daftar) {
4
+ const k = String(item);
5
+ hasil[k] = (hasil[k] || 0) + 1;
6
+ }
7
+ return hasil;
8
+ }
9
+
10
+ function unik(daftar) {
11
+ return Array.from(new Set(daftar));
12
+ }
13
+
14
+ function rata_rata(daftar) {
15
+ if (!daftar.length) return 0;
16
+ return daftar.reduce((a, b) => a + b, 0) / daftar.length;
17
+ }
18
+
19
+ function median(daftar) {
20
+ if (!daftar.length) return 0;
21
+ const s = [...daftar].sort((a, b) => a - b);
22
+ const mid = Math.floor(s.length / 2);
23
+ return s.length % 2 !== 0 ? s[mid] : (s[mid - 1] + s[mid]) / 2;
24
+ }
25
+
26
+ function pasangkan(a, b) {
27
+ const len = Math.min(a.length, b.length);
28
+ const res = [];
29
+ for (let i = 0; i < len; i++) res.push([a[i], b[i]]);
30
+ return res;
31
+ }
32
+
33
+ function kelompokkan(daftar, kunciFn) {
34
+ const hasil = {};
35
+ for (const item of daftar) {
36
+ const k = typeof kunciFn === 'function' ? kunciFn(item) : item[kunciFn];
37
+ if (!hasil[k]) hasil[k] = [];
38
+ hasil[k].push(item);
39
+ }
40
+ return hasil;
41
+ }
42
+
43
+ module.exports = { hitung, unik, rata_rata, median, pasangkan, kelompokkan };
@@ -0,0 +1,9 @@
1
+ const crypto = require('crypto');
2
+
3
+ module.exports = {
4
+ sha256: (teks) => crypto.createHash('sha256').update(String(teks)).digest('hex'),
5
+ md5: (teks) => crypto.createHash('md5').update(String(teks)).digest('hex'),
6
+ acak_hex: (panjangByte = 16) => crypto.randomBytes(panjangByte).toString('hex'),
7
+ encode_base64: (teks) => Buffer.from(String(teks), 'utf8').toString('base64'),
8
+ decode_base64: (teks) => Buffer.from(String(teks), 'base64').toString('utf8'),
9
+ };
@@ -0,0 +1,55 @@
1
+ function faktorial(n) {
2
+ if (n < 0 || !Number.isInteger(n)) {
3
+ throw new Error('faktorial() hanya menerima bilangan bulat non-negatif');
4
+ }
5
+ let res = 1;
6
+ for (let i = 2; i <= n; i++) res *= i;
7
+ return res;
8
+ }
9
+
10
+ function fpb(a, b) {
11
+ a = Math.abs(Math.trunc(a));
12
+ b = Math.abs(Math.trunc(b));
13
+ while (b !== 0) {
14
+ const t = b;
15
+ b = a % b;
16
+ a = t;
17
+ }
18
+ return a;
19
+ }
20
+
21
+ function kpk(a, b) {
22
+ if (a === 0 || b === 0) return 0;
23
+ return Math.abs(Math.trunc(a * b)) / fpb(a, b);
24
+ }
25
+
26
+ module.exports = {
27
+ pi: Math.PI,
28
+ e: Math.E,
29
+ tau: Math.PI * 2,
30
+ tak_hingga: Infinity,
31
+ akar: Math.sqrt,
32
+ pangkat: Math.pow,
33
+ sin: Math.sin,
34
+ cos: Math.cos,
35
+ tan: Math.tan,
36
+ asin: Math.asin,
37
+ acos: Math.acos,
38
+ atan: Math.atan,
39
+ atan2: Math.atan2,
40
+ log: Math.log,
41
+ log10: Math.log10,
42
+ log2: Math.log2,
43
+ exp: Math.exp,
44
+ bawah: Math.floor,
45
+ atas: Math.ceil,
46
+ bulatkan: Math.round,
47
+ mutlak: Math.abs,
48
+ derajat: (rad) => (rad * 180) / Math.PI,
49
+ radian: (deg) => (deg * Math.PI) / 180,
50
+ faktorial,
51
+ fpb,
52
+ kpk,
53
+ apakah_terhingga: Number.isFinite,
54
+ apakah_nan: Number.isNaN,
55
+ };
@@ -0,0 +1,36 @@
1
+ function bulat(min = 0, max = 100) {
2
+ return Math.floor(Math.random() * (max - min + 1)) + min;
3
+ }
4
+
5
+ function desimal(min = 0, max = 1) {
6
+ return Math.random() * (max - min) + min;
7
+ }
8
+
9
+ function pilih(daftar) {
10
+ if (!Array.isArray(daftar) || daftar.length === 0) {
11
+ throw new Error('pilih() membutuhkan daftar yang tidak kosong');
12
+ }
13
+ return daftar[Math.floor(Math.random() * daftar.length)];
14
+ }
15
+
16
+ function sampel(daftar, k) {
17
+ if (k > daftar.length) {
18
+ throw new Error('Jumlah sampel lebih besar dari panjang daftar');
19
+ }
20
+ const salinan = [...daftar];
21
+ for (let i = salinan.length - 1; i > 0; i--) {
22
+ const j = Math.floor(Math.random() * (i + 1));
23
+ [salinan[i], salinan[j]] = [salinan[j], salinan[i]];
24
+ }
25
+ return salinan.slice(0, k);
26
+ }
27
+
28
+ function kocok(daftar) {
29
+ for (let i = daftar.length - 1; i > 0; i--) {
30
+ const j = Math.floor(Math.random() * (i + 1));
31
+ [daftar[i], daftar[j]] = [daftar[j], daftar[i]];
32
+ }
33
+ return daftar;
34
+ }
35
+
36
+ module.exports = { bulat, desimal, pilih, sampel, kocok };
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ cocok: (pola, teks) => new RegExp('^' + pola).test(teks),
3
+ cari: (pola, teks) => {
4
+ const m = String(teks).match(new RegExp(pola));
5
+ return m ? m[0] : null;
6
+ },
7
+ cari_semua: (pola, teks) => {
8
+ const matches = String(teks).match(new RegExp(pola, 'g'));
9
+ return matches || [];
10
+ },
11
+ ganti: (pola, pengganti, teks) => String(teks).replace(new RegExp(pola, 'g'), pengganti),
12
+ pisah: (pola, teks) => String(teks).split(new RegExp(pola)),
13
+ };
@@ -0,0 +1,13 @@
1
+ const os = require('os');
2
+
3
+ module.exports = {
4
+ argumen: process.argv.slice(2),
5
+ versi_node: process.version,
6
+ platform: () => os.platform(),
7
+ arsitektur: () => os.arch(),
8
+ nama_host: () => os.hostname(),
9
+ lingkungan: process.env,
10
+ keluar: (kode = 0) => process.exit(kode),
11
+ memori_bebas: () => os.freemem(),
12
+ memori_total: () => os.totalmem(),
13
+ };
@@ -0,0 +1,52 @@
1
+ let lulus = 0;
2
+ let gagal = 0;
3
+
4
+ function sama(a, b, pesan = '') {
5
+ const sA = JSON.stringify(a);
6
+ const sB = JSON.stringify(b);
7
+ if (sA === sB) {
8
+ lulus++;
9
+ } else {
10
+ gagal++;
11
+ throw new Error(pesan || `Gagal uji.sama: diharapkan ${sB}, didapat ${sA}`);
12
+ }
13
+ }
14
+
15
+ function benar(kondisi, pesan = '') {
16
+ if (kondisi) {
17
+ lulus++;
18
+ } else {
19
+ gagal++;
20
+ throw new Error(pesan || 'Gagal uji.benar: kondisi bernilai Salah');
21
+ }
22
+ }
23
+
24
+ function salah(kondisi, pesan = '') {
25
+ if (!kondisi) {
26
+ lulus++;
27
+ } else {
28
+ gagal++;
29
+ throw new Error(pesan || 'Gagal uji.salah: kondisi bernilai Benar');
30
+ }
31
+ }
32
+
33
+ function lempar_galat(fn, pesan = '') {
34
+ let dilempar = false;
35
+ try {
36
+ fn();
37
+ } catch (e) {
38
+ dilempar = true;
39
+ }
40
+ if (dilempar) {
41
+ lulus++;
42
+ } else {
43
+ gagal++;
44
+ throw new Error(pesan || 'Gagal uji.lempar_galat: fungsi tidak melempar kesalahan');
45
+ }
46
+ }
47
+
48
+ function ringkasan() {
49
+ return { lulus, gagal, total: lulus + gagal };
50
+ }
51
+
52
+ module.exports = { sama, benar, salah, lempar_galat, ringkasan };
@@ -0,0 +1,49 @@
1
+ function sekarang() {
2
+ return Date.now() / 1000;
3
+ }
4
+
5
+ function sekarang_ms() {
6
+ return Date.now();
7
+ }
8
+
9
+ function tidur(detik) {
10
+ const end = Date.now() + detik * 1000;
11
+ while (Date.now() < end) {}
12
+ }
13
+
14
+ function tanggal_sekarang() {
15
+ const d = new Date();
16
+ const y = d.getFullYear();
17
+ const m = String(d.getMonth() + 1).padStart(2, '0');
18
+ const day = String(d.getDate()).padStart(2, '0');
19
+ return `${y}-${m}-${day}`;
20
+ }
21
+
22
+ function jam_sekarang() {
23
+ const d = new Date();
24
+ const hh = String(d.getHours()).padStart(2, '0');
25
+ const mm = String(d.getMinutes()).padStart(2, '0');
26
+ const ss = String(d.getSeconds()).padStart(2, '0');
27
+ return `${hh}:${mm}:${ss}`;
28
+ }
29
+
30
+ function info_waktu() {
31
+ const d = new Date();
32
+ return {
33
+ tahun: d.getFullYear(),
34
+ bulan: d.getMonth() + 1,
35
+ hari: d.getDate(),
36
+ jam: d.getHours(),
37
+ menit: d.getMinutes(),
38
+ detik: d.getSeconds(),
39
+ };
40
+ }
41
+
42
+ module.exports = {
43
+ sekarang,
44
+ sekarang_ms,
45
+ tidur,
46
+ tanggal_sekarang,
47
+ jam_sekarang,
48
+ info_waktu,
49
+ };
@@ -0,0 +1,111 @@
1
+ const { execFileSync } = require('child_process');
2
+
3
+ function callPythonBridge(payload) {
4
+ const pyScript = `
5
+ import sys, json, importlib, importlib.util, os, math
6
+
7
+ req = json.loads(sys.stdin.read())
8
+ mod_name = req["module"]
9
+ base_dir = req.get("baseDir", os.getcwd())
10
+ if base_dir and base_dir not in sys.path:
11
+ sys.path.insert(0, base_dir)
12
+
13
+ if mod_name.endswith(".py") or os.path.sep in mod_name or "/" in mod_name:
14
+ abs_path = os.path.abspath(os.path.join(base_dir, mod_name))
15
+ spec = importlib.util.spec_from_file_location("mhs_py_mod", abs_path)
16
+ mod = importlib.util.module_from_spec(spec)
17
+ spec.loader.exec_module(mod)
18
+ else:
19
+ mod = importlib.import_module(mod_name)
20
+
21
+ def is_json_safe(val):
22
+ if isinstance(val, float):
23
+ return math.isfinite(val)
24
+ if isinstance(val, (int, str, bool)) or val is None:
25
+ return True
26
+ if isinstance(val, list):
27
+ return all(is_json_safe(x) for x in val)
28
+ if isinstance(val, dict):
29
+ return all(isinstance(k, str) and is_json_safe(v) for k, v in val.items())
30
+ return False
31
+
32
+ action = req["action"]
33
+ if action == "inspect":
34
+ attrs = {}
35
+ for k in dir(mod):
36
+ if k.startswith("_"):
37
+ continue
38
+ v = getattr(mod, k)
39
+ if callable(v):
40
+ attrs[k] = {"__callable__": True}
41
+ elif is_json_safe(v):
42
+ attrs[k] = {"__value__": v}
43
+ print(json.dumps({"ok": True, "attrs": attrs}, allow_nan=False))
44
+ elif action == "call":
45
+ target = getattr(mod, req["attr"])
46
+ res = target(*req.get("args", []))
47
+ print(json.dumps({"ok": True, "result": res}, allow_nan=False))
48
+ `;
49
+
50
+ const pythonCmd = process.platform === 'win32' ? 'python' : 'python3';
51
+ let stdout;
52
+ try {
53
+ stdout = execFileSync(pythonCmd, ['-c', pyScript], {
54
+ input: JSON.stringify(payload),
55
+ encoding: 'utf8',
56
+ });
57
+ } catch (err) {
58
+ const msg = err.stderr ? err.stderr.toString().trim() : err.message;
59
+ throw new Error(`Gagal menjalankan bridge Python (${payload.module}): ${msg}`);
60
+ }
61
+ const parsed = JSON.parse(stdout.trim());
62
+ if (!parsed.ok) {
63
+ throw new Error(parsed.error || 'Kesalahan pada bridge Python');
64
+ }
65
+ return parsed;
66
+ }
67
+
68
+ function importPythonModule(moduleName, baseDir = process.cwd()) {
69
+ const { attrs } = callPythonBridge({
70
+ action: 'inspect',
71
+ module: moduleName,
72
+ baseDir,
73
+ });
74
+
75
+ const proxyObj = {};
76
+ for (const [key, meta] of Object.entries(attrs)) {
77
+ if (meta.__callable__) {
78
+ proxyObj[key] = (...args) => {
79
+ const { result } = callPythonBridge({
80
+ action: 'call',
81
+ module: moduleName,
82
+ baseDir,
83
+ attr: key,
84
+ args,
85
+ });
86
+ return result;
87
+ };
88
+ } else {
89
+ proxyObj[key] = meta.__value__;
90
+ }
91
+ }
92
+
93
+ return new Proxy(proxyObj, {
94
+ get(target, prop) {
95
+ if (prop in target) return target[prop];
96
+ if (typeof prop === 'symbol') return undefined;
97
+ return (...args) => {
98
+ const { result } = callPythonBridge({
99
+ action: 'call',
100
+ module: moduleName,
101
+ baseDir,
102
+ attr: String(prop),
103
+ args,
104
+ });
105
+ return result;
106
+ };
107
+ },
108
+ });
109
+ }
110
+
111
+ module.exports = { importPythonModule };
@@ -0,0 +1,26 @@
1
+ import os
2
+ import shutil
3
+
4
+ def baca(jalur, encoding="utf-8"):
5
+ with open(jalur, "r", encoding=encoding) as f:
6
+ return f.read()
7
+
8
+ def tulis(jalur, isi, encoding="utf-8"):
9
+ with open(jalur, "w", encoding=encoding) as f:
10
+ f.write(str(isi))
11
+
12
+ def tambah_isi(jalur, isi, encoding="utf-8"):
13
+ with open(jalur, "a", encoding=encoding) as f:
14
+ f.write(str(isi))
15
+
16
+ ada = os.path.exists
17
+ hapus = os.remove
18
+ daftar_isi = os.listdir
19
+ buat_folder = lambda jalur: os.makedirs(jalur, exist_ok=True)
20
+ hapus_folder = lambda jalur: shutil.rmtree(jalur, ignore_errors=True)
21
+ gabung_jalur = os.path.join
22
+ nama_berkas = os.path.basename
23
+ folder_induk = os.path.dirname
24
+ ekstensi = lambda jalur: os.path.splitext(jalur)[1]
25
+ ukuran = os.path.getsize
26
+ folder_kerja = os.getcwd
@@ -0,0 +1,14 @@
1
+ import json
2
+
3
+ urai = json.loads
4
+
5
+ def ubah_ke_teks(objek, rapi=False):
6
+ return json.dumps(objek, indent=2 if rapi else None)
7
+
8
+ def baca_berkas(jalur):
9
+ with open(jalur, "r", encoding="utf-8") as f:
10
+ return json.load(f)
11
+
12
+ def tulis_berkas(jalur, objek, rapi=True):
13
+ with open(jalur, "w", encoding="utf-8") as f:
14
+ json.dump(objek, f, indent=2 if rapi else None)
@@ -0,0 +1,15 @@
1
+ from urllib.parse import urlparse, parse_qs
2
+ import urllib.request
3
+
4
+ def urai_url(url_str):
5
+ u = urlparse(url_str)
6
+ return {
7
+ "protokol": u.scheme + ":",
8
+ "host": u.netloc,
9
+ "jalur": u.path,
10
+ "kueri": {k: v[0] if len(v) == 1 else v for k, v in parse_qs(u.query).items()},
11
+ }
12
+
13
+ def ambil(url_str):
14
+ with urllib.request.urlopen(url_str) as resp:
15
+ return {"status": resp.status, "isi": resp.read().decode("utf-8")}
@@ -0,0 +1,24 @@
1
+ from collections import Counter
2
+ import statistics
3
+
4
+ def hitung(daftar):
5
+ return dict(Counter(str(x) for x in daftar))
6
+
7
+ def unik(daftar):
8
+ return list(dict.fromkeys(daftar))
9
+
10
+ def rata_rata(daftar):
11
+ return statistics.mean(daftar) if daftar else 0
12
+
13
+ def median(daftar):
14
+ return statistics.median(daftar) if daftar else 0
15
+
16
+ def pasangkan(a, b):
17
+ return [list(x) for x in zip(a, b)]
18
+
19
+ def kelompokkan(daftar, kunci):
20
+ hasil = {}
21
+ for item in daftar:
22
+ k = kunci(item) if callable(kunci) else item[kunci]
23
+ hasil.setdefault(k, []).append(item)
24
+ return hasil
@@ -0,0 +1,18 @@
1
+ import hashlib
2
+ import base64
3
+ import secrets
4
+
5
+ def sha256(teks):
6
+ return hashlib.sha256(str(teks).encode("utf-8")).hexdigest()
7
+
8
+ def md5(teks):
9
+ return hashlib.md5(str(teks).encode("utf-8")).hexdigest()
10
+
11
+ def acak_hex(panjang_byte=16):
12
+ return secrets.token_hex(panjang_byte)
13
+
14
+ def encode_base64(teks):
15
+ return base64.b64encode(str(teks).encode("utf-8")).decode("utf-8")
16
+
17
+ def decode_base64(teks):
18
+ return base64.b64decode(str(teks).encode("utf-8")).decode("utf-8")
@@ -0,0 +1,30 @@
1
+ import math
2
+
3
+ pi = math.pi
4
+ e = math.e
5
+ tau = math.tau
6
+ tak_hingga = math.inf
7
+ akar = math.sqrt
8
+ pangkat = math.pow
9
+ sin = math.sin
10
+ cos = math.cos
11
+ tan = math.tan
12
+ asin = math.asin
13
+ acos = math.acos
14
+ atan = math.atan
15
+ atan2 = math.atan2
16
+ log = math.log
17
+ log10 = math.log10
18
+ log2 = math.log2
19
+ exp = math.exp
20
+ bawah = math.floor
21
+ atas = math.ceil
22
+ bulatkan = round
23
+ mutlak = abs
24
+ derajat = math.degrees
25
+ radian = math.radians
26
+ faktorial = math.factorial
27
+ fpb = math.gcd
28
+ kpk = math.lcm
29
+ apakah_terhingga = math.isfinite
30
+ apakah_nan = math.isnan
@@ -0,0 +1,14 @@
1
+ import random
2
+
3
+ def bulat(min_v=0, max_v=100):
4
+ return random.randint(min_v, max_v)
5
+
6
+ def desimal(min_v=0.0, max_v=1.0):
7
+ return random.uniform(min_v, max_v)
8
+
9
+ pilih = random.choice
10
+ sampel = random.sample
11
+
12
+ def kocok(daftar):
13
+ random.shuffle(daftar)
14
+ return daftar
@@ -0,0 +1,17 @@
1
+ import re
2
+
3
+ def cocok(pola, teks):
4
+ return bool(re.match(pola, str(teks)))
5
+
6
+ def cari(pola, teks):
7
+ m = re.search(pola, str(teks))
8
+ return m.group(0) if m else None
9
+
10
+ def cari_semua(pola, teks):
11
+ return re.findall(pola, str(teks))
12
+
13
+ def ganti(pola, pengganti, teks):
14
+ return re.sub(pola, pengganti, str(teks))
15
+
16
+ def pisah(pola, teks):
17
+ return re.split(pola, str(teks))
@@ -0,0 +1,11 @@
1
+ import sys
2
+ import os
3
+ import platform as _plat
4
+
5
+ argumen = sys.argv[1:]
6
+ versi_python = _plat.python_version()
7
+ platform = lambda: _plat.system().lower()
8
+ arsitektur = _plat.machine
9
+ nama_host = _plat.node
10
+ lingkungan = dict(os.environ)
11
+ keluar = sys.exit