Pulling data from .js file

I have a .js file with the following info:

function GetCESCustomerFacingVersion() {
return “018.20230227.2”;
}
function GetPSSCustomerFacingVersion() {
return “018.20230227.2”;
}
function GetTheAppVersion() {
return “018.20230227.2”;
}

I’m trying to create an analysis to just export the number. I’ve tried using the following:

preceding texts of first “;” of following text of first “return” of (it as string) of lines of files “C:\filename.js”

But I get “Singular expression refers to non-unique object” because there’s more than one. I even tried

preceding texts of last “;” of following text of last “return” of (it as string) of lines of files “C:\filename.js”

Hoping that it’ll grab the just the last return but that didn’t work either. Got the same message. I tried

preceding texts of last “;” of following text of last “GetTheAppVersion()” of (it as string) of lines of files “C:\filename.js”

But that also didn’t work because the GetTheAppVersion() is in a previous line. Any help would be appreciated.

Never mind. I figured it out. I used the following:

preceding texts of first “%22” of following text of first “%22” of (it as string) of line 18 of files “C:\filename.js”

This pulls the data from line 18 of the file and looks for anything between " " which worked for me

You have a number of problems

q: lines of file "c:\trn\fnh123.js"
A: function GetCESCustomerFacingVersion() {
A: return "018.20230227.2";
A: }
A: function GetPSSCustomerFacingVersion() {
A: return "018.20230227.2";
A: }
A: function GetTheAppVersion() {
A: return "018.20230227.2";
A: }
I: plural file line

Firstly, not all lines contain the data you want, so you need to filter to just get the lines that are useful (otherwise you get the ‘Singular expression’ error)

q: lines whose (it contains "return") of files "C:\trn\fnh123.js"
A: return "018.20230227.2";
A: return "018.20230227.2";
A: return "018.20230227.2";
I: plural file line

Then you still have multiple lines to parse and you either need to use plural relevance all the way through, which always looks messy, or use parenthesies so you tackle them individually

q: (preceding text of first ";" of following text of first "return" of it) of lines whose (it contains "return") of files "C:\trn\fnh123.js"
A:  "018.20230227.2"
A:  "018.20230227.2"
A:  "018.20230227.2"
I: plural substring

You now have the data you want, but still have multiple answers, and in not quite the right format
You could change your parsing to remove the unwanted quotes, but in this case we can use a cast to get the correct format

q: (it as version) of (preceding text of first ";" of following text of first "return" of it) of lines whose (it contains "return") of files "C:\trn\fnh123.js"
A: 18.20230227.2
A: 18.20230227.2
A: 18.20230227.2
I: plural version

And finally, hone it further

q: unique values of (it as version) of (preceding text of first ";" of following text of first "return" of it) of lines whose (it contains "return") of files "C:\trn\fnh123.js"
A: 18.20230227.2
I: plural version with multiplicity

This removes an duplication - the answer is still a plural though, which will highlight any versions of the file that return multiple version numbers, or you could change ‘unique values’ to ‘maximum’, ‘minimum’ or ‘extrema’

3 Likes

Wow, thanks! That works much better then mine

1 Like