DynamicString
DynamicString
A dynamic value is smart string that can contain dynamic values and plain strings. You can insert them anywhere (headers, URL params, body, environment variables) in the requests you create with Paw.
A dynamic string can be seen as an array of components each being either a string
or a DynamicValue. When Paw generates requests, client code or evaluates dynamic strings via the JavaScript API each component is evaluated and all are concatenated together to form a result string
DynamicString
DynamicString
Argument:
...items: string || DynamicValue: None
A
string
or
DynamicValue
The constructor DynamicValue() is globally available in Paw. It takes at least one argument, and up to two.
function import(context, items, options) {
// create a dynamic value
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
'input':'MY_TOKEN'
});
// create a dynamic string
// we concatenate a string + a dynamic value + another string
var dynamicString = DynamicString("Hash...", dynamicValue, "...");
}
length
length
The number of components the dynamic string has. This does not reflect the character length of the string.
function import(context, items, options) {
// create a dynamic value
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
'input':'MY_TOKEN'
});
// create a dynamic string
var dynamicString = DynamicString("Hash...", dynamicValue, "...");
console.log(dynamicString.length); // 3
}
components
components
All components as an array, a component may be either a
string
or a
DynamicValue.
function import(context, items, options) {
// create a dynamic value
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
'input':'MY_TOKEN'
});
// create a dynamic string
var dynamicString = DynamicString("Hash...", dynamicValue, "...");
// get all components
var components = dynamicString.components;
console.log(components[0]); // "Hash..."
console.log(components[1].toString()); // "DynamicValue<com.luckymarmot.HashDynamicValue>"
console.log(components[2]); // "..."
}
toString
toString
Returns: None: string
Returns a simple and pretty representation of the dynamic string.
function import(context, items, options) {
// create a dynamic value
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
'input':'MY_TOKEN'
});
// create a dynamic string
var dynamicString = DynamicString("Hash...", dynamicValue, "...");
console.log(dynamicString.toString()); // DynamicString<3 component(s)>
}
getComponentAtIndex
getComponentAtIndex
Argument: index: integer: None
Index of component to get
Returns: None: string || DynamicValue
Returns the component at the index
or returns null
if out of bounds.
function import(context, items, options) {
// create a dynamic value
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
'input':'MY_TOKEN'
});
// create a dynamic string
var dynamicString = DynamicString("Hash...", dynamicValue, "...");
console.log(dynamicString.getComponentAtIndex(0)); // "Hash..."
console.log(dynamicString.getComponentAtIndex(1)); // "DynamicValue<com.luckymarmot.HashDynamicValue>"
console.log(dynamicString.getComponentAtIndex(2)); // "..."
}
getSimpleString
getSimpleString
Returns: None: string
Concatenates together only string
components and ignores DynamicValues
function import(context, items, options) {
// create a dynamic value
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
'input':'MY_TOKEN'
});
// create a dynamic string
var dynamicString = DynamicString("Hash{", dynamicValue, "}");
console.log(dynamicString.getSimpleString()); // "Hash{}"
}
getOnlyString
getOnlyString
Returns: None: string
Returns the only string
component.
If the dynamic string contains only one string
component, returns it, otherwise returns null
.
getOnlyDynamicValue
getOnlyDynamicValue
If the dynamic string contains only one DynamicValues component, returns it, otherwise returns null
.
getEvaluatedString
getEvaluatedString
Returns: None: string
Evaluates the dynamic string and returns a static string
.
Each component is evaluated: strings
are left as is while DynamicValues are replaced by their evaluated value. Resulting items are then concatenated to form the evaluated string.
function import(context, items, options) {
// create a dynamic value
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
'input':'MY_TOKEN'
});
// create a dynamic string
var dynamicString = DynamicString("Hash{", dynamicValue, "}");
// evaluates the dynamic string
var str = dynamicString.getEvaluatedString();
console.log(str); // "Hash{1f27bb78c3de8d3833243e9eb6b4b43aa84fa9e0}"
}
copy
copy
Returns: None: DynamicString
Returns a copy of this DynamicString.
Returns a duplicate of the dynamic string. Dynamic strings not created via the constructor DynamicString()
are immutable, you can copy them and perform updates on the duplicate.
appendString
appendString
Argument: newString: string: None
the new string to append
Appends a string at the end of the dynamic string.
Dynamic strings not created via the constructor DynamicString()
are immutable, you can copy them and perform updates on the duplicate.
function import(context, items, options) {
// create a dynamic value
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
'input':'MY_TOKEN'
});
// create a dynamic string
var dynamicString = DynamicString("Hash", dynamicValue);
// append a new string
dynamicString.appendString("!!!");
}
appendDynamicValue
appendDynamicValue
Argument:
newDynamicValue: DynamicValue: None
the new
DynamicValues to append
Appends a DynamicValues at the end of the dynamic string.
Dynamic strings not created via the constructor DynamicString()
are immutable, you can copy them and perform updates on the duplicate.
function import(context, items, options) {
// create a dynamic string
var dynamicString = DynamicString("Hash");
// create a dynamic value
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
'input':'MY_TOKEN'
});
// append the dynamic value
dynamicString.appendDynamicValue(dynamicValue);
}
appendDynamicString
appendDynamicString
Argument: dynamicString: DynamicString: None
the new DynamicString to append
Appends another dynamic string at the end of the target dynamic string.
Dynamic strings not created via the constructor DynamicString()
are immutable, you can copy them and perform updates on the duplicate.
function import(context, items, options) {
// create a dynamic value
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
'input':'MY_TOKEN'
});
// create a dynamic string
var dynamicString = DynamicString("Hash", dynamicValue);
// create another dynamic string
var anotherDynamicString = DynamicString(";Signature", dynamicValue);
// append a dynamic string to the other one
// "Hash" + dynamicValue + ";Signature" + dynamicValue
dynamicString.appendDynamicString(anotherDynamicString);
}