{"id":15353759,"url":"https://github.com/westonganger/js-try","last_synced_at":"2025-04-15T05:57:40.200Z","repository":{"id":57283774,"uuid":"97187484","full_name":"westonganger/js-try","owner":"westonganger","description":"JS-Try is a Javascript implementation of the try method from Rails for safe navigation","archived":false,"fork":false,"pushed_at":"2024-09-06T19:56:36.000Z","size":11,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T05:57:34.688Z","etag":null,"topics":["javascript","js","node-js","rails","ruby","safe-navigation","try"],"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/westonganger.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-14T03:07:20.000Z","updated_at":"2024-09-06T19:56:40.000Z","dependencies_parsed_at":"2024-10-16T02:40:49.575Z","dependency_job_id":null,"html_url":"https://github.com/westonganger/js-try","commit_stats":{"total_commits":8,"total_committers":2,"mean_commits":4.0,"dds":0.25,"last_synced_commit":"5fa8485eaef83e6dcebc6a4d961ea709f4af4501"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westonganger%2Fjs-try","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westonganger%2Fjs-try/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westonganger%2Fjs-try/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westonganger%2Fjs-try/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/westonganger","download_url":"https://codeload.github.com/westonganger/js-try/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016325,"owners_count":21198832,"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":["javascript","js","node-js","rails","ruby","safe-navigation","try"],"created_at":"2024-10-01T12:15:06.565Z","updated_at":"2025-04-15T05:57:40.170Z","avatar_url":"https://github.com/westonganger.png","language":"JavaScript","funding_links":["https://ko-fi.com/A5071NK'"],"categories":[],"sub_categories":[],"readme":"# JS-Try\n\u003ca href=\"https://badge.fury.io/js/js-try\" target=\"_blank\"\u003e\u003cimg height=\"21\" style='border:0px;height:21px;' border='0' src=\"https://badge.fury.io/js/js-try.svg\" alt=\"NPM Version\"\u003e\u003c/a\u003e\n\u003ca href='https://github.com/westonganger/js-try/actions' target='_blank'\u003e\u003cimg src=\"https://github.com/westonganger/js-try/actions/workflows/test.yml/badge.svg?branch=master\" style=\"max-width:100%;\" height='21' style='border:0px;height:21px;' border='0' alt=\"CI Status\"\u003e\u003c/a\u003e\n\u003ca href='https://www.npmjs.org/package/js-try' target='_blank'\u003e\u003cimg height='21' style='border:0px;height:21px;' src='https://img.shields.io/npm/dt/js-try.svg?label=NPM+Downloads' border='0' alt='NPM Downloads' /\u003e\u003c/a\u003e\n\u003ca href='https://ko-fi.com/A5071NK' target='_blank'\u003e\u003cimg height='22' style='border:0px;height:22px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee' /\u003e\u003c/a\u003e\n\nJS-Try is a Javascript implementation of the try method from Rails for safe navigation.\n\n# Install\n\n#### Yarn, NPM, or Bower\n```javascript\nyarn add js-try\n\nnpm install js-try\n\nbower install js-try\n```\n\n#### Rails / Bundler\n\n```ruby\n# Gemfile\nsource 'https://rails-assets.org' do\n  gem 'rails-assets-js-try'\nend\n\n\n# app/assets/javascripts/application.js\n/*\n *= require js-try\n*/\n```\n\n# Usage\n#### Require/Import\n```javascript\nvar Try = require('js-try');\n// or\nimport { Try } from 'js-try';\n```\n\n#### Basic Examples\n```javascript\nTry(undefined) == false;\nTry(null) == false;\nTry(false) == false;\nTry(true) == true;\nTry(0) == 0;\nTry('') == '';\nTry('foobar') == 'foobar';\nTry([]) == [];\nTry({}) == {};\n\nfalse.try('length') == false;\ntrue.try('length') == false;\n\n''.try('length') == 0;\n''.try('foobar') == false;\n'foobar'.try('charAt', 3) == 'b';\n''.try('badMethod').try('anotherBadMethod'); == false\n\nvar x = 0;\nx.try('toString') == '0';\nx.try('foobar') == false;\n\n[].try('sort') == [];\n[].try('foobar') == false;\n[1,2,3].try(2) == 3;\n[1,2,3].try(3) == false;\n\n{}.try('toString') == \"[object Object]\";\n{}.try('foobar') == false;\n{foo: 'bar'}.try('foo') == 'bar';\n{foo: 'bar'}.try('bar') == false;\n```\n\n# Credits\nCreated by Weston Ganger - [@westonganger](https://github.com/westonganger)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwestonganger%2Fjs-try","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwestonganger%2Fjs-try","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwestonganger%2Fjs-try/lists"}