@dramxx/brolang 0.1.0 → 0.1.1

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 (2) hide show
  1. package/README.md +152 -151
  2. package/package.json +37 -37
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # BroLang
2
2
 
3
- A programming language for developers who communicate in modern vernacular. Write code the way you actually talk.
4
-
5
3
  **File extension:** `.bro`
6
4
  **Runtime:** Node.js
7
5
  **Transpiles to:** Vanilla JavaScript
@@ -97,7 +95,7 @@ function greet(name) {
97
95
  return "Yo " + name;
98
96
  }
99
97
 
100
- const add = function(a, b) {
98
+ const add = function (a, b) {
101
99
  return a + b;
102
100
  };
103
101
  ```
@@ -250,8 +248,12 @@ vibing (lilbro n of nums) {
250
248
 
251
249
  ```js
252
250
  for (let n of nums) {
253
- if (n === 0) { continue; }
254
- if (n < 0) { break; }
251
+ if (n === 0) {
252
+ continue;
253
+ }
254
+ if (n < 0) {
255
+ break;
256
+ }
255
257
  console.log(n);
256
258
  }
257
259
  ```
@@ -367,9 +369,9 @@ share lilbro MAX_RETRIES = 3
367
369
  ```
368
370
 
369
371
  ```js
370
- import { useState, useEffect } from 'react';
371
- import axios from 'axios';
372
- import * as utils from './utils';
372
+ import { useState, useEffect } from "react";
373
+ import axios from "axios";
374
+ import * as utils from "./utils";
373
375
 
374
376
  export default function MyComponent() {
375
377
  return null;
@@ -409,7 +411,7 @@ async function fetchData(url) {
409
411
  }
410
412
  }
411
413
 
412
- const getData = async function(id) {
414
+ const getData = async function (id) {
413
415
  return await fetchData("/api/" + id);
414
416
  };
415
417
  ```
@@ -425,7 +427,7 @@ const getData = async function(id) {
425
427
  #### Literal values
426
428
 
427
429
  | BroLang | Value |
428
- |-----------|-------------|
430
+ | --------- | ----------- |
429
431
  | `cool` | `true` |
430
432
  | `notcool` | `false` |
431
433
  | `shit` | `null` |
@@ -501,25 +503,25 @@ The BroLang runtime is injected into every `.bro` file automatically. No imports
501
503
 
502
504
  ### Console
503
505
 
504
- | Function | Description |
505
- |------------------------|------------------------------------------|
506
- | `spam(...args)` | Log to stdout |
507
- | `omfg(...args)` | Log to stderr |
508
- | `omg(...args)` | Log a warning |
509
- | `spreadshit(data)` | Print tabular data |
510
- | `debugshit(...args)` | Debug output |
511
- | `clearshit()` | Clear the console |
512
- | `timeshit(label)` | Start a named timer |
513
- | `timeshitdone(label)` | End a timer and print elapsed time |
514
-
515
- ```js
516
- spam("hello world")
517
- omfg("critical failure")
518
- omg("this seems sketchy")
519
- spreadshit(users)
520
- timeshit("load")
521
- loadData()
522
- timeshitdone("load")
506
+ | Function | Description |
507
+ | --------------------- | ---------------------------------- |
508
+ | `spam(...args)` | Log to stdout |
509
+ | `omfg(...args)` | Log to stderr |
510
+ | `omg(...args)` | Log a warning |
511
+ | `spreadshit(data)` | Print tabular data |
512
+ | `debugshit(...args)` | Debug output |
513
+ | `clearshit()` | Clear the console |
514
+ | `timeshit(label)` | Start a named timer |
515
+ | `timeshitdone(label)` | End a timer and print elapsed time |
516
+
517
+ ```js
518
+ spam("hello world");
519
+ omfg("critical failure");
520
+ omg("this seems sketchy");
521
+ spreadshit(users);
522
+ timeshit("load");
523
+ loadData();
524
+ timeshitdone("load");
523
525
  ```
524
526
 
525
527
  ```js
@@ -536,12 +538,12 @@ console.timeEnd("load");
536
538
 
537
539
  ### Timers
538
540
 
539
- | Function | Description |
540
- |----------------------------|-----------------------------------------------|
541
- | `laterbruh(fn, ms)` | Execute `fn` after `ms` milliseconds |
542
- | `keepspamming(fn, ms)` | Execute `fn` every `ms` milliseconds |
543
- | `nevermind(id)` | Cancel a `laterbruh` timer |
544
- | `shutup(id)` | Cancel a `keepspamming` interval |
541
+ | Function | Description |
542
+ | ---------------------- | ------------------------------------ |
543
+ | `laterbruh(fn, ms)` | Execute `fn` after `ms` milliseconds |
544
+ | `keepspamming(fn, ms)` | Execute `fn` every `ms` milliseconds |
545
+ | `nevermind(id)` | Cancel a `laterbruh` timer |
546
+ | `shutup(id)` | Cancel a `keepspamming` interval |
545
547
 
546
548
  ```js
547
549
  lilbro id = laterbruh(bro() {
@@ -557,11 +559,11 @@ shutup(ticker)
557
559
  ```
558
560
 
559
561
  ```js
560
- let id = setTimeout(function() {
562
+ let id = setTimeout(function () {
561
563
  console.log("finally");
562
564
  }, 3000);
563
565
 
564
- let ticker = setInterval(function() {
566
+ let ticker = setInterval(function () {
565
567
  console.log("tick");
566
568
  }, 1000);
567
569
 
@@ -573,18 +575,18 @@ clearInterval(ticker);
573
575
 
574
576
  ### Math
575
577
 
576
- | Function | Description |
577
- |-----------------------------|--------------------------|
578
- | `dice()` | Random float in [0, 1) |
579
- | `lowball(n)` | Floor |
580
- | `highball(n)` | Ceiling |
581
- | `ballpark(n)` | Round |
582
- | `bigbro(...n)` | Maximum value |
583
- | `smolbro(...n)` | Minimum value |
584
- | `nominus(n)` | Absolute value |
585
- | `whatroot(n)` | Square root |
586
- | `tothepower(base, exp)` | Exponentiation |
587
- | `PI` | 3.14159... |
578
+ | Function | Description |
579
+ | ----------------------- | ---------------------- |
580
+ | `dice()` | Random float in [0, 1) |
581
+ | `lowball(n)` | Floor |
582
+ | `highball(n)` | Ceiling |
583
+ | `ballpark(n)` | Round |
584
+ | `bigbro(...n)` | Maximum value |
585
+ | `smolbro(...n)` | Minimum value |
586
+ | `nominus(n)` | Absolute value |
587
+ | `whatroot(n)` | Square root |
588
+ | `tothepower(base, exp)` | Exponentiation |
589
+ | `PI` | 3.14159... |
588
590
 
589
591
  ```js
590
592
  lilbro rand = lowball(dice() * 100)
@@ -604,29 +606,29 @@ let capped = Math.min(Math.max(val, 0), 100);
604
606
 
605
607
  Available on all arrays via prototype extension.
606
608
 
607
- | Method | Description |
608
- |-----------------------------|----------------------------------------|
609
- | `.cook(fn)` | Transform each element |
610
- | `.keeponly(fn)` | Filter elements |
611
- | `.smashdown(fn, init)` | Reduce to a single value |
612
- | `.vibecheck(fn)` | Iterate without collecting results |
613
- | `.findone(fn)` | First element matching predicate |
614
- | `.findindex(fn)` | Index of first match |
615
- | `.gotthis(val)` | Test element inclusion |
616
- | `.allfine(fn)` | Test if all elements satisfy predicate |
617
- | `.anyonegood(fn)` | Test if any element satisfies |
618
- | `.stuffin(val)` | Append element |
619
- | `.yeetlast()` | Remove and return last element |
620
- | `.stufffirst(val)` | Prepend element |
621
- | `.yeetfirst()` | Remove and return first element |
622
- | `.glue(sep)` | Join elements into a string |
623
- | `.cutout(s, e)` | Extract subarray |
624
- | `.surgery(s, d, ...items)` | In-place insertion/removal |
625
- | `.sortitout(fn)` | Sort in place |
626
- | `.flipit()` | Reverse in place |
627
- | `.flatten()` | Flatten one level of nesting |
628
- | `.flatmash(fn)` | Map then flatten |
629
- | `.howmany` | Element count (property, not method) |
609
+ | Method | Description |
610
+ | -------------------------- | -------------------------------------- |
611
+ | `.cook(fn)` | Transform each element |
612
+ | `.keeponly(fn)` | Filter elements |
613
+ | `.smashdown(fn, init)` | Reduce to a single value |
614
+ | `.vibecheck(fn)` | Iterate without collecting results |
615
+ | `.findone(fn)` | First element matching predicate |
616
+ | `.findindex(fn)` | Index of first match |
617
+ | `.gotthis(val)` | Test element inclusion |
618
+ | `.allfine(fn)` | Test if all elements satisfy predicate |
619
+ | `.anyonegood(fn)` | Test if any element satisfies |
620
+ | `.stuffin(val)` | Append element |
621
+ | `.yeetlast()` | Remove and return last element |
622
+ | `.stufffirst(val)` | Prepend element |
623
+ | `.yeetfirst()` | Remove and return first element |
624
+ | `.glue(sep)` | Join elements into a string |
625
+ | `.cutout(s, e)` | Extract subarray |
626
+ | `.surgery(s, d, ...items)` | In-place insertion/removal |
627
+ | `.sortitout(fn)` | Sort in place |
628
+ | `.flipit()` | Reverse in place |
629
+ | `.flatten()` | Flatten one level of nesting |
630
+ | `.flatmash(fn)` | Map then flatten |
631
+ | `.howmany` | Element count (property, not method) |
630
632
 
631
633
  ```js
632
634
  lilbro nums = [1, 2, 3, 4, 5]
@@ -648,8 +650,8 @@ let result = nums
648
650
  .map((n) => n * 10)
649
651
  .reduce((acc, n) => acc + n, 0);
650
652
 
651
- console.log(result); // 60
652
- console.log(nums.length); // 5
653
+ console.log(result); // 60
654
+ console.log(nums.length); // 5
653
655
  ```
654
656
 
655
657
  ---
@@ -658,25 +660,25 @@ console.log(nums.length); // 5
658
660
 
659
661
  Available on all strings via prototype extension.
660
662
 
661
- | Method | Description |
662
- |--------------------------|--------------------------------------|
663
- | `.chop(sep)` | Split into array |
664
- | `.cleanitup()` | Trim leading and trailing whitespace |
665
- | `.cleanfront()` | Trim leading whitespace only |
666
- | `.cleanback()` | Trim trailing whitespace only |
667
- | `.gotthis(sub)` | Test substring inclusion |
668
- | `.swapout(old, new)` | Replace first occurrence |
669
- | `.swapallout(old, new)` | Replace all occurrences |
670
- | `.smallify()` | Lowercase |
671
- | `.bigify()` | Uppercase |
672
- | `.startswith(s)` | Test prefix |
673
- | `.endswith(s)` | Test suffix |
674
- | `.pad(n, char)` | Left-pad to target length |
675
- | `.padback(n, char)` | Right-pad to target length |
676
- | `.cutout(s, e)` | Substring extraction |
677
- | `.atpos(i)` | Character at index |
678
- | `.numcode(i)` | Character code at index |
679
- | `.howlong` | Character count (property, not method) |
663
+ | Method | Description |
664
+ | ----------------------- | -------------------------------------- |
665
+ | `.chop(sep)` | Split into array |
666
+ | `.cleanitup()` | Trim leading and trailing whitespace |
667
+ | `.cleanfront()` | Trim leading whitespace only |
668
+ | `.cleanback()` | Trim trailing whitespace only |
669
+ | `.gotthis(sub)` | Test substring inclusion |
670
+ | `.swapout(old, new)` | Replace first occurrence |
671
+ | `.swapallout(old, new)` | Replace all occurrences |
672
+ | `.smallify()` | Lowercase |
673
+ | `.bigify()` | Uppercase |
674
+ | `.startswith(s)` | Test prefix |
675
+ | `.endswith(s)` | Test suffix |
676
+ | `.pad(n, char)` | Left-pad to target length |
677
+ | `.padback(n, char)` | Right-pad to target length |
678
+ | `.cutout(s, e)` | Substring extraction |
679
+ | `.atpos(i)` | Character at index |
680
+ | `.numcode(i)` | Character code at index |
681
+ | `.howlong` | Character count (property, not method) |
680
682
 
681
683
  ```js
682
684
  lilbro str = " Hello World "
@@ -687,24 +689,24 @@ spam(str.howlong) // 15
687
689
 
688
690
  ```js
689
691
  let str = " Hello World ";
690
- console.log(str.trim().toLowerCase()); // "hello world"
691
- console.log(str.trim().split(" ")); // ["Hello", "World"]
692
- console.log(str.length); // 15
692
+ console.log(str.trim().toLowerCase()); // "hello world"
693
+ console.log(str.trim().split(" ")); // ["Hello", "World"]
694
+ console.log(str.length); // 15
693
695
  ```
694
696
 
695
697
  ---
696
698
 
697
699
  ### Object Utilities
698
700
 
699
- | Function | Description |
700
- |-----------------------------|-------------------------------------------|
701
- | `listkeys(obj)` | Array of own enumerable keys |
702
- | `listvals(obj)` | Array of own enumerable values |
703
- | `listpairs(obj)` | Array of `[key, value]` pairs |
704
- | `mash(target, ...sources)` | Merge sources into target (mutates) |
705
- | `frozensolid(obj)` | Prevent any modification to object |
706
- | `sealitup(obj)` | Prevent adding or deleting properties |
707
- | `freshobj(proto)` | Create new object with given prototype |
701
+ | Function | Description |
702
+ | -------------------------- | -------------------------------------- |
703
+ | `listkeys(obj)` | Array of own enumerable keys |
704
+ | `listvals(obj)` | Array of own enumerable values |
705
+ | `listpairs(obj)` | Array of `[key, value]` pairs |
706
+ | `mash(target, ...sources)` | Merge sources into target (mutates) |
707
+ | `frozensolid(obj)` | Prevent any modification to object |
708
+ | `sealitup(obj)` | Prevent adding or deleting properties |
709
+ | `freshobj(proto)` | Create new object with given prototype |
708
710
 
709
711
  ```js
710
712
  lilbro person = { name: "Chad", age: 42 }
@@ -728,11 +730,11 @@ for (let [key, val] of Object.entries(person)) {
728
730
 
729
731
  ### JSON
730
732
 
731
- | Function | Description |
732
- |---------------------------|------------------------------------------|
733
- | `textify(val)` | Serialize value to JSON string |
734
- | `textifypretty(val, n)` | Serialize with `n`-space indentation |
735
- | `untext(str)` | Parse JSON string to value |
733
+ | Function | Description |
734
+ | ----------------------- | ------------------------------------ |
735
+ | `textify(val)` | Serialize value to JSON string |
736
+ | `textifypretty(val, n)` | Serialize with `n`-space indentation |
737
+ | `untext(str)` | Parse JSON string to value |
736
738
 
737
739
  ```js
738
740
  lilbro payload = { name: "BroLang", version: 1 }
@@ -758,22 +760,22 @@ console.log(parsed.name);
758
760
 
759
761
  `pinkyswear` is the Promise interface. Use `fresh pinkyswear(fn)` to construct a new promise.
760
762
 
761
- | Expression | Description |
762
- |----------------------------------|------------------------------------------|
763
- | `fresh pinkyswear(fn)` | Create a new promise |
764
- | `pinkyswear.sorted(val)` | Resolved promise wrapping `val` |
765
- | `pinkyswear.noped(err)` | Rejected promise with `err` |
766
- | `pinkyswear.waitforall(arr)` | Resolve when all promises resolve |
767
- | `pinkyswear.firstfinish(arr)` | Settle when first promise settles |
768
- | `pinkyswear.nodrama(arr)` | Wait for all, regardless of rejection |
763
+ | Expression | Description |
764
+ | ----------------------------- | ------------------------------------- |
765
+ | `fresh pinkyswear(fn)` | Create a new promise |
766
+ | `pinkyswear.sorted(val)` | Resolved promise wrapping `val` |
767
+ | `pinkyswear.noped(err)` | Rejected promise with `err` |
768
+ | `pinkyswear.waitforall(arr)` | Resolve when all promises resolve |
769
+ | `pinkyswear.firstfinish(arr)` | Settle when first promise settles |
770
+ | `pinkyswear.nodrama(arr)` | Wait for all, regardless of rejection |
769
771
 
770
772
  Promise chain methods:
771
773
 
772
- | Method | Description |
773
- |---------------------|------------------------------------------|
774
- | `.thendo(fn)` | Run `fn` on fulfillment |
775
- | `.otherwise(fn)` | Run `fn` on rejection |
776
- | `.nomatterwhat(fn)` | Run `fn` on either outcome |
774
+ | Method | Description |
775
+ | ------------------- | -------------------------- |
776
+ | `.thendo(fn)` | Run `fn` on fulfillment |
777
+ | `.otherwise(fn)` | Run `fn` on rejection |
778
+ | `.nomatterwhat(fn)` | Run `fn` on either outcome |
777
779
 
778
780
  ```js
779
781
  lilbro p = fresh pinkyswear(bro(win, fail) {
@@ -791,7 +793,7 @@ p
791
793
  ```
792
794
 
793
795
  ```js
794
- let p = new Promise(function(resolve, reject) {
796
+ let p = new Promise(function (resolve, reject) {
795
797
  if (condition) {
796
798
  resolve("sorted!");
797
799
  } else {
@@ -799,8 +801,7 @@ let p = new Promise(function(resolve, reject) {
799
801
  }
800
802
  });
801
803
 
802
- p
803
- .then((val) => console.log(val))
804
+ p.then((val) => console.log(val))
804
805
  .catch((err) => console.error(err))
805
806
  .finally(() => console.log("done"));
806
807
  ```
@@ -811,21 +812,21 @@ p
811
812
 
812
813
  DOM helpers are available in browser environments. In Node.js, query functions return `null` or `[]` stubs.
813
814
 
814
- | Function / Property | Description |
815
- |------------------------------|------------------------------------------|
816
- | `findthisshit(id)` | Element by ID |
817
- | `findme(sel)` | First element matching CSS selector |
818
- | `findallofthem(sel)` | All elements matching CSS selector |
819
- | `makething(tag)` | Create a new element |
820
- | `.whenthishappens(ev, fn)` | Attach event listener |
821
- | `.stoplistening(ev, fn)` | Remove event listener |
822
- | `.addtodoc(child)` | Append child node |
823
- | `.kickout(child)` | Remove child node |
824
- | `.text` | Get/set text content (property) |
825
- | `.html` | Get/set inner HTML (property) |
826
- | `.classes` | ClassList reference |
827
- | `.attr(name, val)` | Set attribute |
828
- | `.getattr(name)` | Get attribute |
815
+ | Function / Property | Description |
816
+ | -------------------------- | ----------------------------------- |
817
+ | `findthisshit(id)` | Element by ID |
818
+ | `findme(sel)` | First element matching CSS selector |
819
+ | `findallofthem(sel)` | All elements matching CSS selector |
820
+ | `makething(tag)` | Create a new element |
821
+ | `.whenthishappens(ev, fn)` | Attach event listener |
822
+ | `.stoplistening(ev, fn)` | Remove event listener |
823
+ | `.addtodoc(child)` | Append child node |
824
+ | `.kickout(child)` | Remove child node |
825
+ | `.text` | Get/set text content (property) |
826
+ | `.html` | Get/set inner HTML (property) |
827
+ | `.classes` | ClassList reference |
828
+ | `.attr(name, val)` | Set attribute |
829
+ | `.getattr(name)` | Get attribute |
829
830
 
830
831
  ```js
831
832
  lilbro btn = findme("#submit")
@@ -841,7 +842,7 @@ btn.whenthishappens("click", bro(e) {
841
842
  ```js
842
843
  let btn = document.querySelector("#submit");
843
844
 
844
- btn.addEventListener("click", function(e) {
845
+ btn.addEventListener("click", function (e) {
845
846
  let div = document.createElement("div");
846
847
  div.textContent = "Submitted!";
847
848
  div.classList.add("success");
@@ -853,13 +854,13 @@ btn.addEventListener("click", function(e) {
853
854
 
854
855
  ### Type Checking
855
856
 
856
- | Function | Description |
857
- |-----------------|----------------------------------------------------|
858
- | `wtf(x)` | Type of `x` as a string |
859
- | `x ispartof Y` | `true` if `x` is an instance of `Y` |
860
- | `isalist(x)` | `true` if `x` is an array |
861
- | `isnothing(x)` | `true` if `x` is `shit` (`null`) or `idk` (`undefined`) |
862
- | `exists(x)` | `true` if `x` is neither `shit` nor `idk` |
857
+ | Function | Description |
858
+ | -------------- | ------------------------------------------------------- |
859
+ | `wtf(x)` | Type of `x` as a string |
860
+ | `x ispartof Y` | `true` if `x` is an instance of `Y` |
861
+ | `isalist(x)` | `true` if `x` is an array |
862
+ | `isnothing(x)` | `true` if `x` is `shit` (`null`) or `idk` (`undefined`) |
863
+ | `exists(x)` | `true` if `x` is neither `shit` nor `idk` |
863
864
 
864
865
  ```js
865
866
  sus (isnothing(user)) {
@@ -881,7 +882,7 @@ if (user === null || user === undefined) {
881
882
  }
882
883
 
883
884
  if (Array.isArray(data)) {
884
- data.forEach(function(item) {
885
+ data.forEach(function (item) {
885
886
  if (typeof item.id === "number") {
886
887
  console.log(item.id);
887
888
  }
@@ -931,4 +932,4 @@ x ispartof Y x instanceof Y
931
932
 
932
933
  ---
933
934
 
934
- *BroLang — because someone had to do it.*
935
+ _BroLang — because someone had to do it._
package/package.json CHANGED
@@ -1,38 +1,38 @@
1
- {
2
- "name": "@dramxx/brolang",
3
- "version": "0.1.0",
4
- "description": "JavaScript transpiler for people who peaked in 1997",
5
- "license": "MIT",
6
- "author": "dmaxx",
7
- "keywords": [
8
- "brolang",
9
- "transpiler",
10
- "javascript",
11
- "language",
12
- "cli",
13
- "bro"
14
- ],
15
- "engines": {
16
- "node": ">=14.0.0"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "https://github.com/dramxx/brolang.git"
21
- },
22
- "homepage": "https://github.com/dramxx/brolang#readme",
23
- "bugs": {
24
- "url": "https://github.com/dramxx/brolang/issues"
25
- },
26
- "files": [
27
- "bin",
28
- "src",
29
- "examples",
30
- "README.md"
31
- ],
32
- "bin": {
33
- "bro": "./bin/bro.js"
34
- },
35
- "scripts": {
36
- "test": "node test/transpiler.test.js"
37
- }
1
+ {
2
+ "name": "@dramxx/brolang",
3
+ "version": "0.1.1",
4
+ "description": "JavaScript transpiler for people who peaked in 1997",
5
+ "license": "MIT",
6
+ "author": "dmaxx",
7
+ "keywords": [
8
+ "brolang",
9
+ "transpiler",
10
+ "javascript",
11
+ "language",
12
+ "cli",
13
+ "bro"
14
+ ],
15
+ "engines": {
16
+ "node": ">=14.0.0"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/dramxx/brolang.git"
21
+ },
22
+ "homepage": "https://github.com/dramxx/brolang#readme",
23
+ "bugs": {
24
+ "url": "https://github.com/dramxx/brolang/issues"
25
+ },
26
+ "files": [
27
+ "bin",
28
+ "src",
29
+ "examples",
30
+ "README.md"
31
+ ],
32
+ "bin": {
33
+ "bro": "./bin/bro.js"
34
+ },
35
+ "scripts": {
36
+ "test": "node test/transpiler.test.js"
37
+ }
38
38
  }