# ember-compatibility-helpers

> Zero-cost compatibility flags and helpers for Ember.js

Latest version **1.2.7** (published 2023-10-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-compatibility-helpers
pnpm add ember-compatibility-helpers
yarn add ember-compatibility-helpers
bun add ember-compatibility-helpers
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.7 |
| Published | 2023-10-31 |
| First published | 2017-07-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 10.* \|\| >= 12.* |
| Dependencies | 5 |
| Unpacked size | 25.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Maintainers | rwjblue, pzuraq, katiegengler |
| Keywords | ember-addon |

## Links

- npm: https://www.npmjs.com/package/ember-compatibility-helpers
- Repository: https://github.com/pzuraq/ember-compatibility-helpers
- Homepage: https://github.com/pzuraq/ember-compatibility-helpers#readme
- Issues: https://github.com/pzuraq/ember-compatibility-helpers/issues
- npm.io page: https://npm.io/package/ember-compatibility-helpers

## Dependencies (5)

- [semver](https://npm.io/package/semver.md) ^5.4.1
- [find-up](https://npm.io/package/find-up.md) ^5.0.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^9.1.0
- [babel-plugin-debug-macros](https://npm.io/package/babel-plugin-debug-macros.md) ^0.2.0
- [ember-cli-version-checker](https://npm.io/package/ember-cli-version-checker.md) ^5.1.1

## Recent versions

- 1.2.7 (latest) — 2023-10-31
- 1.2.0-beta.1 (next) — 2018-10-20
- 1.2.6 — 2022-02-10
- 1.2.5 — 2021-08-09
- 1.2.4 — 2021-03-29
- 1.2.3 — 2021-03-23
- 1.2.2 — 2020-11-10
- 1.2.1 — 2020-04-22
- 1.2.0 — 2019-02-11
- 1.1.2 — 2018-10-03
- 1.1.1 — 2018-10-03
- 1.1.0 — 2018-10-02
- 1.0.2 — 2018-07-20
- 1.0.1 — 2018-07-18
- 1.0.0 — 2018-04-27
- … 8 more at https://npm.io/package/ember-compatibility-helpers/versions

## README

[![Build Status](https://travis-ci.org/pzuraq/ember-compatibility-helpers.svg?branch=master)](https://travis-ci.org/pzuraq/ember-compatibility-helpers) [![npm version](https://badge.fury.io/js/ember-compatibility-helpers.svg)](https://badge.fury.io/js/ember-compatibility-helpers)

# ember-compatibility-helpers

Provides flags for features in Ember, allowing you to write code that will work
with whatever version the consuming application is on. This addon is intended
to help addon authors write backwards/forwards compatibility code.

The flags are replaced at build time with boolean literals (`true` or `false`)
by a Babel transform. When ran through a minifier (with dead code elimination) the entire section will be stripped, meaning that the section of code which is not used
will not be added to production builds - zero cost compatibility!

## Installation

```
ember install ember-compatibility-helpers
```

## Available Flags

```js
import {
  // General functions for checking against Ember version
  gte,
  lte,

  // Flags for specific Ember functionality
  HAS_UNDERSCORE_ACTIONS,
  HAS_MODERN_FACTORY_INJECTIONS,

  IS_GLIMMER_2,
  IS_RECORD_DATA,

  SUPPORTS_FACTORY_FOR,
  SUPPORTS_GET_OWNER,
  SUPPORTS_SET_OWNER,
  SUPPORTS_NEW_COMPUTED,
  SUPPORTS_INVERSE_BLOCK,
  SUPPORTS_CLOSURE_ACTIONS,
  SUPPORTS_UNIQ_BY_COMPUTED
} from 'ember-compatibility-helpers';
```

More welcome, open an issue or a PR!

## Version Identifiers

Version strings passed to version checker functions, such as `gte` or `lte`, must be fully qualified versions. Version ranges or shorthands are not supported.

```
// Do this:
lte('3.13.0-beta.1')

// Not this:
lte('3.12'); // won't work!
lte('^3.12.0'); // won't work!
```

## Example Usage for testing ember-source versions

```js
import Component from '@glimmer/component';
import { get } from '@ember/object';

import { gte } from 'ember-compatibility-helpers';

export default class MyComponent extends Component {
  get aProp() {
    if (gte('4.0.0')) {
      return this.args.aProxy.name;
    } else {
      return get(this.args.aProxy, 'name');
    }
  }  
}
```

## Example Usage for testing other addon package versions

```js
import Component from '@glimmer/component';
import { get } from '@ember/object';

import { gte } from 'ember-compatibility-helpers';

export default class MyComponent extends Component {
  get aProp() {
    if (gte('my-ember-addon', '1.2.3')) {
      return this.args.newProp;
    } else {
      return this.args.oldProp;
    }
  }  
}
```

## Example Flag usage:

```javascript
import Component from '@ember/component';
import { computed } from '@ember/object';

import { SUPPORTS_NEW_COMPUTED } from 'ember-compatibility-helpers';

function fooMacro() {
  if (SUPPORTS_NEW_COMPUTED) {
    return computed({
      get() {
        return this.get('foo');
      },

      set(key, value) {
        this.set('foo', value);
        return value
      }
    });
  } else {
    return computed(function(key, value) {
      if (arguments.length === 2) {
        this.set('foo', value);
        return value;
      }

      return this.get('foo');
    })
  }
}

export default Component.extend({
  bar: fooMacro()
});
```

## Development

* `git clone <repository-url>` this repository
* `cd ember-compatibility-helpers`
* `yarn`

## Running Tests

* `npm test`

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