Skip to content

Commit

Permalink
feat: add number format filter and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
martiuslim authored and yq314 committed Oct 29, 2019
1 parent 6a453ad commit 1a29f34
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ Braze's liquid is a subset of Shopify's liquid, hence some incompatible features

| Filter Name | Example | Notes |
| --- | --- | --- |
| url_escape | `'{{"hey<>hi" \| url_escape}}'` | ⚠️ this uses `encodeURI` which is slightly different from Braze's implementation |
| url_param_escape | `'{{"hey<>hi" \| url_param_escape}}'` | ⚠️ this uses `encodeURIComponent` which is slightly different from Braze's implementation |
| url_escape | `{{"hey<>hi" \| url_escape}}` | ⚠️ this uses `encodeURI` which is slightly different from Braze's implementation |
| url_param_escape | `{{"hey<>hi" \| url_param_escape}}` | ⚠️ this uses `encodeURIComponent` which is slightly different from Braze's implementation |

* [Property Accessor][braze/property_accessor]

| Filter Name | Example | Notes |
| --- | --- | --- |
| property_accessor | `{{hash \| property_accessor: 'key'}}` | Example hash: `{ 'key' => 'hello' }` | |
| property_accessor | `{{hash \| property_accessor: 'key'}}` | Example hash: `{ 'key' => 'hello' }` |
* Number Formatting

| Filter Name | Example | Notes |
| --- | --- | --- |
| number_with_delimiter | `{{123456 \| number_with_delimiter}}` | ⚠️ this uses `toLocaleString` which is slightly different from Braze's implementation |

* JSON Escape

| Filter Name | Example | Notes |
Expand Down Expand Up @@ -152,13 +158,6 @@ Braze's liquid is a subset of Shopify's liquid, hence some incompatible features

⚠️ At time of writing, Braze only support nesting 2 levels of content blocks

#### TBD
Below Braze supported [filters][braze/filters] are yet to be added:

* #### Number formatting filters
* number_with_delimiter

[braze/liquid]: https://www.braze.com/docs/user_guide/personalization_and_dynamic_content/liquid/overview/
[tutorial]: https://shopify.github.io/liquid/basics/introduction/
[liquidjs]: https://github.com/harttle/liquidjs
Expand Down
3 changes: 2 additions & 1 deletion src/braze/filters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import hash from './hash'
import json from './json'
import url from './url'
import encoding from './encoding'
import number from './number'

export default { ...hash, ...json, ...url, ...encoding }
export default { ...hash, ...json, ...url, ...encoding, ...number }
3 changes: 3 additions & 0 deletions src/braze/filters/number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
'number_with_delimiter': (x: string) => x.toLocaleString()
}
11 changes: 11 additions & 0 deletions test/integration/braze/filters/number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test } from '../../../stub/render'

describe('braze/filters/number', function () {
describe('number_with_delimiter', function () {
it('should return a number formatted with commas', () => test('{{123456 | number_with_delimiter}}', '123,456'))
it('should return a number formatted with commas', () => test('{{1234 | number_with_delimiter}}', '1,234'))
it('should return a number with no commas', () => test('{{123 | number_with_delimiter}}', '123'))
it('should return a float formatted with commas', () => test('{{123456.78 | number_with_delimiter}}', '123,456.78'))
it('should return a float with 3 decimal places formatted with commas', () => test('{{123456.789 | number_with_delimiter}}', '123,456.789'))
})
})

0 comments on commit 1a29f34

Please sign in to comment.