Skip to content

Commit

Permalink
feat: add $stringEndsWith expression
Browse files Browse the repository at this point in the history
  • Loading branch information
simonfan committed Mar 30, 2021
1 parent eaab2f9 commit 444d162
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Array [
"$pipe",
"$string",
"$stringConcat",
"$stringEndsWith",
"$stringInterpolate",
"$stringLength",
"$stringPadEnd",
Expand Down
7 changes: 7 additions & 0 deletions src/expressions/string.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ describe('$stringStartsWith', () => {
])
})

describe('$stringEndsWith', () => {
_evTestCases([
['some_string', ['$stringEndsWith', '_string'], true],
['some_string', ['$stringEndsWith', 'somethingelse'], false],
])
})

describe('$stringLength', () => {
_evTestCases([
['some_string', ['$stringLength'], 11],
Expand Down
12 changes: 12 additions & 0 deletions src/expressions/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ export const $stringStartsWith: InterpreterSpec = [
['string', 'string'],
]

/**
* @function $stringEndsWith
* @param {String} query
* @param {string} [str=$$VALUE]
* @returns {Boolean}
*/
export const $stringEndsWith: InterpreterSpec = [
(query: string, str: string): boolean => str.endsWith(query),
['string', 'string'],
]

/**
* @function $stringLength
* @param {String} [str=$$VALUE]
Expand Down Expand Up @@ -200,6 +211,7 @@ export const $stringInterpolate: InterpreterSpec = [
export const STRING_EXPRESSIONS = {
$string,
$stringStartsWith,
$stringEndsWith,
$stringLength,
$stringSubstr,
$stringConcat,
Expand Down

0 comments on commit 444d162

Please sign in to comment.