Releases: cshaa/filtrex
v3.1.0
v3.0.0
Breaking Changes
- Trying to access properties that aren't present in the
data
object now produces an error (#22) - Logical values are no longer converted to
1
and0
, proper booleans are returned instead (#27) - Corrected the precedence of exponentiation (#41, #43)
- Modulo now always returns a positive number (#36)
- Removed
random
from standard functions (#47) - Corrected the precedence of
not in
(#42) - Corrected the precedence of the ternary operator (#34)
Deprecations
- The ternary operator
? :
is now deprecated in favor ofif..then..else
(#34) - Modulo operator
%
is now deprecated in favor ofmod
(#48)
New Features
-
Chained comparisons are now possible:
x>y>z
, meaningx>y and y>z
(#37) -
Operators can now be overloaded using
options.operators['+']
and the like (#38)- The supported operators are
+
,-
,*
,/
,mod
,^
,==
,!=
,<
,<=
,>=
,>
,~=
- The minus operator overload is used for both the binary and the unary operator:
-a
will result inoperators['-'](a)
a - b
will result inoperators['-'](a, b)
.
- The supported operators are
-
Errors are now i18n-friendly (#35)
-
err.I18N_STRING
will return one of the following strings:UNKNOWN_FUNCTION
, English message: “Unknown function:<funcName>
”UNKNOWN_PROPERTY
, English message: “Property “<propName>
” does not exist.”UNKNOWN_OPTION
, English message: “Unknown option:<key>
”UNEXPECTED_TYPE
, English message: “Expected a<expected>
, but got a<got>
instead.”INTERNAL
, does not have a standardized message
-
The values in angled brackeds are available as properties on the error, eg.
err.funcName
anderr.propName
-
Parse errors are sadly not i18n-friendly yet – this is a limitation of Jison (#55)
-
-
Adds
options.constants
, which allows you to pass constant values (like pi) to the user without the need to modifydata
(#38)- When using unquoted symbols, constants shadow data properties, ie.
2*pi
will resolve as2*constants.pi
if it is defined - Quoted symbols always resolve as data properties, ie.
2*'pi'
will always resolve as2*data.pi
- When using unquoted symbols, constants shadow data properties, ie.
-
Optionally, you use dot as a property accessor (#44)
- The available predefined
prop
functions are:useOptionalChaining
,useDotAccessOperator
anduseDotAccessOperatorAndOptionalChaining
customProp
now has additional argumenttype: 'unescaped' | 'single-quoted'
- The available predefined
v2.2.0
Minor improvements
Changelog
-
Added support for quote-escaping in string literals and quoted symbols.
"some \"quoted\" string and a \\ backslash"
'a \'quoted\' symbol and a \\ backslash'
- Breaking change: Backslash
\
character now has to be escaped\\
. - These expressions throw a syntax error:
"\'"
,'\"'
,"\n"
(use literal newline),"\anythingother"
-
Added support for
in
operator with runtime arrays.value in array
will return1
when the value is present in the array and0
otherwisearray in array
will return1
when the first array is a subset of the second one,0
otherwisearray in value
andvalue in value
technically also work, they convertvalue
to[value]
.
-
Changed the
compileExpression
method's call signature- Breaking change.
- Previously the method had up to three parameters:
expression
,extraFunctions
andcustomProp
. - Now the method has two parameters:
expression
andoptions
, whereoptions = { extraFunctions, customProp }
. - Current exported types:
export function compileExpression(
expression: string,
options?: Options
): (obj: any) => any
export interface Options
{
extraFunctions?: {
[T: string]: Function
},
customProp?: (
name: string,
get: (name: string) => any,
object: any
) => any
}
Stable and safe
First publish from @m93a.