{"id":17617374,"url":"https://github.com/danestves/browser-monads-ts","last_synced_at":"2025-08-26T15:24:12.072Z","repository":{"id":42958021,"uuid":"362971737","full_name":"danestves/browser-monads-ts","owner":"danestves","description":"Provide interfaces for the window, document and navigator variables of a webpage to be used on SSR and Client.","archived":false,"fork":false,"pushed_at":"2022-08-11T18:19:37.000Z","size":261,"stargazers_count":5,"open_issues_count":6,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-30T18:11:42.642Z","etag":null,"topics":["browser-monads","document","gatsby","javascript","navigator","nextjs","typescript","window"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danestves.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-29T23:21:39.000Z","updated_at":"2023-03-08T22:11:30.000Z","dependencies_parsed_at":"2022-09-02T20:22:40.465Z","dependency_job_id":null,"html_url":"https://github.com/danestves/browser-monads-ts","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danestves%2Fbrowser-monads-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danestves%2Fbrowser-monads-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danestves%2Fbrowser-monads-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danestves%2Fbrowser-monads-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danestves","download_url":"https://codeload.github.com/danestves/browser-monads-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251758173,"owners_count":21638989,"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":["browser-monads","document","gatsby","javascript","navigator","nextjs","typescript","window"],"created_at":"2024-10-22T19:13:13.689Z","updated_at":"2025-04-30T18:11:53.278Z","avatar_url":"https://github.com/danestves.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Browser Monads TS\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.org/package/browser-monads-ts\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/browser-monads-ts/latest.svg\" alt=\"NPM Version\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.org/package/browser-monads-ts\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dm/browser-monads-ts.svg\" alt=\"Monthly download on NPM\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/danestves/browser-monads-ts/actions\"\u003e\n    \u003cimg src=\"https://github.com/danestves/browser-monads-ts/workflows/CI/badge.svg\" alt=\"Workflow of main.yml action\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003e This package is inspired by [browser-monads](https://github.com/Jense5/browser-monads) currently without support from the author.\n\nProvide interfaces for the `window`, `document` and `navigator` variables of a webpage.\n\n## What is a monad?\n\n\u003e In functional programming, a monad is an abstraction that allows structuring programs generically. Supporting languages may use monads to abstract away boilerplate code needed by the program logic.\n\u003e\n\u003e -Wikipedia - [Monad (functional programming)](\u003chttps://en.wikipedia.org/wiki/Monad_(functional_programming)\u003e)\n\nYou don't really have to know what a monad is since the variables provided by this library aren't _really_ monads. Let's take a look at the `window` variable to get a basic understanding. The main purpose of this variable is that it _may be a window_ or it _may be nothing_. You don't know what it is and you shouldn't really care. In case it is a window, you can use it as you're used to. In case it is not a window, you can still use the same functions on the instance. The caring about the existence of the variable is already taken care of.\n\nThis same concept is applicable to the `document` variable too. You can use the `exists` function in order to check if the variable exists or you are operating on an instance that contains _nothing_.\n\n## Why use monads?\n\nThis library makes it possible to use these variables without checks with [Gatsby](https://www.gatsbyjs.org) and [NextJS](https://nextjs.org/). This way of programming splits the defensive part from your own code, since you don't have to care anymore about the environment in which you are running. This makes it especially useful with server-side rendering. More info about the `nothing`-type can be found [here](https://github.com/slmgc/Nothing).\n\n## Example\n\n```js\nimport { window, document, exists } from 'browser-monads-ts';\n\n// inside browser ? window.location.href : ''\nwindow.location.href;\n\n// inside browser ? document.getElementById(\"myId\") : ''\ndocument.getElementById('myId');\n\n// inside browser ? true : false\nexists(window);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanestves%2Fbrowser-monads-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanestves%2Fbrowser-monads-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanestves%2Fbrowser-monads-ts/lists"}