How can I use datetime format without have interpolation escape to false - datetime

Doing this:
// JSON
{
"intlDateTime": "On the {{val, datetime}}",
}
i18next.t('intlDateTime', { val: new Date(Date.UTC(2012, 11, 20, 3, 0, 0)) });
// --> On the 12/20/2012
without interpolation escape to false
ends with a display of / instead of "/"
How can we use date format and avoid xss attacks at the same time ?
To solve the wrong display, I need to write:
{t('lastModified', {
val: new Date(Date.UTC(2012, 11, 20, 3, 0, 0)),
interpolation: { escapeValue: false },
})}
which I would like to avoid.

Related

Json Path property filter structure

newtonsoft version 13.0.1
given the object data which is a JToken with the content of:
{
"myString": "demo2",
"myNumber": 2.2,
"myInteger": 20,
"myObject": {
"myObject": {
"myArray": [
2,
20,
200,
2000
]
},
"myArray": [
2,
20,
200,
2000
]
},
"myArray": [
2,
20,
200,
2000
],
"myBoolean": true,
"myNull": null
}
and the selecttokens command like this.
data.SelectTokens("$..myObject[?(#.myArray)]")
I expect to get one object back. but it doesn't return any. Is there something I do wrong here?
if I try it on https://jsonpath.com/ it will return me an object.
or should I test it like $..[?(#.myObject.myArray)]

How can i get the values in eloquent relation array result of laravel 8

I have a result array from laravel8 relations. like below
$val = {
"q_id": 1,
"q_text": "1111",
"q_mandatory": 1,
"q_status": "unpublished",
"que_logic_relation": [
{
"ql_id": 1,
"ql_quest_id": 1,
"ql_answer_choice_id": null,
"ql_succeeding_q_order": 3,
},
{
"ql_id": 4,
"ql_quest_id": 1,
"ql_answer_choice_id": null,
"ql_succeeding_q_order": 3,
}
]
}
When I print $val['q_text'] // output 1111
when I print $val['que_logic_relation'] //no result or empty
I want to print the data in que_logic_relation seperately. How can I do that?
Issued fixed by adding toArray() to the query result and everything works fine now.

Firebase data update to retain other data

I have this current data structure on my firebase
{
"bible-operators": [{
"op-id": 0,
"op-name": "Anonymous",
"bcv": 101001001,
"op-version": 1,
"pass": "none",
"setting1": 1,
"setting2": 2,
"setting3": 3,
"setting4": 4,
"setting5": 5,
"setting6": 6,
"setting7": 7,
"bg": 1
}, ... {
"op-id": 4,
"op-name": "Test User 4",
"bcv": 101001001,
"op-version": 1,
"pass": "pass4",
"setting1": 1,
"setting2": 2,
"setting3": 3,
"setting4": 4,
"setting5": 5,
"setting6": 6,
"setting7": 7,
"bg": 1
}]
}
I tried to make test update using this function
function update(op_id, nuname, nuversion, nubcv, nupass) {
firebase.database().ref('operators/' + op_id).set({
"op-name": nuname,
"op-version": nuversion,
pass: nupass,
bcv : nubcv
});
}
My expected result is to update the provided new data but retain the others that has no updates. However, after calling update, all non provided data were deleted from the database. setting1-7 and bg.
How can I run the update without losing data that has no new data provided?
Thanks
The function firebase.database().ref('bible-operators/' + op_id).set() replace the document, you have to use update() instead of set().
try it:
firebase.database().ref('bible-operators/' + op_id).update({
"op-name": nuname,
"op-version": nuversion,
pass: nupass,
bcv : nubcv
});

Using a key within a map

I have this function:
def getMap(value = null) {
[
"SomeTitle": [ Param: 9, Size: 2, Default: 150, Val: value ]
]
}
and I can use getMap(152).SomeTitle.Val
What I want to do is use the key Size while calculating the Key Val, something like:
def getMap(value = null) {
[
"SomeTitle": [ Param: 9, Size: 2, Default: 150, Val: value * Size ]
]
}
Is there a way to use the Value of a Key within a map as a variable while calculating the Value of a another Key
This in Java/Groovy
Groovy can't autoreference the map on it's initialization, but you can use a with {} method to do some post-initialization processing:
def getMap(value = null) {
[
"SomeTitle": [ Param: 9, Size: 2, Default: 150 ].with {
put('Val', value * get('Size'))
it
}
]
}
assert getMap(10).SomeTitle.Val == 20

ractivejs list sorting , ascending decending support?

Im trying to understand if there is a feature in ractivejs , for descending sorting , and ascending .
I couldnt find anyhting in the documentation .
No - Ractive purposely avoids being a 'kitchen sink' utility library. But it's very easy to add an ascending or descending helper:
var helpers = Ractive.defaults.data;
// assuming a and b are numbers...
helpers.ascending = function ( a, b ) {
return a - b;
};
helpers.descending = function ( a, b ) {
return b - a;
};
ractive = new Ractive({
el: 'body',
template: '' +
'<p>ascending: {{ numbers.slice().sort(ascending) }}</p>' +
'<p>descending: {{ numbers.slice().sort(descending) }}</p>'
},
data: {
numbers: [ 9, 4, 6, 2, 4, 1, 10, 2, 7, 8 ]
}
});
Note that you could also put the ascending and descending functions directly on the data object, if that's preferable.
Here's a JSFiddle to demonstrate: http://jsfiddle.net/rich_harris/nszt3150/

Resources