nodeJS, MySQL and UTF8 - javascript

I am trying to write a custom String.Prototype function:
String.prototype.Apos = function () {
var string = this.innerHTML.toString();
return string.replace(/’/g,"'").replace(/“|â€/g,'"');
};
I really just want to write a utf8 string to the browser using javascript, however using decodeURIComponent wont work and so I have just resorted to replacing the apostrophes myself.
So from the examples I've seen I wrote the above function, however it doesnt seem to return anything. When I run the following:
$("span").html(string.Apos);
I don't get a response. I've never written a custom prototype function before so could someone help me out and tell me where Im going wrong?

Do you really need to mess with string.prototype?
You can write a function to do the specific job you want to perform, i.e., replace text.
function replaceQuotes(i, oldHtml) {
return oldHtml.toString().replace(/’/g,"'").replace(/“|â€/g,'"');
}
And then:
$("span").html(replaceQuotes);

Related

INPUT_GET doesn't work with some strings?

I'm encountering a situation I can't figure out and passing along a string from javascript to PHP via jquery. Simply put when I have a y+ it doesn't seem to pass from javascript to PHP, but when it says y- it does pass. Here is a code for the HTML.
This happens if I type in any math expression that starts with y+. It also happens if it starts with x+. If I change the equation around in anyways as to the string being passed it works unless it starts with one of those two. I've looked at how input_get works but can't find any limitations on the plus sign, similar to how you have to be careful with things like quotes or . I figure there is something like this which is stopping the string from being passed along.
Javascript side:
function initResults(data) {
document.getElementById("test").innerHTML=data;
}
function init() {
var equation=document.getElementById("username").value;
$.get("test.php",{equation: equation},initResults);
}
PHP side:
$equation=filter_input(INPUT_GET,"equation");
print"$equation from php file";
There are no error messages, it just doesn't pass. Below is two screenshots first where it works, the other where it doesn't. I've typed in multiple examples on what works and what doesn't work which I included in the third screenshot. Thanks!

How to make javascript function can use after dot

I'm doing firebase project these days, and i got a question about something.
var citiesRef = db.collection("cities");
citiesRef.where("state", ">=", "CA").where("population", ">", 100000)
Those where() are stick together after dot and i have no idea.
How can i make function or class like that? I don't even know how to search !
I tried to make classes and unnamed functions but it doesn't work.
If i get to know about it, it'll be very useful for me. I really want to know.
Please help please
This is something akin to the Builder Pattern. The idea is to return the object after appending a condition.
Example code (language agnostic):
def where(condition){
self.appendCondition(condition)
return self // Important part
}
The return self enables to chain methods on the same object. Each one returns itself with the new condition appended.

JavaScript RegExp test returns wrong value

I am solving curious problem right now. I am testing a string with regexp and it returns false eventhough it should return true. I am implementing it in javascript. I have this function
function isPhoneNumberValid(phoneNumber) {
return /^\+\d{12}$/.test(phoneNumber);
}
phoneNumber is a variable in format of + and 12 numbers after (+421123123123 for example). I've played around with different versions of regexp like /^\+[0-9]{12}$/.
According to sites like https://www.regextester.com/21 my regexp should be working for the format I want, yet it returns false still. When I tried testing this regexp /^\+[0-9]/ it returned true when only +3 was written, I guess the problem is with the numbers count?
Parameter phoneNumber received in the function is correct one so I don't think the mistake is there. Also no combination of modifiers helped.
Here is a log of this function
function isPhoneNumberValid(phoneNumber) {
console.log('ph:'+phoneNumber);
console.log(/^\+\d{12}$/.test(phoneNumber));
}
To give you more insight I have a input type text with class .phoneNumber, then I have jquery function watching keyup event, it looks like this
$('.phoneNumber').on('keyup', function() {
if (isPhoneNumberValid($(this).val())) {
console.log('is valid');
} else {
console.log( 'invalid');
}
});
Other function you've already seen above. I tried wrapping values in String(), too.
I am trying to clarify why live example in online environment is for no good, since I know this code works in there as I already stated before. The question is aimed more to what could possibly make it go this way, since the exact same copy works in codepen, yet doesn't work in my project.
The problem was with latte template engine. It needed to have
<script n:syntax="double"></script>
to work.

google script - how to overcome fact, that it is not possible to use built in function in custom function

at the starting point - I am completely new to programming, so maybe my question is silly.
Please could you give me some advice with this problem?
function GETCOUNTFROMTITLE(title) {
var re = new Regexp ("^[0-9]+.[cC]ount");
if (re.test(title) ){
return "yes";
}
}
In custom function, I need to process regular expression evaluation a then do some more operation with given string, but I am getting error message
"ReferenceError: undefined „Regexp“. (row 2, file „code“)".
How can I make this work?
Thank you very much
any advice will help
Javascript is case-sensitive.
You mean RegExp.
Also, you should use a regex literal instead.
And, you should return a boolean.

Decoding Javascript File

need to know wich kind of encoded is this:
$(_0x6b88[150])[_0x6b88[149]]();
$(_0x6b88[154])[_0x6b88[153]](function () {
$(this)[_0x6b88[151]](_0x6b88[14]);
})[_0x6b88[152]](function () {
$(this)[_0x6b88[151]](_0x6b88[12]);
});
I had encoded my js code some months ago and now I dont know where I saved the beautified version.
Can anyone help me? How can I decode this? It look like Hexadecimal or something (_0x6b88[14]) but the rect [] looks very strange too me.
Thanks.
0x6b88 is a number in hexadecimal.
so _0x6b88 is like writing _27528, or myinteger. It is a variable name, the name doesn't really matter.
(_27528 is a different variable to _0x6b88, though)
It looks like an array, so lets replace it with alist to make it easier to understand:
$(alist[150])[alist[149]](); // runs an element with id alist[149]
$(alist[154])[alist[153]]( // runs an element and gives it a function
function () {
$(this)[alist[151]](alist[14]);
}
)
[alist[152]]( // gets an element from what ever is returned by the function
function () { // Passes a function to the element gotten
$(this)[alist[151]](alist8[12]);
}
);
alist[0] is the first element in the array. Inorder to work out what this does, you need to know what is in the cells of those arrays.
It is probably best to rewrite your code; it will be easier that way. It has been obfuscated, so you'll have a hard time working it out.
You probably won't be able to get the original variables names, although that depends on the software you used for obfuscating the code.

Categories

Resources