What is cordova/argscheck used for?
Asked Answered
C

1

10

I am trying to figure out what does cordova/argscheck do. I was not able to find any documentation that describes what is it used for nor how to use it.

I managed to find its git repo however no comments are mentioned in the code. I have also taken a look at a couple of plugins and they seem to use it as follows:

Device.prototype.getInfo = function(successCallback, errorCallback) {
    argscheck.checkArgs('fF', 'Device.getInfo', arguments);
    exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);
};

This code has been taken from the Device plugin. Find the git repo here.

Correy answered 5/3, 2015 at 7:26 Comment(0)
C
8

I have figured it out is seems that the function is used to check the parameters to make sure that they are one of the following:

'A'=> 'Array'
'D'=> 'Date'
'N'=> 'Number'
'S'=> 'String'
'F'=> 'Function'
'O'=> 'Object'
'*'=>  'Anything goes'

This check is done to make sure that the java calls that will be called using the exec function will not throw any errors because of bad parameter types.

Correy answered 5/3, 2015 at 8:9 Comment(1)
For those wanting to dive deeper, the argscheck code repo is [here] (github.com/apache/cordova-js/blob/master/src/common/…). Some repositories will have something like 'sFF', but the checkArgs(...) converts everything to uppercase to then check against this list from @thedethfox.Rhamnaceous

© 2022 - 2024 — McMap. All rights reserved.