Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,33 @@ addons:
chrome: stable

cache:
directories:
- $HOME/.npm
yarn: true

env:
# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- EMBER_TRY_SCENARIO=ember-lts-2.8
- EMBER_TRY_SCENARIO=ember-lts-2.12
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=ember-default
global:
# See https://git.io/vdao3 for details.
- JOBS=1
matrix:
# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- EMBER_TRY_SCENARIO=ember-lts-2.8
- EMBER_TRY_SCENARIO=ember-lts-2.12
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=ember-default

matrix:
fast_finish: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary

before_install:
- npm config set spin false
- npm install -g npm@4
- npm --version
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH

install:
- yarn install --no-lockfile --non-interactive

script:
# Usually, it's ok to finish the test scenario without reverting
Expand Down
43 changes: 43 additions & 0 deletions DEPRECATIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 1.0.0

## `fmt`
### until: 2.0.0
### id: ember-string-fmt

This utility was included to ease the transition from the
internal Ember string package to this addon.
We suggest that you update your code to use [ES2015 template strings](http://babeljs.io/docs/learn-es2015/#template-strings).

For example, if you have the following `fmt` uses:

```javascript
import { fmt } from "@ember/string";

let firstName = "John";
let lastName = "Doe";

fmt("Hello %@ %@", firstName, lastName); // "Hello John Doe"
fmt("Hello %@2, %@1", firstName, lastName); // "Hello Doe, John"
```

You can instead use the following template strings:

```javascript
import { fmt } from "@ember/string";

let firstName = "John";
let lastName = "Doe";

`Hello ${firstName} ${lastName}` // "Hello John Doe"
`Hello ${lastName}, ${firstName}` // "Hello Doe, John"
```


## `loc`
### until: 2.0.0
### id: ember-string-loc

This utility was included to ease the transition from the
internal Ember string package to this addon.
You can consult the [Ember deprecation guide for loc](https://emberjs.com/deprecations/v2.x#toc_code-ember-string-loc-code-and-code-import-loc-from-ember-string-code) for further
instructions on how to update your code.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# ember-string
# @ember/string

This README outlines the details of collaborating on this Ember addon.

## Installation

* `git clone <repository-url>` this repository
* `cd ember-string`
* `npm install`
* `cd @ember/string`
* `yarn install`

## Running

Expand All @@ -15,7 +15,7 @@ This README outlines the details of collaborating on this Ember addon.

## Running Tests

* `npm test` (Runs `ember try:each` to test your addon against multiple Ember versions)
* `yarn test` (Runs `ember try:each` to test your addon against multiple Ember versions)
* `ember test`
* `ember test --server`

Expand Down
73 changes: 73 additions & 0 deletions addon/cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const UNDEFINED = function() {}

export default class Cache {
constructor(limit, func, key, store) {
this.size = 0;
this.misses = 0;
this.hits = 0;
this.limit = limit;
this.func = func;
this.key = key;
this.store = store || new DefaultStore();
}

get(obj) {
let key = this.key === undefined ? obj : this.key(obj);
let value = this.store.get(key);
if (value === undefined) {
this.misses ++;
value = this._set(key, this.func(obj));
} else if (value === UNDEFINED) {
this.hits ++;
value = undefined;
} else {
this.hits ++;
// nothing to translate
}

return value;
}

set(obj, value) {
let key = this.key === undefined ? obj : this.key(obj);
return this._set(key, value);
}

_set(key, value) {
if (this.limit > this.size) {
this.size ++;
if (value === undefined) {
this.store.set(key, UNDEFINED);
} else {
this.store.set(key, value);
}
}

return value;
}

purge() {
this.store.clear();
this.size = 0;
this.hits = 0;
this.misses = 0;
}
}

class DefaultStore {
constructor() {
this.data = Object.create(null);
}

get(key) {
return this.data[key];
}

set(key, value) {
this.data[key] = value;
}

clear() {
this.data = Object.create(null);
}
}
Loading