@@ -3,6 +3,7 @@ import SetAssetReferenceAction from "./variable/SetAssetReferenceAction";
33import SetFromContextAction from "./variable/SetFromContextAction" ;
44import SetFromMetadataAction from "./variable/SetFromMetadataAction" ;
55import { ExpressionQualifier } from "../qualifiers/expression/ExpressionQualifier" ;
6+ import { toFloatAsString } from "../internal/utils/toFloatAsString" ;
67
78/**
89 * Defines a new user variable with the given value.
@@ -34,14 +35,67 @@ import {ExpressionQualifier} from "../qualifiers/expression/ExpressionQualifier"
3435 * @summary action
3536 * @description Sets a new user variable with the given value.
3637 * @memberOf Actions.Variable
37- * @param name Variable name
38+ * @param { string } name Variable name
3839 * @param {number | string | number[] | string[] } value Variable value
3940 * @return {Actions.Variable.SetAction }
4041 */
4142function set ( name : string , value : number | string | number [ ] | string [ ] | ExpressionQualifier ) : SetAction {
43+ if ( Object . prototype . hasOwnProperty . call ( value , 'push' ) ) {
44+ return new SetAction ( name , value ) ;
45+ }
46+
4247 return new SetAction ( name , value ) ;
4348}
4449
50+ /**
51+ * @summary action
52+ * @description Same as 'set', but forces the end value to be a float setFloat(1) will result in $foo_1.0
53+ * @memberOf Actions.Variable
54+ * @param {string } name Variable name
55+ * @param {number } value Variable value
56+ * @return {Actions.Variable.SetAction }
57+ */
58+ function setFloat ( name : string , value : number ) : SetAction {
59+ return new SetAction ( name , toFloatAsString ( value ) , '' ) ;
60+ }
61+
62+ /**
63+ * @summary action
64+ * @description Same as 'set', but forces the end value to be an integer setInteger(1.1) will result in $foo_1, input is rounded down
65+ * @memberOf Actions.Variable
66+ * @param {string } name Variable name
67+ * @param {number } value Variable value
68+ * @return {Actions.Variable.SetAction }
69+ */
70+ function setInteger ( name : string , value : number ) : SetAction {
71+ let val = value ;
72+ if ( typeof value === 'string' ) {
73+ val = parseInt ( value ) ;
74+ }
75+
76+ if ( isNaN ( val ) ) {
77+ val = 0 ;
78+ }
79+
80+ return new SetAction ( name , Math . round ( val ) ) ;
81+ }
82+
83+
84+ /**
85+ * @summary action
86+ * @description Same as 'set', but forces the end value to be a string setString(1) will result in $foo_!1!
87+ * @memberOf Actions.Variable
88+ * @param {string, number } name Variable name
89+ * @param {number } value Variable value
90+ * @return {Actions.Variable.SetAction }
91+ */
92+ function setString ( name : string , value : string | number ) : SetAction {
93+ return new SetAction ( name , value . toString ( ) ) ;
94+ }
95+
96+
97+
98+
4599/**
46100 * @summary action
47101 * @description Allows adding a variable by sending a key and value which is a reference to an asset.
@@ -82,12 +136,18 @@ function setFromMetadata(name: string, value: string): SetFromMetadataAction {
82136
83137const Variable = {
84138 set,
139+ setFloat,
140+ setString,
141+ setInteger,
85142 setAssetReference,
86143 setFromContext,
87144 setFromMetadata
88145} ;
89146export {
90147 set ,
148+ setFloat ,
149+ setString ,
150+ setInteger ,
91151 setAssetReference ,
92152 setFromContext ,
93153 setFromMetadata ,
0 commit comments