|
| 1 | +# TechScript v2.0.0 — Standard Library Reference |
| 2 | + |
| 3 | +> Complete reference for all 150+ built-in functions. |
| 4 | +
|
| 5 | +--- |
| 6 | + |
| 7 | +## 🌍 Global Functions |
| 8 | + |
| 9 | +### I/O Functions |
| 10 | +| Function | Description | Example | |
| 11 | +|:---|:---|:---| |
| 12 | +| `say(value)` | Print with newline | `say "Hello"` | |
| 13 | +| `print(value)` | Print without newline | `print "..."` | |
| 14 | +| `write(value)` | Alias for print | `write "text"` | |
| 15 | +| `format(fmt, ...)` | Format string | `format("{} is {}", name, age)` | |
| 16 | +| `debug(value)` | Print with type info | `debug myvar` | |
| 17 | +| `warn(value)` | Print as warning (yellow) | `warn "caution"` | |
| 18 | +| `error(value)` | Print as error (red) | `error "failed"` | |
| 19 | +| `clear()` | Clear terminal screen | `clear()` | |
| 20 | + |
| 21 | +### Core Functions |
| 22 | +| Function | Description | Example | |
| 23 | +|:---|:---|:---| |
| 24 | +| `assert(cond, msg)` | Panic if false | `assert(x > 0, "must be positive")` | |
| 25 | +| `panic(msg)` | Stop with error | `panic("fatal")` | |
| 26 | +| `sleep(ms)` | Pause execution | `sleep(1000)` | |
| 27 | +| `time()` | Unix timestamp (seconds) | `make t = time()` | |
| 28 | +| `time_ms()` | Unix timestamp (ms) | `make t = time_ms()` | |
| 29 | +| `exit(code)` | Exit process | `exit(0)` | |
| 30 | +| `version()` | Return version string | `say version()` | |
| 31 | +| `callable(val)` | Check if callable | `callable(my_fn)` | |
| 32 | + |
| 33 | +### Type Conversion |
| 34 | +| Function | Description | Example | |
| 35 | +|:---|:---|:---| |
| 36 | +| `int(val)` | Convert to integer | `int("42")` → `42` | |
| 37 | +| `float(val)` | Convert to float | `float("3.14")` → `3.14` | |
| 38 | +| `str(val)` | Convert to string | `str(42)` → `"42"` | |
| 39 | +| `bool(val)` | Convert to boolean | `bool(0)` → `false` | |
| 40 | +| `list(val)` | Convert to list | `list("abc")` → `["a","b","c"]` | |
| 41 | +| `type(val)` | Get type name string | `type(42)` → `"int"` | |
| 42 | +| `len(val)` | Get length | `len([1,2,3])` → `3` | |
| 43 | + |
| 44 | +### String Functions |
| 45 | +| Function | Description | Example | |
| 46 | +|:---|:---|:---| |
| 47 | +| `upper(s)` | Uppercase | `upper("hi")` → `"HI"` | |
| 48 | +| `lower(s)` | Lowercase | `lower("HI")` → `"hi"` | |
| 49 | +| `trim(s)` | Remove whitespace | `trim(" hi ")` → `"hi"` | |
| 50 | +| `trim_start(s)` | Trim leading | `trim_start(" hi")` → `"hi"` | |
| 51 | +| `trim_end(s)` | Trim trailing | `trim_end("hi ")` → `"hi"` | |
| 52 | +| `split(s, d)` | Split by delimiter | `split("a,b", ",")` → `["a","b"]` | |
| 53 | +| `join(list, d)` | Join list with delimiter | `join(["a","b"], "-")` → `"a-b"` | |
| 54 | +| `replace(s, a, b)` | Replace occurrences | `replace("hi", "h", "H")` → `"Hi"` | |
| 55 | +| `contains(s, sub)` | Check substring | `contains("hello", "ell")` → `true` | |
| 56 | +| `starts_with(s, p)` | Check prefix | `starts_with("hello", "he")` → `true` | |
| 57 | +| `ends_with(s, p)` | Check suffix | `ends_with("hello", "lo")` → `true` | |
| 58 | +| `find(s, sub)` | Find index (-1 if none) | `find("hello", "ll")` → `2` | |
| 59 | +| `chars(s)` | String to char list | `chars("hi")` → `["h","i"]` | |
| 60 | +| `repeat_str(s, n)` | Repeat N times | `repeat_str("ab", 3)` → `"ababab"` | |
| 61 | + |
| 62 | +### Math Shortcuts |
| 63 | +| Function | Description | Example | |
| 64 | +|:---|:---|:---| |
| 65 | +| `abs(x)` | Absolute value | `abs(-5)` → `5` | |
| 66 | +| `round(x)` | Round | `round(3.7)` → `4` | |
| 67 | +| `floor(x)` | Floor | `floor(3.7)` → `3` | |
| 68 | +| `ceil(x)` | Ceiling | `ceil(3.2)` → `4` | |
| 69 | +| `sqrt(x)` | Square root | `sqrt(16)` → `4` | |
| 70 | +| `pow(x, y)` | Power | `pow(2, 8)` → `256` | |
| 71 | +| `min(a, b)` | Minimum | `min(3, 7)` → `3` | |
| 72 | +| `max(a, b)` | Maximum | `max(3, 7)` → `7` | |
| 73 | +| `clamp(x, lo, hi)` | Clamp to range | `clamp(15, 0, 10)` → `10` | |
| 74 | +| `sum(list)` | Sum of list | `sum([1,2,3])` → `6` | |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## 📐 `math.*` Module (38 functions) |
| 79 | + |
| 80 | +### Constants |
| 81 | +| Constant | Value | |
| 82 | +|:---|:---| |
| 83 | +| `math.PI` | 3.141592653589793 | |
| 84 | +| `math.E` | 2.718281828459045 | |
| 85 | +| `math.TAU` | 6.283185307179586 | |
| 86 | +| `math.INF` | Infinity | |
| 87 | + |
| 88 | +### Trigonometry |
| 89 | +`math.sin(x)` · `math.cos(x)` · `math.tan(x)` · `math.asin(x)` · `math.acos(x)` · `math.atan(x)` · `math.atan2(y,x)` · `math.sinh(x)` · `math.cosh(x)` · `math.tanh(x)` · `math.to_radians(deg)` · `math.to_degrees(rad)` |
| 90 | + |
| 91 | +### Power / Roots / Logs |
| 92 | +`math.sqrt(x)` · `math.cbrt(x)` · `math.pow(x,y)` · `math.exp(x)` · `math.log(x)` · `math.log2(x)` · `math.log10(x)` |
| 93 | + |
| 94 | +### Rounding |
| 95 | +`math.floor(x)` · `math.ceil(x)` · `math.round(x)` · `math.abs(x)` · `math.sign(x)` |
| 96 | + |
| 97 | +### Integer Math |
| 98 | +`math.factorial(n)` · `math.gcd(a,b)` · `math.lcm(a,b)` · `math.fibonacci(n)` · `math.is_prime(n)` |
| 99 | + |
| 100 | +### Statistics |
| 101 | +`math.min(list)` · `math.max(list)` · `math.sum(list)` · `math.mean(list)` · `math.clamp(x,lo,hi)` |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +## 📁 `fs.*` Module (20 functions) |
| 106 | + |
| 107 | +| Function | Description | |
| 108 | +|:---|:---| |
| 109 | +| `fs.read(path)` | Read file to string | |
| 110 | +| `fs.write(path, data)` | Write string to file | |
| 111 | +| `fs.append(path, data)` | Append to file | |
| 112 | +| `fs.exists(path)` | Check if path exists | |
| 113 | +| `fs.delete(path)` | Delete file | |
| 114 | +| `fs.rename(old, new)` | Rename file | |
| 115 | +| `fs.copy(src, dst)` | Copy file | |
| 116 | +| `fs.is_file(path)` | Check if file | |
| 117 | +| `fs.is_dir(path)` | Check if directory | |
| 118 | +| `fs.size(path)` | File size in bytes | |
| 119 | +| `fs.list_dir(path)` | List directory contents | |
| 120 | +| `fs.make_dir(path)` | Create directory | |
| 121 | +| `fs.cwd` | Current working directory | |
| 122 | +| `fs.read_bytes(path)` | Read as byte list | |
| 123 | +| `fs.write_bytes(path, bytes)` | Write byte list | |
| 124 | +| `fs.extension(path)` | Get file extension | |
| 125 | +| `fs.basename(path)` | Get filename | |
| 126 | +| `fs.parent(path)` | Get parent directory | |
| 127 | +| `fs.join(a, b)` | Join path components | |
| 128 | +| `fs.abs_path(path)` | Get absolute path | |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +## 🖥️ `os.*` Module (10 functions) |
| 133 | + |
| 134 | +| Function | Description | |
| 135 | +|:---|:---| |
| 136 | +| `os.name` | OS name (e.g. "windows") | |
| 137 | +| `os.arch` | CPU architecture | |
| 138 | +| `os.pid` | Current process ID | |
| 139 | +| `os.env_get(key)` | Get environment variable | |
| 140 | +| `os.env_set(key, val)` | Set environment variable | |
| 141 | +| `os.system(cmd)` | Run command (exit code) | |
| 142 | +| `os.popen(cmd)` | Run command (get output) | |
| 143 | +| `os.args` | Command line arguments | |
| 144 | +| `os.home` | User home directory | |
| 145 | +| `os.exit(code)` | Exit with code | |
| 146 | + |
| 147 | +--- |
| 148 | + |
| 149 | +## 📊 `json.*` Module (3 functions) |
| 150 | + |
| 151 | +| Function | Description | Example | |
| 152 | +|:---|:---|:---| |
| 153 | +| `json.encode(val)` | Value → JSON string | `json.encode({"a":1})` → `'{"a":1}'` | |
| 154 | +| `json.encode_pretty(val)` | Value → formatted JSON | Multi-line, indented | |
| 155 | +| `json.decode(str)` | JSON string → value | `json.decode('{"a":1}')` → `{"a":1}` | |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +## 🔐 `crypto.*` Module (4 functions) |
| 160 | + |
| 161 | +| Function | Description | Example | |
| 162 | +|:---|:---|:---| |
| 163 | +| `crypto.sha256(str)` | SHA-256 hash (real FIPS 180-4) | `crypto.sha256("hi")` → `"8f43..."` | |
| 164 | +| `crypto.md5(str)` | MD5-style hash | `crypto.md5("hi")` | |
| 165 | +| `crypto.base64_encode(str)` | Encode to Base64 | `crypto.base64_encode("hi")` → `"aGk="` | |
| 166 | +| `crypto.base64_decode(str)` | Decode from Base64 | `crypto.base64_decode("aGk=")` → `"hi"` | |
| 167 | + |
| 168 | +--- |
| 169 | + |
| 170 | +## 📅 `date.*` Module (9 functions) |
| 171 | + |
| 172 | +| Function | Description | |
| 173 | +|:---|:---| |
| 174 | +| `date.now` | Current date/time string (UTC) | |
| 175 | +| `date.year` | Current year | |
| 176 | +| `date.month` | Current month (1-12) | |
| 177 | +| `date.day` | Current day (1-31) | |
| 178 | +| `date.hour` | Current hour (0-23, UTC) | |
| 179 | +| `date.minute` | Current minute (0-59) | |
| 180 | +| `date.second` | Current second (0-59) | |
| 181 | +| `date.unix` | Unix timestamp (seconds) | |
| 182 | +| `date.unix_ms` | Unix timestamp (milliseconds) | |
| 183 | + |
| 184 | +--- |
| 185 | + |
| 186 | +## 🎲 `random.*` Module (6 functions) |
| 187 | + |
| 188 | +| Function | Description | |
| 189 | +|:---|:---| |
| 190 | +| `random.random` | Random float 0.0–1.0 | |
| 191 | +| `random.randint(min, max)` | Random integer in range | |
| 192 | +| `random.choice(list)` | Random element | |
| 193 | +| `random.sample(list, n)` | N random elements | |
| 194 | +| `random.uuid` | Generate UUID v4 string | |
| 195 | +| `random.shuffle(list)` | Shuffle list in place | |
| 196 | + |
| 197 | +--- |
| 198 | + |
| 199 | +## 🎬 `anime.*` Module (New v2.0!) |
| 200 | + |
| 201 | +The `anime` module provides a powerful high-level interface for creating complex motion designs and cinematic animations directly within TechScript. |
| 202 | + |
| 203 | +| Function | Description | |
| 204 | +|:---|:---| |
| 205 | +| `anime.create()` | Create a new animation context | |
| 206 | +| `anime.render(anim)` | Render the animation to a window/browser | |
| 207 | +| `anime.animate(target, props)` | Standard animation call | |
| 208 | +| `anime.stagger(ms)` | Staggered timing for multiple elements | |
| 209 | +| `anime.remove(target)` | Stop and remove animation | |
| 210 | +| `anime.set(target, props)` | Instantly set properties | |
| 211 | +| `anime.path(path)` | Create a motion path | |
| 212 | +| `anime.timeline(config)` | Create complex sequenced animations | |
0 commit comments