Currency reading in range - javascript

I am working on JavaScript program which gets as input string and should return JSON or any other form with organized currency parts.
For example: func("2 kEURO") should return {value:2, scalar:"thousand", currency:"EURO"}. I have list of currency and scalar symbols but I would like to correctly read "from 2k to 5k USD" as well. I am using now js parser and it is enough for simple sentences.
I would like to ask if you know any others methods to make it done? I have been looking but what I found was only parsers with regex. It would be awesome if I could also read "5k in USD, 4k in EURO" any ideas?
Kind regards.

Related

Need to compare contents of word template & actual PDF

I have 2 files (word & pdf) and need to compare them. word doc will be template which defines how pdf should be generated. Below are the samples.
Word doc:
<firstname>,<LastName>
<ID>,<organization>
<salary>,<place>
Dear <firstname>,
you are working in the department of <organization> and we are really honored to have you here. Expecting many more successful years of service from you.
Thanks,
Actual PDF:
John, Kennedy
234,google
USD1245,CA
Dear John,
you are working in the department of google and we are really honored to have you here. Expecting many more successful years of service from you.
Thanks,
Can someone help with the comparison logic to validate both the static and dynamic content are getting generated as expected??
we are using TestComplete with JavaScript for the automation.
If you know what is in the template, you could start with some regex splitting first few lines where are all variables. Then read the template, replace every variable with values got from pdf beggining and if the replaced text matches the text in pdf, then you have pdf built from template.
Regex splitting example: read word file, split every line, get the first 3 lines, split them with ",", and set the vars to coresponding indexes.
As I said, this works only if you know the content of the template

What is a simple, reversible, non-cryptographic string cypher function with excellent avalanching?

I need to implement a pair of functions to obfuscate / deobfuscate a string, in the form:
string cipher(string plainText, string secret)
string decipher(string cipherText, string secret)
I need them to be terse and simple to implement. I am hoping for e.g. about a page of code or less that I will embed in my code body with no special dependencies. I will need to implement this in C# and vanilla JavaScript in-browser.
This does not need to be cryptographically secure; it is totally OK if it is trivial to hack.
Most of all I am looking for a function with excellent avalanching, i.e. small changes to the plain text input result in drastically different cipher text output.
I am considering a few possibilities, including XTEA and NTSA. But what I have seen so far is small changes e.g. to the end of the plain text result only in (somewhat) small changes to the end of the cipher text. Hence the changes appear to be localized. This is not great for my use, where the plain text will include an ever-incrementing timestamp as its main source of entropy.
What is a good function or algorithm to achieve this, without resorting to large bodies of code or dependencies?
I think I have decided on XXTEA prefaced with a random number salt prefix, which appears to give excellent avalanching. Thank you #Christopher for reminding me about this technique.

When should I split a JSON into smaller parts?

I want to use cmudict file in a web. It contains 170000 words with its phonetic transcription (in ARPAbet symbols).
http://www.speech.cs.cmu.edu/cgi-bin/cmudict
I want to use it in JSON format, search any word introduced by the user and return an explanation of how to pronounce it syllabe by syllabe. The second part is not very complex in search terms as there are only 39 different phonemes, but the first one with the 170000 entries may consume too much time if the user introduces a text instead of a single word to transcript.
I wonder if it's worth to split the JSON into for example 26 parts (one per initial letter) and search only in the corresponding file.
Also I don't know if JSON is the best format for this, but I want to use it in a free blog like Tumblr or Blogger ones (or similar, the thing is that I don't want to spend money in this) and Javascript is what they support. I would listen suggestions on this too.
Well, that is tough call since you must consider download size. I would shorten the names of all your properties to be as small as possible, so instead of repeating "description" : "the short description", I would go with "sd" : "the short description". You are trying to use javascript to serve a data file, which is okay since you can rely on caching and what not, but the initial download size may be rather large. I would do something like var myDictionary = { }; at the top of the file, that way you can reference the variable since it is in the global space. It is an interesting experiment for sure.

jQuery (or Javascript) Way to Format a Number Based on a Given C#/VBA/Java Format String

I have a number being returned from a database with an associated format string. For the purposes of this example think 2 columns.
Value FormatString ----> DESIRED OUTPUT FROM JAVASCRIPT/JQUERY
----- ------------ -------------------------------------
100 #0.00 100.00
100000 #0,.0K 100.0K
.193 #0.0% 19.3%
Formatting options include # of decimal points, thousands separator or not, magnitude (K,M,B), percent, currency, etc. The format strings work just fine in C# and VBA (and I believe Java uses the same format strings).
I am looking for a javascript way (using whatever library is applicable, jQuery preferred) to provide the raw value and the format string and have it return a formatted number.
We are trying to re-write an app and this is what the database is giving us...can't change the database (and not sure I would want to either as the database shouldn't care about formatting the numbers for display).
Worst case: we have to change all the format strings to something javascript likes...but even then I have yet to find a usable solution that accepts a format string.
EDIT
I have looked into the following libraries/plugins/tools.
Numeral.js
DecimalFormat.js
jquery-numberformatter
All have varying levels of "correctness" (as it applies to the C#/VBA format strings). I could probably hack something together using 1 of the above as a starting point but want to see if there is something already out there.
Numeral.js feels like the most promising but it doesn't handle magnitude the way I need (it wants to auto determine the magnitude for you based on the value passed in). This feels like the "easiest" one to alter if that is the ultimate solution.
And after sleeping on it and trying to google again the morning I believe I have found what I need.
flexible-js
This appears to be working as I would expect. Don't know if it handles every use case perfectly but based on initial testing it looks to be working as I need.

Insert EBCDIC character into javascript string

I need to create an EBCDIC string within my javascript and save it into an EBCDIC database. A process on the EBCDIC system then uses the data. I haven't had any problems until I came across the character '¬'. In EBCDIC it is hex value of 5F. All of the usual letters and symbols seem to automagically convert with no problem. Any idea how I can create the EBCDIC value for '¬' within javascript so I can store it properly in the EBCDIC db?
Thanks!
If "all of the usual letters and symbols seem to automagically convert", then I very strongly suspect that you do not have to create an EBCDIC string in Javascript. The character codes for Latin letters and digits are completely different in EBCDIC than they are in Unicode, so something in your server code is already converting the strings.
Thus what you need to determine is how that process works, and specifically you need to find out how the translation maps character codes from Unicode source into the EBCDIC equivalents. Once you know that, you'll know what Unicode character to use in your Javascript code.
As a further note: every single time I've been told by an IT organization that their mainframe software requires that data be supplied in EBCDIC, that advice has been dead wrong. The fact that there's some external interface means that something in the pile of iron that makes up the mainframe and it's tentacles, something the IT people have forgotten about and probably couldn't find if they needed to, is already mapping "real world" character encodings like Unicode into EBCDIC. How does it work? Well, it may be impossible to figure out.
You might try whether this works: var notSign = "\u00AC";
edit: also: here's a good reference for HTML entities and Unicode glyphs: http://www.elizabethcastro.com/html/extras/entities.html The HTML/XML syntax uses decimal numbers for the character codes. For Javascript, you have to convert those to hex, and the notation in Javascript strings is "\u" followed by a 4-digit hex constant. (That reference isn't complete, but it's pretty easy to read and it's got lots of useful symbols.)

Categories

Resources