SuddenDevelopment / json-collection-decorator

efficiently run a collection of records by conditions and decorate them when conditions match, return results - filtered items
MIT License
0 stars 0 forks source link

Adds a unit test showing how to retrieve transform options for multiple data types #5

Closed anderfjord closed 7 years ago

anderfjord commented 7 years ago

I added comments related to this, but some important things to know are as follows.


It is not necessary for calling code to call the loadTransformOptions() function. This should be called only if the caller wants to override the default transform options that are generated by this library. The caller can override the generated mapping of available options at any time. If the caller does nothing to specify the options mapping, then the library will automatically generate the full mapping of available options based on the _objGlobalDataTypeOptions and _objDataTypeOptionsTemplate objects that are embedded within the library. This occurs automatically when the decorator object is instantiated.


Whether the caller uses the default options mapping or specifies their own, every data type's options end up being composed of:

(NOTE: All of the above can be (optionally) customized by the calling code (if desired) by calling loadTransformOptions() and providing it a mapping object. Overriding the global options is a little wonky, but doable, and in general shouldn't be an issue. The expectation is that in the vast majority of cases calling code will want to use the transform options mapping that is generated automatically by default.)


When retrieving options for one or more data types... ...if, for example, you call fnReturnOptions() like this:

var objTransformOptions = objDec.fnReturnOptions({ typ: 'string', dataTypes: ['ip', 'url'] });

Then, the response you'd receive would look something like this:

{
  string: {ops: [...strings here...], acts: [...strings here...]},
  ip: {ops: [...strings here...], acts: [...strings here...]},
  url: {ops: [...strings here...], acts: [...strings here...]},
}

(Note: The contents of the ops and acts arrays for each data type get returned in alphabetical order.)