fxxkinmethod
v1.0.1
Published
Provides some fxxkin' methods.
Maintainers
Readme
fxxkinmethod
Provides some fxxkin' methods.
English | 日本語
A joke package. It gives you print, puts, var_dump, Println, printf, and friends —
each one reproducing the quirks of how that language actually renders values to the terminal.
Ships as both ESM and CommonJS, with full TypeScript types.
Install
npm install fxxkinmethodUsage
Import the language you want from its subpath — this is the recommended style (only what you use gets bundled):
import { print } from "fxxkinmethod/python";
import { puts, p } from "fxxkinmethod/ruby";
print("hello", "world"); // hello world
puts([1, 2, 3]); // 1\n2\n3CommonJS works the same way:
const { print } = require("fxxkinmethod/python");
const { printf } = require("fxxkinmethod/c");
print("hello", "world");
printf("%5.2f\n", 3.14159); // 3.14Prefer a single import?
You can still grab every language as a namespace from the package root:
import { python, ruby, php, go, c } from "fxxkinmethod";
python.print("hello", "world"); // hello world
ruby.puts([1, 2, 3]); // 1\n2\n3
php.var_dump("hi"); // string(2) "hi"
go.Printf("%d items\n", 3); // 3 items
c.printf("%5.2f\n", 3.14159); // 3.14Supported languages
| Subpath | Functions |
| ---------------------- | ------------------------------------------ |
| fxxkinmethod/python | print, pprint, pformat, str, repr |
| fxxkinmethod/ruby | puts, print, p, pp, printf, sprintf/format, warn, putc, toS, inspect |
| fxxkinmethod/php | echo, print, printf, sprintf, vprintf, vsprintf, print_r, var_dump, var_export |
| fxxkinmethod/go | Print, Println, Printf, Sprint, Sprintln, Sprintf, Fprint, Fprintln, Fprintf |
| fxxkinmethod/c | printf, fprintf, sprintf, snprintf, puts, fputs, putchar, fputc, perror |
Functions that write to a stream take a stream argument or option: Python print(…, { file: "stderr" }),
Go Fprintln(go.Stderr, …), C fprintf(c.stderr, …). Ruby's warn and C's perror go to stderr.
Constants
Each language also exports the names it spells differently from plain JS
(things JS already has — true, false, null, NaN, Infinity — are not redefined):
| Subpath | Constants |
| ---------------------- | ------------------------------------------ |
| fxxkinmethod/python | True, False, None, Ellipsis, math.nan / math.inf |
| fxxkinmethod/ruby | nil, end, _, Float.NAN / Float.INFINITY |
| fxxkinmethod/php | NAN, INF, PHP_EOL |
| fxxkinmethod/go | nil, _, math.NaN() / math.Inf(sign) |
| fxxkinmethod/c | NULL, EOF, NAN, INFINITY |
Yes, you can import Ruby's end and close your blocks in style:
import { puts, nil, end } from "fxxkinmethod/ruby";
if (nil === null) {
puts("nil is null");
}
end;The quirks it reproduces
- Python —
True/False/None, lists as[1, 'a', True], dicts as{'a': 1}, andprint(..., { sep, end })keyword-style options. - Ruby —
putsflattens arrays one-element-per-line and won't double a trailing newline;pprints theinspectform ("hi",nil) and returns its argument. - PHP —
echo trueprints1,echo falseprints nothing;var_dumpreports byte lengths (string(2) "hi");print_rreproduces the indentedArray ( … )layout. - Go —
fmt.Printonly inserts a space when neither neighbour is a string; slices print as[1 2 3], maps asmap[a:1 b:2], nil as<nil>. - C —
printfsupports%d %i %u %o %x %X %b %f %e %g %s %c, flags-+ 0#, width and precision (including*);putsalways appends\n.
Contributing
Contributions are welcome! See CONTRIBUTING.md for how to file an issue, open a pull request, and set up the project locally. Requires Node.js >= 18.
License
MIT © otoneko.
