{"id":28229237,"url":"https://github.com/dibsonthis/sprig","last_synced_at":"2025-06-10T14:30:46.320Z","repository":{"id":258573884,"uuid":"871487935","full_name":"dibsonthis/sprig","owner":"dibsonthis","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-08T06:17:10.000Z","size":301,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-18T15:13:52.435Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dibsonthis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-12T05:23:33.000Z","updated_at":"2025-02-08T06:17:13.000Z","dependencies_parsed_at":"2024-10-28T15:06:15.204Z","dependency_job_id":"68f1e27e-ead2-4b93-a915-34b2b3843b13","html_url":"https://github.com/dibsonthis/sprig","commit_stats":null,"previous_names":["dibsonthis/sprig"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dibsonthis%2Fsprig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dibsonthis%2Fsprig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dibsonthis%2Fsprig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dibsonthis%2Fsprig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dibsonthis","download_url":"https://codeload.github.com/dibsonthis/sprig/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dibsonthis%2Fsprig/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259092522,"owners_count":22804029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-18T15:13:52.109Z","updated_at":"2025-06-10T14:30:46.307Z","avatar_url":"https://github.com/dibsonthis.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sprig 🌿 A Language Sprouting From NodeJS\n\nSprig is a dynamic programming language built on NodeJS that allows developers to write efficient code. It leverages the capabilities of NodeJS while providing its own syntax and useful extensions.\n\n## Key Features\n\n- **Bi-Directional Data Flow**: Sprig enables seamless data exchange between NodeJS and the Sprig environment, making it easy to utilize existing NodeJS libraries and functions within your Sprig code.\n\n- **Extensibility**: Sprig is designed for easy extension, allowing developers to create native JS functionality on the fly to extend the language.\n\n- **Integration with NodeJS**: Sprig takes advantage of NodeJS’s non-blocking I/O and asynchronous programming model, providing a robust framework for building scalable applications.\n\n## Getting Started\n\n1. **Installation**: Clone the repository and install dependencies:\n\n   ```bash\n   git clone https://github.com/dibsonthis/sprig.git\n   cd sprig\n   npm install\n   ```\n\n2. **Build the executable**: Use the following command to build the sprig executable - this compiles and packages sprig into the bin folder:\n\n   ```bash\n   npm run package (or package:win for Windows)\n   ```\n\n3. **Install the executable**: To install sprig globally, use the following script:\n   ```bash\n   npm run bin (or bin:win for Windows)\n   ```\n\n### Your first Sprig program\n\n```python\nconst greet = (name) =\u003e `Hey {{name}}, welcome to Sprig 🌿`\n\n\"friend\"-\u003egreet-\u003eprint // Hey friend, welcome to Sprig 🌿\ngreet(\"pal\")-\u003eprint() // Hey pal, welcome to Sprig 🌿\nprint(greet(\"buddy\")) // Hey buddy, welcome to Sprig 🌿\n```\n\n### Leveraging NodeJS on the fly\n\n```python\nconst nativeAdd = exec(`(a, b) =\u003e a + b`);\n(100 + nativeAdd(20, 30))-\u003eprint // 150\n\nconst rawBuffer = exec(`(size) =\u003e Buffer.alloc(size)`)\nconst buffer = rawBuffer(10)\nprint(buffer) // Buffer* Raw\u003cobject\u003e\nprint(buffer-\u003evalue) // { 0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, readBigUInt64LE: native: 'readBigUInt64LE' (offset = 0), readBigUInt64BE: native: 'readBigUInt64BE' (offset = 0) ... }\n```\n\n## Further Examples\n\n### Proxies\n\nMuch like JS, we can create object proxies that whose native functionality can be intercepted via a handler object. Note that '\\_' means the intercept applies to all the properties. Property keys can also be provided here for specificity.\n\n```python\nconst person = {\n        name: \"Jack\",\n        id: 43,\n        address: {\n            name: \"123 Fake st.\"\n        }\n    }\n\n    const handler = {\n        repr: {\n            _: (v) =\u003e \"***\"\n        },\n        get: {\n            _: (v) =\u003e (v ? [v] : undefined)\n        },\n        set: {\n            _: (o, k, v, c) =\u003e {\n                if (o[k]) {\n                    return v\n                }\n                return undefined\n            }\n        },\n    }\n\n    const personProxy = person-\u003eproxy(handler)\n    personProxy.age = 45\n    personProxy.id = 1001\n\n    print(personProxy.name[0]) // \"Jack\"\n    print(personProxy.id[0]) // 1001\n    print(personProxy.age) // undefined\n```\n\n## Classes\n\nClasses are simply constructor functions in Sprig. The difference between a normal function and a constructor is the parentheses in the function name. Anything returned from a constructor will have its type be that constructor function.\n\n```python\nconst (Color) = (r = 0, g = 0, b = 0) =\u003e {\n        const color = {r: 0, g: 0, b: 0}-\u003eproxy({\n            repr: {\n                r: (v) =\u003e `\\e[31m{{v}}\\e[0m`,\n                g: (v) =\u003e `\\e[32m{{v}}\\e[0m`,\n                b: (v) =\u003e `\\e[34m{{v}}\\e[0m`,\n            },\n            set: {\n                _: (o, k, v, c) =\u003e {\n                    if (v \u003c 0) {\n                        return 0\n                    }\n                    if (v \u003e 255) {\n                        return 255\n                    }\n                    return v\n                }\n            }\n        })\n\n        color.r = r\n        color.g = g\n        color.b = b\n\n        return color\n    }\n\n    const c = Color()\n\n    c.r = 20\n    c.g = 400\n    c.b = -34\n\n    const constructor = c-\u003eclass\n\n    print(c.r) // 20\n    print(c.g) // 255\n    print(c.b) // 0\n```\n\n## Coroutines\n\nSprig supports coroutines out of the box. Any function that has a yield statement is automatically identified as a coroutine.\n\n```python\nconst coro = () =\u003e {\n        var x = 0\n        while (true) {\n            yield x += 1\n        }\n    }\n\n    const c1 = coro();\n\n    while ((let c = c1()) \u003c= 10) {\n        // do nothing\n    }\n\n    print(c) // 11\n\n    const coroAdvanced = (init, value) =\u003e {\n        var x = init\n        while (true) {\n            yield x += value\n        }\n    }\n\n    const cAdvanced = coroAdvanced(100);\n\n    const res = cAdvanced(20)\n\n    print(res) // 120\n```\n\n## Async\n\nSince Sprig is built on top of NodeJS, async is automatically supported. For the time being, async/await syntax is not yet supported, however asynchronous programming is available via the old school callback approach via `-\u003ethen` and `-\u003ecatch`.\n\n```python\n    fetch(\"https://jsonplaceholder.typicode.com/todos/1\")-\u003ethen((data) =\u003e {\n        print(\"retrieved data\")\n    })-\u003ecatch((e) =\u003e print((e-\u003evalue).message))\n\n    print(\"here\")\n\n    // here\n    // retrieved data\n```\n\n## Common\n\nCommon built-ins can be accessed globally or through the \\_\\_common object.\n\n```python\nconst commonKeys = __common\n    -\u003ekeys\n    -\u003efilter((k) =\u003e k[0] != \"_\")\n    -\u003eprint\n\n// [instanceOf, includes, reduce, slice, timeout, interval, fetch, then, catch, delay, promise, toNumber, toString, truncate, Io, Json, Server, Str, Testing, Websocket]\n```\n\n## Config overrides\n\nAdding a `config.sp` file at the top level can set global variables and create custom operators. Anything in the `globals` object will be injected into the global scope. Operators defined in `operators` can be either unary or binary based on the number of parameters provided. Dynamically resolved paths can also be added here, via the `paths` property.\n\nThese two objects can also be accessed via `__config`.\n\n```python\n\n// config.sp\n\nconst globals = {\n    APP_ID: \"app-0001\",\n}\n\nconst operators = {\n    \"$$\": (a, b) =\u003e {\n        return (a * b) / 3\n    },\n    \"#\": (v) =\u003e {\n        return [v]\n    },\n}\n\nconst paths = {\n    \"@modules\": \"../../../modules\"\n}\n```\n\nMore examples can be found in `testing/tests.sp`.\n\nTo run those tests using the built-in Testing suite, simply run:\n\n```bash\nsprig testing/tests.sp\n```\n\n## Modules\n\nAlongside creating native NodeJS functionality on the fly, Sprig also allows you to define modules that can be imported and used in your programs. Refer to `src/modules` folder to see how these are set up and used.\n\n## Documentation\n\nHead over to the official [Sprig Docs](https://dibs.gitbook.io/sprig-docs) to learn more about Sprig!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdibsonthis%2Fsprig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdibsonthis%2Fsprig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdibsonthis%2Fsprig/lists"}