# js-try

> JS-try is a Javascript implementation of the try method from Rails for safe navigation

Latest version **0.9.1** (published 2017-07-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install js-try
pnpm add js-try
yarn add js-try
bun add js-try
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.1 |
| Published | 2017-07-18 |
| First published | 2017-07-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Weston Ganger |
| Maintainers | westonganger |
| Keywords | try, safe-navigation, jquery, javascript, js, rails, ruby |

## Links

- npm: https://www.npmjs.com/package/js-try
- Repository: https://github.com/westonganger/js-try
- Issues: https://github.com/westonganger/js-try/issues
- npm.io page: https://npm.io/package/js-try

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.9.1 (latest) — 2017-07-18
- 0.9.0 — 2017-07-14

## README

# JS-Try [![Build Status](https://api.travis-ci.org/westonganger/js-try.svg?branch=master)](https://travis-ci.org/westonganger/js-try)

JS-Try is a Javascript implementation of the try method from Rails for safe navigation.

# Install

#### Yarn, NPM, or Bower
```javascript
yarn add js-try

npm install js-try

bower install js-try
```

#### Rails / Bundler

```ruby
# Gemfile
source 'https://rails-assets.org' do
  gem 'rails-assets-js-try'
end


# app/assets/javascripts/application.js
/*
 *= require js-try
*/
```

# Usage
#### Require/Import
```javascript
var Try = require('js-try');
// or
import { Try } from 'js-try';
```

#### Basic Examples
```javascript
Try(undefined) == false;
Try(null) == false;
Try(false) == false;
Try(true) == true;
Try(0) == 0;
Try('') == '';
Try('foobar') == 'foobar';
Try([]) == [];
Try({}) == {};

false.try('length') == false;
true.try('length') == false;

''.try('length') == 0;
''.try('foobar') == false;
'foobar'.try('charAt', 3) == 'b';
''.try('badMethod').try('anotherBadMethod'); == false

var x = 0;
x.try('toString') == '0';
x.try('foobar') == false;

[].try('sort') == [];
[].try('foobar') == false;
[1,2,3].try(2) == 3;
[1,2,3].try(3) == false;

{}.try('toString') == "[object Object]";
{}.try('foobar') == false;
{foo: 'bar'}.try('foo') == 'bar';
{foo: 'bar'}.try('bar') == false;
```

# Credits
Created by Weston Ganger - [@westonganger](https://github.com/westonganger)

For any consulting or contract work please contact me via my company website: [Solid Foundation Web Development](https://solidfoundationwebdev.com)

## Similar Libraries Created By Me
- [Rearmed-JS](https://github.com/westonganger/rearmed-js)
- [Rearmed-CSS](https://github.com/westonganger/rearmed-css)
- [Rearmed Ruby](https://github.com/westonganger/rearmed-rb)
- [Rearmed Rails](https://github.com/westonganger/rearmed_rails)

---
_Source: https://npm.io/package/js-try · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
