{"id":21712510,"url":"https://github.com/youfoundron/babel-plugin-syntax-exists","last_synced_at":"2025-04-12T18:08:23.560Z","repository":{"id":57155930,"uuid":"67163630","full_name":"youfoundron/babel-plugin-syntax-exists","owner":"youfoundron","description":"Allows parsing of an existential check in Babel.","archived":false,"fork":false,"pushed_at":"2017-04-08T17:39:07.000Z","size":14,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-14T09:14:43.874Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/youfoundron.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-01T20:21:27.000Z","updated_at":"2019-12-31T11:50:21.000Z","dependencies_parsed_at":"2022-08-30T06:50:17.500Z","dependency_job_id":null,"html_url":"https://github.com/youfoundron/babel-plugin-syntax-exists","commit_stats":null,"previous_names":["rongierlach/babel-plugin-syntax-exists"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youfoundron%2Fbabel-plugin-syntax-exists","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youfoundron%2Fbabel-plugin-syntax-exists/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youfoundron%2Fbabel-plugin-syntax-exists/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youfoundron%2Fbabel-plugin-syntax-exists/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/youfoundron","download_url":"https://codeload.github.com/youfoundron/babel-plugin-syntax-exists/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248217146,"owners_count":21066633,"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":"2024-11-25T23:39:30.515Z","updated_at":"2025-04-12T18:08:23.538Z","avatar_url":"https://github.com/youfoundron.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Babel Plugin: syntax-exists\nThis is a \u003ca href=\"https://babeljs.io\"\u003eBabel\u003c/a\u003e plugin which adds syntax for making existential checks in your code.  \nIt uses the the keyword `ex` which is short for *exists*. :sparkles:  \n  \n[![Build Status](https://travis-ci.org/rongierlach/babel-plugin-syntax-exists.svg?branch=master)](https://travis-ci.org/rongierlach/babel-plugin-syntax-exists) [![Dependency Status](https://david-dm.org/rongierlach/babel-plugin-syntax-exists.svg)](https://david-dm.org/rongierlach/babel-plugin-syntax-exists) [![devDependency Status](https://david-dm.org/rongierlach/babel-plugin-syntax-exists/dev-status.svg)](https://david-dm.org/rongierlach/babel-plugin-syntax-exists#info=devDependencies)\n\n# Features\n- [x] Return true if value exists\n- [x] Return false if value is null or undefined\n- [x] Return child if parent exists\n- [ ] Return false on child if parent is null or undefined\n- [x] Return function call if value is a function\n- [x] Return false for function call if value is not a function\n\n\n## What?\nFrom \u003ca href=\"https://arcturo.github.io/library/coffeescript/index.html\"\u003eThe Little Book on Coffeescript\u003c/a\u003e:\n\u003e Using `if` for `null` checks in JavaScript is common, but has a few pitfalls in that empty strings and `zero` are both coerced into `false`, which can catch you out. CoffeeScript existential operator `?` returns `true` unless a variable is `null` or `undefined`, similar to Ruby's `nil?`.  \n\n### So what does it look like?\n`foo.ex` transpiles to `typeof foo !== \"undefined\" \u0026\u0026 foo !== null`\n### How about a more exhilirating use case?\nGiven an object:\n```\nlet obj = {\n  attr: 'value',\n  nested_attr: { name: 'nested' },\n  func: () =\u003e 777\n}\n```\nWe can write write the following statements and expect the subsequent returns:\n```\nobj.ex.attr              // 'value'\nobj.attr.ex              // true\nobj.nested_attr.ex.name  // 'nested'\n\n// Oh, and it works for functions too...\n// --------------------------------------\nobj.func.ex              // true\nobj.func.ex()            // 777\n\n// But what about undefined errors?\n// --------------------------------------\nobj.doesnt_exist.ex      // false\nobj.doesnt_exist.ex.nope // false, currently unsupported :(\nobj.not_a_func.ex()      // false\n```\n## Installation\n`$ npm install babel-plugin-syntax-exists`\n\n## Usage\n### Via **`.babelrc`** (Recommended)\n**babelrc**\n```\n{\n  \"plugins\": [\"syntax-exists\"]\n}\n```\n\n### Via CLI\n`$ babel --plugins syntax-exists script.js`\n\n### Via Node API\n```\nrequire('babel').transform('code', {\n  plugins: ['syntax-exists']\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoufoundron%2Fbabel-plugin-syntax-exists","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoufoundron%2Fbabel-plugin-syntax-exists","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoufoundron%2Fbabel-plugin-syntax-exists/lists"}