{"id":19220420,"url":"https://github.com/louisbrunner/exist-utils","last_synced_at":"2026-05-17T10:36:05.840Z","repository":{"id":19546746,"uuid":"87304075","full_name":"LouisBrunner/exist-utils","owner":"LouisBrunner","description":"Utility functions that emulate CoffeeScript existence operator","archived":false,"fork":false,"pushed_at":"2023-10-18T07:47:06.000Z","size":1882,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-14T19:43:16.027Z","etag":null,"topics":["coffee","coffee-script","coffeescript","elvis","exists","utils"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/LouisBrunner.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":"2017-04-05T11:58:47.000Z","updated_at":"2024-06-11T21:11:16.021Z","dependencies_parsed_at":"2023-01-11T20:30:12.356Z","dependency_job_id":"3c7f0468-7a38-4bad-80c8-1f395033698a","html_url":"https://github.com/LouisBrunner/exist-utils","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LouisBrunner%2Fexist-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LouisBrunner%2Fexist-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LouisBrunner%2Fexist-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LouisBrunner%2Fexist-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LouisBrunner","download_url":"https://codeload.github.com/LouisBrunner/exist-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240293492,"owners_count":19778527,"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":["coffee","coffee-script","coffeescript","elvis","exists","utils"],"created_at":"2024-11-09T14:35:05.802Z","updated_at":"2026-05-17T10:36:05.808Z","avatar_url":"https://github.com/LouisBrunner.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# exist-utils [![NPM Version][npm-image]][npm-url] ![Build Status][ci-image] [![Coverage Status][coveralls-image]][coveralls-url] [![dependencies Status][deps-image]][deps-url] [![devDependencies Status][deps-dev-image]][deps-dev-url]\n\nThis package is a collection of util functions that emulate _CoffeeScript_ existence operator.\nWhile waiting that some of them are integrated in the [next version of JavaScript](https://github.com/tc39/proposals), you can use this package while porting from _CoffeeScript_, etc.\n\n\n## Installation\n\n### Node Installation\n\n```sh\nnpm install exist-utils\n```\n\nYou can then `ExistUtils = require('exist-utils')` or `import * as ExistUtils from 'exist-utils'`.\n\n### Browser Installation\n\nUse the minified UMD build in the `dist` folder: [here](dist/exist-utils.min.js).\nIt exports a global `window.ExistUtils` when imported as a `\u003cscript\u003e` tag.\n\n\n## Usage\n\nEach function as a full name (i.e. `exists`) and a shorthand (i.e. `ex`), both are specified in the title of their description.\nYou can check the equivalence with _CoffeeScript_ operators in the [following section](#coffeescript-equivalents).\n\n### `exists` (`ex`)\n\nExample:\n```js\nif (!exists(arg)) {\n  error('missing arg');\n}\n```\n\nThis is the equivalent to _CoffeeScript_ `val?`, it checks if a value \"exists\" (is neither `null` nor `undefined`).\n\n### `existsChained` (`exc`)\n\nExample:\n```js\nif (!existsChained(arg, 'callback')) {\n  error('no callback specified');\n}\n```\n\nThis is the equivalent to _CoffeeScript_ `obj?.prop?`, it checks if a whole chain \"exists\".\n\n### `existsChainedValue` (`excv`)\n\nExample:\n```js\nconst callback = existsChainedValue(arg, 'callback');\nif (!exists(callback)) {\n  error('no callback specified');\n  return;\n}\ncallback();\n```\n\nThis is the equivalent to _CoffeeScript_ `obj?.prop`, it checks if a whole chain \"exists\" and returns the final value.\n\n### `elvis` (`el`)\n\nExample:\n```js\nval = elvis(arg, 42);\n```\n\nThis is the equivalent to _CoffeeScript_ `val ? default` and a safer version to `val || default`.\nIt returns the second value if the first one doesn't \"exist\".\n\n### `callsIfExist` (`fnex`)\n\nExample:\n```js\ncallsIfExist(func, 1, 2);\n```\n\nThis is the equivalent to _CoffeeScript_ `func?(1, 2)`, it checks the existence of the function and calls it with the provided arguments.\n\n### `callsIfExistObj` (`fnexo`)\n\nExample:\n```js\ncallsIfExistObj(obj, 'func', 1, 2);\n```\n\nThis is the equivalent to _CoffeeScript_ `obj?.func?(1, 2)`, it checks the existence of the function and calls it with the provided arguments while providing the right value for `this`.\n\n\n## _CoffeeScript_ equivalents\n\n| CoffeeScript             | `exist-utils`                      | `exist-utils` shorthand    |\n|:-------------------------|:-----------------------------------|:---------------------------|\n| `val?`                   | `exists(val)`                      | `ex(val)`                  |\n| `obj?.prop?`             | `existsChained(obj, 'prop')`       | `exc(obj, 'prop')`         |\n| `obj?.prop`              | `existsChainedValue(obj, 'prop')`  | `excv(obj, 'prop')`        |\n| `val = arg ? 3`          | `val = elvis(arg, 3)`              | `val = el(arg, 3)`         |\n| `func?(a, b)`            | `callsIfExist(func, a, b)`         | `fnex(func, a, b)`         |\n| `obj.func?(a, b)`        | `callsIfExistObj(obj, func, a, b)` | `fnexo(obj, func, a, b)`   |\n\n\n## License\n\nMIT, Copyright (c) 2017-2020 Louis Brunner\n\n\n\n[npm-image]: https://img.shields.io/npm/v/exist-utils.svg\n[npm-url]: https://npmjs.org/package/exist-utils\n[ci-image]: https://github.com/LouisBrunner/exist-utils/workflows/Build/badge.svg\n[coveralls-image]: https://coveralls.io/repos/github/LouisBrunner/exist-utils/badge.svg?branch=master\n[coveralls-url]: https://coveralls.io/github/LouisBrunner/exist-utils?branch=master\n[deps-image]: https://david-dm.org/louisbrunner/exist-utils/status.svg\n[deps-url]: https://david-dm.org/louisbrunner/exist-utils\n[deps-dev-image]: https://david-dm.org/louisbrunner/exist-utils/dev-status.svg\n[deps-dev-url]: https://david-dm.org/louisbrunner/exist-utils?type=dev\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flouisbrunner%2Fexist-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flouisbrunner%2Fexist-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flouisbrunner%2Fexist-utils/lists"}