Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds pad for adding zero padding to a number. #514

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b792755
Adds pad for adding zero padding to a number.
jfrux Oct 11, 2018
0bfb215
Updates README.
jfrux Oct 11, 2018
cfed5bb
Fixes readme.
jfrux Oct 11, 2018
a0b4dc9
Updates Readme
jfrux Oct 11, 2018
c9e40b6
Add notEmpty macro (#512)
dnahodil Oct 19, 2018
75161ff
alphabetize change
Oct 19, 2018
d0d7245
Update dependency ember-cli-inject-live-reload to v2 (#515)
renovate[bot] Oct 19, 2018
acffdc8
Update dependency ember-source to ~3.5.0 (#511)
renovate[bot] Oct 19, 2018
a83f184
Update dependency ember-cli-babel to v7 (#509)
renovate[bot] Oct 19, 2018
0756369
update ember-cli 3.4 (#517)
Oct 19, 2018
0dc9e10
use npm 6
Oct 19, 2018
82fac14
Update dependency @ember/optional-features to ^0.7.0
renovate-bot Oct 19, 2018
8bc9486
Add missing boolean operations (#516)
dnahodil Oct 21, 2018
b1d6001
3.1.0
Oct 21, 2018
bb1c47b
update changelog
Oct 22, 2018
98e8286
Update dependency eslint-plugin-node to v8
renovate-bot Oct 27, 2018
5ec6555
Update dependency ember-load-initializers to v2
renovate-bot Oct 29, 2018
11cc571
Update dependency ember-cli-eslint to v5
renovate-bot Nov 9, 2018
467b144
Update dependency ember-sinon to v3
renovate-bot Nov 9, 2018
d6c3009
remove ember-macro-test-helpers
Nov 14, 2018
d6ec8ba
TravisCI: Remove deprecated `sudo: false` option
Turbo87 Dec 2, 2018
acf6ebb
update eslint-plugin-ember
Dec 2, 2018
52b3605
update ember-cli 3.5
Dec 2, 2018
261ec33
Update dependency ember-qunit to v4
renovate-bot Dec 2, 2018
fac9f54
Update dependency ember-source to ~3.6.0
renovate-bot Dec 7, 2018
6edc7c2
update ember-cli 3.6
Dec 31, 2018
1596ddd
Update dependency ember-source to ~3.7.0
renovate-bot Jan 7, 2019
0d170e7
ember-cli 3.7
Feb 2, 2019
48c3a8c
revert babel 7
Feb 14, 2019
67bf899
3.2.0
Feb 14, 2019
4351905
Revert "revert babel 7"
Feb 14, 2019
22d24c6
Update dependency ember-macro-helpers to v3
renovate-bot Feb 13, 2019
90cc540
4.0.0
Feb 14, 2019
0c45aad
update changelog
Feb 14, 2019
6e1e71f
Update dependency ember-source to ~3.8.0
renovate-bot Feb 18, 2019
5511f6c
Update dependency renovate-config-standard to v2
renovate-bot Mar 2, 2019
32c841b
fix eslint
Mar 8, 2019
f7ae3da
ember-cli-update
Mar 8, 2019
543d545
Update dependency eslint-config-sane to ^0.7.0
renovate-bot Mar 8, 2019
f78b7ca
Lock file maintenance
renovate-bot Apr 1, 2019
0a8a1a4
Update dependency ember-source to ~3.9.0
renovate-bot Apr 2, 2019
3937213
Fix isEmpty doc
ctjhoa Apr 19, 2019
102da9a
ember-cli-update
May 27, 2019
81bac65
Update dependency ember-sinon to v4
renovate-bot May 27, 2019
fbaf1a0
Update dependency ember-source-channel-url to v2
renovate-bot May 27, 2019
8c64ba1
Update dependency ember-try to v1
renovate-bot May 27, 2019
992f6e3
Lock file maintenance
renovate-bot May 27, 2019
de87424
5.0.0
May 27, 2019
d720d43
Lock file maintenance
renovate-bot Jun 1, 2019
7a01d15
Update dependency qunit-dom to ^0.9.0
renovate-bot Jun 14, 2019
b1de6ab
Update dependency ember-source to ~3.11.0
renovate-bot Jun 25, 2019
79a626f
Update dependency eslint-config-sane to ^0.8.0
renovate-bot Jul 21, 2019
6d6e158
update ember-cli
Jul 21, 2019
5549612
update changelog
Jul 23, 2019
e259590
Version bump to include bug fix: https://github.com/kellyselden/ember…
amyrlam Jul 28, 2019
2fa5f97
5.0.1
Jul 28, 2019
57158a8
Lock file maintenance
renovate-bot Aug 1, 2019
0d933a4
Update dependency ember-source to ~3.12.0
renovate-bot Aug 6, 2019
3700716
Update dependency ember-cli to ~3.12.0
renovate-bot Aug 16, 2019
1ced82f
Lock file maintenance
renovate-bot Sep 1, 2019
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ import { nameOfMacro } from 'ember-awesome-macros';
* [`quotient`](#quotient)
* [`subtract`](#subtract)
* [`sum`](#sum)
* [`pad`](#pad)

##### Object
* [`getBy`](#getby)
Expand Down Expand Up @@ -855,6 +856,18 @@ value1: or('source1', 'source2', 'source3'), // true
value2: or(not('source1'), 'source2', not('source3')) // false
```

##### `pad`
adds zero-padding to a number and returns a string, allows composing

```js
number1: 1,
size1: 3,
size2: '5',
example1: pad('number1','size1'), // 001
example2: pad('number1','size1'), // 001
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example1 and example2 are now the same.

example3: pad(raw(8),'size2') // 00008
```

##### `parseFloat`
wraps [`parseFloat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat), allows composing

Expand Down
1 change: 1 addition & 0 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export { default as isEmpty } from './is-empty';
export { default as isHtmlSafe } from './is-html-safe';
export { default as lt } from './lt';
export { default as lte } from './lte';
export { default as pad } from './pad';
export { default as math } from './math';
export { default as mod } from './mod';
export { default as multiply } from './multiply';
Expand Down
9 changes: 9 additions & 0 deletions addon/pad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { curriedComputed } from 'ember-macro-helpers';

export default curriedComputed((val1, val2) => {
let s = val1 + '';
while (s.length < parseInt(val2)) {
s = '0' + s;
}
return s;
});
5 changes: 5 additions & 0 deletions tests/acceptance/top-level-imports-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import macros, {
isEmpty,
lt,
lte,
pad,
math,
mod,
multiply,
Expand Down Expand Up @@ -114,6 +115,7 @@ import _isHtmlSafe from 'ember-awesome-macros/is-html-safe';
import _isEmpty from 'ember-awesome-macros/is-empty';
import _lt from 'ember-awesome-macros/lt';
import _lte from 'ember-awesome-macros/lte';
import _pad from 'ember-awesome-macros/pad';
import _mod from 'ember-awesome-macros/mod';
import _multiply from 'ember-awesome-macros/multiply';
import _neq from 'ember-awesome-macros/neq';
Expand Down Expand Up @@ -161,6 +163,7 @@ module('Acceptance | top level imports', function() {
assert.ok(macros.isEmpty);
assert.ok(macros.lt);
assert.ok(macros.lte);
assert.ok(macros.pad);
assert.ok(macros.math);
assert.ok(macros.mod);
assert.ok(macros.multiply);
Expand Down Expand Up @@ -257,6 +260,7 @@ module('Acceptance | top level imports', function() {
assert.ok(isEmpty);
assert.ok(lt);
assert.ok(lte);
assert.ok(pad);
assert.ok(math);
assert.ok(mod);
assert.ok(multiply);
Expand Down Expand Up @@ -352,6 +356,7 @@ module('Acceptance | top level imports', function() {
assert.ok(_isEmpty);
assert.ok(_lt);
assert.ok(_lte);
assert.ok(_pad);
assert.ok(_mod);
assert.ok(_multiply);
assert.ok(_neq);
Expand Down
45 changes: 45 additions & 0 deletions tests/integration/pad-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { pad, raw } from 'ember-awesome-macros';
import { module, test } from 'qunit';
import { compute } from 'ember-macro-test-helpers';

module('Integration | Macro | pad', function() {
test('pad returns 001', function(assert) {
compute({
assert,
computed: pad('source1', 'source2'),
properties: {
source1: 1,
source2: 3
},
strictEqual: '001'
});
});

test('pad with string source returns 001', function(assert) {
compute({
assert,
computed: pad('source1', 'source2'),
properties: {
source1: 1,
source2: '3'
},
strictEqual: '001'
});
});

test('it handles numbers', function(assert) {
compute({
assert,
computed: pad(1, 2),
strictEqual: '01'
});
});

test('it handles nesting', function(assert) {
compute({
assert,
computed: pad(raw(1), raw(2)),
strictEqual: '01'
});
});
});