New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

manyfest

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

manyfest - npm Package Compare versions

Comparing version 1.0.30 to 1.0.31

source/Manyfest-ObjectAddress-Parser.js

2

package.json
{
"name": "manyfest",
"version": "1.0.30",
"version": "1.0.31",
"description": "JSON Object Manifest for Data Description and Parsing",

@@ -5,0 +5,0 @@ "main": "source/Manyfest.js",

/**
* @author <steven@velozo.com>
*/
let libSimpleLog = require('./Manyfest-LogToConsole.js');
const libSimpleLog = require('./Manyfest-LogToConsole.js');
// This is for resolving functions mid-address
const libGetObjectValue = require('./Manyfest-ObjectAddress-GetValue.js');
// TODO: Just until this is a fable service.
let _MockFable = { DataFormat: require('./Manyfest-ObjectAddress-Parser.js') };
/**

@@ -28,2 +33,3 @@ * Object Address Resolver

{
this.getObjectValueClass = new libGetObjectValue(libSimpleLog, libSimpleLog);
}

@@ -37,3 +43,3 @@

// existance and returns true or false dependent.
checkAddressExists (pObject, pAddress)
checkAddressExists (pObject, pAddress, pRootObject)
{

@@ -46,7 +52,11 @@ // TODO: Should these throw an error?

// TODO: Make this work for things like SomeRootObject.Metadata["Some.People.Use.Bad.Object.Property.Names"]
let tmpSeparatorIndex = pAddress.indexOf('.');
// Set the root object to the passed-in object if it isn't set yet. This is expected to be the root object.
// NOTE: This was added to support functions mid-stream
let tmpRootObject = (typeof(pRootObject) == 'undefined') ? pObject : pRootObject;
// DONE: Make this work for things like SomeRootObject.Metadata["Some.People.Use.Bad.Object.Property.Names"]
let tmpAddressPartBeginning = _MockFable.DataFormat.stringGetFirstSegment(pAddress);
// This is the terminal address string (no more dots so the RECUSION ENDS IN HERE somehow)
if (tmpSeparatorIndex == -1)
if (tmpAddressPartBeginning.length == pAddress.length)
{

@@ -56,2 +66,34 @@ // Check if the address refers to a boxed property

let tmpBracketStopIndex = pAddress.indexOf(']');
// Check if there is a function somewhere in the address... parenthesis start should only be in a function
let tmpFunctionStartIndex = pAddress.indexOf('(');
// NOTE THAT FUNCTIONS MUST RESOLVE FIRST
// Functions look like this
// MyFunction()
// MyFunction(Some.Address)
// MyFunction(Some.Address,Some.Other.Address)
// MyFunction(Some.Address,Some.Other.Address,Some.Third.Address)
//
// This could be enhanced to allow purely numeric and string values to be passed to the function. For now,
// To heck with that. This is a simple function call.
//
// The requirements to detect a function are:
// 1) The start bracket is after character 0
if ((tmpFunctionStartIndex > 0)
// 2) The end bracket is after the start bracket
&& (_MockFable.DataFormat.stringCountEnclosures(pAddress) > 0))
{
let tmpFunctionAddress = pAddress.substring(0, tmpFunctionStartIndex).trim();
if ((pObject.hasOwnProperty(tmpFunctionAddress)) && (typeof(pObject[tmpFunctionAddress]) == 'function'))
{
return true;
}
else
{
// The address suggests it is a function, but it is not.
return false;
}
}
// Boxed elements look like this:

@@ -66,3 +108,3 @@ // MyValues[10]

// 1) The start bracket is after character 0
if ((tmpBracketStartIndex > 0)
else if ((tmpBracketStartIndex > 0)
// 2) The end bracket has something between them

@@ -125,4 +167,4 @@ && (tmpBracketStopIndex > tmpBracketStartIndex)

{
let tmpSubObjectName = pAddress.substring(0, tmpSeparatorIndex);
let tmpNewAddress = pAddress.substring(tmpSeparatorIndex+1);
let tmpSubObjectName = tmpAddressPartBeginning;
let tmpNewAddress = pAddress.substring(tmpAddressPartBeginning.length+1);

@@ -133,2 +175,56 @@ // Test if the tmpNewAddress is an array or object

let tmpBracketStopIndex = tmpSubObjectName.indexOf(']');
// Check if there is a function somewhere in the address... parenthesis start should only be in a function
let tmpFunctionStartIndex = tmpSubObjectName.indexOf('(');
// NOTE THAT FUNCTIONS MUST RESOLVE FIRST
// Functions look like this
// MyFunction()
// MyFunction(Some.Address)
// MyFunction(Some.Address,Some.Other.Address)
// MyFunction(Some.Address,Some.Other.Address,Some.Third.Address)
//
// This could be enhanced to allow purely numeric and string values to be passed to the function. For now,
// To heck with that. This is a simple function call.
//
// The requirements to detect a function are:
// 1) The start bracket is after character 0
if ((tmpFunctionStartIndex > 0)
// 2) The end bracket is after the start bracket
&& (_MockFable.DataFormat.stringCountEnclosures(tmpSubObjectName) > 0))
{
let tmpFunctionAddress = tmpSubObjectName.substring(0, tmpFunctionStartIndex).trim();
//tmpParentAddress = `${tmpParentAddress}${(tmpParentAddress.length > 0) ? '.' : ''}${tmpSubObjectName}`;
if (!typeof(pObject[tmpFunctionAddress]) == 'function')
{
// The address suggests it is a function, but it is not.
return false;
}
// Now see if the function has arguments.
// Implementation notes: * ARGUMENTS MUST SHARE THE SAME ROOT OBJECT CONTEXT *
let tmpFunctionArguments = _MockFable.DataFormat.stringGetSegments(_MockFable.DataFormat.stringGetEnclosureValueByIndex(tmpSubObjectName.substring(tmpFunctionAddress.length), 0), ',');
if ((tmpFunctionArguments.length == 0) || (tmpFunctionArguments[0] == ''))
{
// No arguments... just call the function (bound to the scope of the object it is contained withing)
return this.checkAddressExists(pObject[tmpFunctionAddress].apply(pObject), tmpNewAddress, tmpRootObject);
}
else
{
let tmpArgumentValues = [];
let tmpRootObject = (typeof(pRootObject) == 'undefined') ? pObject : pRootObject;
// Now get the value for each argument
for (let i = 0; i < tmpFunctionArguments.length; i++)
{
// Resolve the values for each subsequent entry
// NOTE: This is where the resolves get really tricky. Recursion within recursion. Programming gom jabbar, yo.
tmpArgumentValues.push(this.getObjectValueClass.getValueAtAddress(tmpRootObject, tmpFunctionArguments[i]));
}
return this.checkAddressExists(pObject[tmpFunctionAddress].apply(pObject, tmpArgumentValues), tmpNewAddress, tmpRootObject);
}
}
// Boxed elements look like this:

@@ -143,3 +239,3 @@ // MyValues[42]

// 1) The start bracket is after character 0
if ((tmpBracketStartIndex > 0)
else if ((tmpBracketStartIndex > 0)
// 2) The end bracket has something between them

@@ -188,3 +284,3 @@ && (tmpBracketStopIndex > tmpBracketStartIndex)

// Recurse directly into the subobject
return this.checkAddressExists(pObject[tmpBoxedPropertyName][tmpBoxedPropertyReference], tmpNewAddress);
return this.checkAddressExists(pObject[tmpBoxedPropertyName][tmpBoxedPropertyReference], tmpNewAddress, tmpRootObject);
}

@@ -194,3 +290,3 @@ else

// We parsed a valid number out of the boxed property name, so recurse into the array
return this.checkAddressExists(pObject[tmpBoxedPropertyName][tmpBoxedPropertyNumber], tmpNewAddress);
return this.checkAddressExists(pObject[tmpBoxedPropertyName][tmpBoxedPropertyNumber], tmpNewAddress, tmpRootObject);
}

@@ -208,3 +304,3 @@ }

// If there is already a subobject pass that to the recursive thingy
return this.checkAddressExists(pObject[tmpSubObjectName], tmpNewAddress);
return this.checkAddressExists(pObject[tmpSubObjectName], tmpNewAddress, tmpRootObject);
}

@@ -215,3 +311,3 @@ else

pObject[tmpSubObjectName] = {};
return this.checkAddressExists(pObject[tmpSubObjectName], tmpNewAddress);
return this.checkAddressExists(pObject[tmpSubObjectName], tmpNewAddress, tmpRootObject);
}

@@ -218,0 +314,0 @@ }

@@ -238,4 +238,2 @@ /**

}
//This is a bracketed value

@@ -242,0 +240,0 @@ // 4) If the middle part is *only* a number (no single, double or backtick quotes) it is an array element,

@@ -6,4 +6,6 @@ /**

let fCleanWrapCharacters = require('./Manyfest-CleanWrapCharacters.js');
let fParseConditionals = require(`../source/Manyfest-ParseConditionals.js`)
let fParseConditionals = require(`../source/Manyfest-ParseConditionals.js`);
let _MockFable = { DataFormat: require('./Manyfest-ObjectAddress-Parser.js') };
/**

@@ -62,11 +64,11 @@ * Object Address Resolver - GetValue

// TODO: Make this work for things like SomeRootObject.Metadata["Some.People.Use.Bad.Object.Property.Names"]
let tmpSeparatorIndex = pAddress.indexOf('.');
// DONE: Make this work for things like SomeRootObject.Metadata["Some.People.Use.Bad.Object.Property.Names"]
let tmpAddressPartBeginning = _MockFable.DataFormat.stringGetFirstSegment(pAddress);
// Adding simple back-navigation in objects
if (tmpSeparatorIndex == 0)
if (tmpAddressPartBeginning == '')
{
// Given an address of "Bundle.Contract.IDContract...Project.IDProject" the ... would be interpreted as two back-navigations from IDContract.
// When the address is passed in, though, the first . is already eliminated. So we can count the dots.
let tmpParentAddressParts = tmpParentAddress.split('.');
let tmpParentAddressParts = _MockFable.DataFormat.stringGetSegments(tmpParentAddress);

@@ -109,4 +111,6 @@ let tmpBackNavigationCount = 0;

// This is the terminal address string (no more dots so the RECUSION ENDS IN HERE somehow)
if (tmpSeparatorIndex == -1)
if (tmpAddressPartBeginning.length == pAddress.length)
{
// TODO: Optimize this by having these calls only happen when the previous fails.
// TODO: Alternatively look for all markers in one pass?
// Check if the address refers to a boxed property

@@ -120,2 +124,54 @@ let tmpBracketStartIndex = pAddress.indexOf('[');

// Check if there is a function somewhere in the address... parenthesis start should only be in a function
let tmpFunctionStartIndex = pAddress.indexOf('(');
// NOTE THAT FUNCTIONS MUST RESOLVE FIRST
// Functions look like this
// MyFunction()
// MyFunction(Some.Address)
// MyFunction(Some.Address,Some.Other.Address)
// MyFunction(Some.Address,Some.Other.Address,Some.Third.Address)
//
// This could be enhanced to allow purely numeric and string values to be passed to the function. For now,
// To heck with that. This is a simple function call.
//
// The requirements to detect a function are:
// 1) The start bracket is after character 0
if ((tmpFunctionStartIndex > 0)
// 2) The end bracket is after the start bracket
&& (_MockFable.DataFormat.stringCountEnclosures(pAddress) > 0))
{
let tmpFunctionAddress = pAddress.substring(0, tmpFunctionStartIndex).trim();
if (!typeof(pObject[tmpFunctionAddress]) == 'function')
{
// The address suggests it is a function, but it is not.
return false;
}
// Now see if the function has arguments.
// Implementation notes: * ARGUMENTS MUST SHARE THE SAME ROOT OBJECT CONTEXT *
let tmpFunctionArguments = _MockFable.DataFormat.stringGetSegments(_MockFable.DataFormat.stringGetEnclosureValueByIndex(pAddress.substring(tmpFunctionAddress.length), 0), ',');
if ((tmpFunctionArguments.length == 0) || (tmpFunctionArguments[0] == ''))
{
// No arguments... just call the function (bound to the scope of the object it is contained withing)
return pObject[tmpFunctionAddress].apply(pObject);
}
else
{
let tmpArgumentValues = [];
let tmpRootObject = (typeof(pRootObject) == 'undefined') ? pObject : pRootObject;
// Now get the value for each argument
for (let i = 0; i < tmpFunctionArguments.length; i++)
{
// Resolve the values for each subsequent entry
tmpArgumentValues.push(this.getValueAtAddress(tmpRootObject, tmpFunctionArguments[i]));
}
return pObject[tmpFunctionAddress].apply(pObject, tmpArgumentValues);
}
}
// Boxed elements look like this:

@@ -130,3 +186,3 @@ // MyValues[10]

// 1) The start bracket is after character 0
if ((tmpBracketStartIndex > 0)
else if ((tmpBracketStartIndex > 0)
// 2) The end bracket has something between them

@@ -205,2 +261,3 @@ && (tmpBracketStopIndex > tmpBracketStartIndex)

tmpOutputArray.push(tmpInputArray[i]);
}

@@ -239,4 +296,6 @@ }

{
let tmpSubObjectName = pAddress.substring(0, tmpSeparatorIndex);
let tmpNewAddress = pAddress.substring(tmpSeparatorIndex+1);
//let tmpSubObjectName = pAddress.substring(0, tmpSeparatorIndex);
//let tmpNewAddress = pAddress.substring(tmpSeparatorIndex+1);
let tmpSubObjectName = tmpAddressPartBeginning;
let tmpNewAddress = pAddress.substring(tmpAddressPartBeginning.length+1);

@@ -248,2 +307,55 @@ // BOXED ELEMENTS

let tmpBracketStopIndex = tmpSubObjectName.indexOf(']');
// Check if there is a function somewhere in the address... parenthesis start should only be in a function
let tmpFunctionStartIndex = tmpSubObjectName.indexOf('(');
// NOTE THAT FUNCTIONS MUST RESOLVE FIRST
// Functions look like this
// MyFunction()
// MyFunction(Some.Address)
// MyFunction(Some.Address,Some.Other.Address)
// MyFunction(Some.Address,Some.Other.Address,Some.Third.Address)
//
// This could be enhanced to allow purely numeric and string values to be passed to the function. For now,
// To heck with that. This is a simple function call.
//
// The requirements to detect a function are:
// 1) The start bracket is after character 0
if ((tmpFunctionStartIndex > 0)
// 2) The end bracket is after the start bracket
&& (_MockFable.DataFormat.stringCountEnclosures(tmpSubObjectName) > 0))
{
let tmpFunctionAddress = tmpSubObjectName.substring(0, tmpFunctionStartIndex).trim();
tmpParentAddress = `${tmpParentAddress}${(tmpParentAddress.length > 0) ? '.' : ''}${tmpSubObjectName}`;
if (!typeof(pObject[tmpFunctionAddress]) == 'function')
{
// The address suggests it is a function, but it is not.
return false;
}
// Now see if the function has arguments.
// Implementation notes: * ARGUMENTS MUST SHARE THE SAME ROOT OBJECT CONTEXT *
let tmpFunctionArguments = _MockFable.DataFormat.stringGetSegments(_MockFable.DataFormat.stringGetEnclosureValueByIndex(tmpSubObjectName.substring(tmpFunctionAddress.length), 0), ',');
if ((tmpFunctionArguments.length == 0) || (tmpFunctionArguments[0] == ''))
{
// No arguments... just call the function (bound to the scope of the object it is contained withing)
return this.getValueAtAddress(pObject[tmpFunctionAddress].apply(pObject), tmpNewAddress, tmpParentAddress, tmpRootObject);
}
else
{
let tmpArgumentValues = [];
let tmpRootObject = (typeof(pRootObject) == 'undefined') ? pObject : pRootObject;
// Now get the value for each argument
for (let i = 0; i < tmpFunctionArguments.length; i++)
{
// Resolve the values for each subsequent entry
tmpArgumentValues.push(this.getValueAtAddress(tmpRootObject, tmpFunctionArguments[i]));
}
return this.getValueAtAddress(pObject[tmpFunctionAddress].apply(pObject, tmpArgumentValues), tmpNewAddress, tmpParentAddress, tmpRootObject);
}
}
// Boxed elements look like this:

@@ -258,3 +370,3 @@ // MyValues[42]

// 1) The start bracket is after character 0
if ((tmpBracketStartIndex > 0)
else if ((tmpBracketStartIndex > 0)
// 2) The end bracket has something between them

@@ -261,0 +373,0 @@ && (tmpBracketStopIndex > tmpBracketStartIndex)

@@ -21,3 +21,3 @@ // Given a string, parse out any conditional expressions and set whether or not to keep the record.

// Ugh dependency injection. Can't wait to make these all fable services.
let libObjectAddressCheckAddressExists = new (require('./Manyfest-ObjectAddress-CheckAddressExists.js'))();
//let libObjectAddressCheckAddressExists = new (require('./Manyfest-ObjectAddress-CheckAddressExists.js'))();

@@ -65,13 +65,11 @@ // Test the condition of a value in a record

break;
case 'FALSE':
return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) === false);
break;
case 'EX':
case 'EXISTS':
return libObjectAddressCheckAddressExists.checkAddressExists(pRecord, pSearchAddress);
break;
case 'DNEX':
case 'DOES_NOT_EXIST':
return !libObjectAddressCheckAddressExists.checkAddressExists(pRecord, pSearchAddress);
break;
// TODO: Welcome to dependency hell. This fixes itself when we move to fable services.
// case 'EX':
// case 'EXISTS':
// return libObjectAddressCheckAddressExists.checkAddressExists(pRecord, pSearchAddress);
// break;
// case 'DNEX':
// case 'DOES_NOT_EXIST':
// return !libObjectAddressCheckAddressExists.checkAddressExists(pRecord, pSearchAddress);
// break;
case '!=':

@@ -78,0 +76,0 @@ return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) != pValue);

@@ -62,6 +62,7 @@ /**

{
'files[]<<~?length,EXISTS?~>>': {Name:'Files With a length Property', Hash:'FilesWithLength'},
'files[]<<~?length,DNEX?~>>': {Name:'Files Without a length Property', Hash:'FilesWithoutLength'},
'files[]<<~?length,DNEX?~>><<~?source,==,original?~>>': {Name:'Original Files With a length Property', Hash:'OriginalFilesWithLength'},
'files[]<<~?thumbnail,EXISTS?~>>': {Name:'Thumbnail Bit is Explicitly Set', Hash:'ThumbnailExplicitlySet'},
// TODO: STRICKEN OUT BY DEPENDENCY HELL
//'files[]<<~?length,EXISTS?~>>': {Name:'Files With a length Property', Hash:'FilesWithLength'},
// 'files[]<<~?length,DNEX?~>>': {Name:'Files Without a length Property', Hash:'FilesWithoutLength'},
// 'files[]<<~?length,DNEX?~>><<~?source,==,original?~>>': {Name:'Original Files With a length Property', Hash:'OriginalFilesWithLength'},
// 'files[]<<~?thumbnail,EXISTS?~>>': {Name:'Thumbnail Bit is Explicitly Set', Hash:'ThumbnailExplicitlySet'},
'files[]<<~?thumbnail,TRUE?~>>': {Name:'Thumbnail Files', Hash:'ThumbnailFiles'},

@@ -83,17 +84,18 @@ 'files[]<<~?thumbnail,FALSE?~>>': {Name:'Not Thumbnail Files', Hash:'NotThumbnailFiles'},

let tmpFilesWithLength = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'FilesWithLength');
Expect(tmpFilesWithLength).to.be.an('array');
Expect(tmpFilesWithLength.length).to.equal(3);
// TODO: Dependencies are the wurst
// let tmpFilesWithLength = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'FilesWithLength');
// Expect(tmpFilesWithLength).to.be.an('array');
// Expect(tmpFilesWithLength.length).to.equal(3);
let tmpOGFilesWithLength = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'OriginalFilesWithLength');
Expect(tmpOGFilesWithLength).to.be.an('array');
Expect(tmpOGFilesWithLength.length).to.equal(2);
// let tmpOGFilesWithLength = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'OriginalFilesWithLength');
// Expect(tmpOGFilesWithLength).to.be.an('array');
// Expect(tmpOGFilesWithLength.length).to.equal(2);
let tmpFilesWithoutLength = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'FilesWithoutLength');
Expect(tmpFilesWithoutLength).to.be.an('array');
Expect(tmpFilesWithoutLength.length).to.equal(14);
// let tmpFilesWithoutLength = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'FilesWithoutLength');
// Expect(tmpFilesWithoutLength).to.be.an('array');
// Expect(tmpFilesWithoutLength.length).to.equal(14);
let tmpExplicitlyExists = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'ThumbnailExplicitlySet');
Expect(tmpExplicitlyExists).to.be.an('array');
Expect(tmpExplicitlyExists.length).to.equal(2);
// let tmpExplicitlyExists = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'ThumbnailExplicitlySet');
// Expect(tmpExplicitlyExists).to.be.an('array');
// Expect(tmpExplicitlyExists.length).to.equal(2);

@@ -100,0 +102,0 @@ let tmpShortFormatFiles = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'ShortFormatFiles');

@@ -67,2 +67,56 @@ /**

);
test
(
'Elements exist in function return values ... yiiiiikes.',
(fTestComplete)=>
{
// Create a compmlex mock object to check metadata on.
let _MockObject = (
{
"Name": "Yadda",
"TheFunction": (pValue) => { return `Value is: ${pValue}`; },
"ComplexFunction": (pValue, pOutput) => { return `Value is: ${pValue} and would output as ${pOutput}`; },
"Behaviors":
{
"Value": 0,
"Increment": function ()
{
this.Value++; return this.Value;
},
"SillyObject": function()
{
return { Cost: 1.00, Name: 'Beanie Baby', Stores: ['Aberdeen', 'Seattle', 'Tacoma'] }
},
"FormatOutput": function () { return `My magic value is: ${this.Value}`; }
},
"Manyfest":
{
Scope:'Function.Mock',
Descriptors:
{
"metadata.creator":
{
Name:'Creator',
Hash:'Creator'
}
}
},
"Data": _SampleDataArchiveOrgFrankenberry
});
let _Manyfest = new libManyfest(_MockObject.Manyfest);
// Function existence should just work
Expect(_Manyfest.checkAddressExists(_MockObject, 'Behaviors.SillyObject')).to.equal(true);
// If it is a function we can ask manyfest if it's a function and it will be true
Expect(_Manyfest.checkAddressExists(_MockObject, 'Behaviors.SillyObject()')).to.equal(true);
// Non functions will return false even if they exist.
Expect(_Manyfest.checkAddressExists(_MockObject, 'Behaviors.Value')).to.equal(true);
Expect(_Manyfest.checkAddressExists(_MockObject, 'Behaviors.Value()')).to.equal(false);
Expect(_Manyfest.checkAddressExists(_MockObject, 'Behaviors.SillyObject().Stores')).to.equal(true);
Expect(_Manyfest.checkAddressExists(_MockObject, 'Behaviors.SillyObject().Stores[0]')).to.equal(true);
fTestComplete();
}
);
}

@@ -69,0 +123,0 @@ );

@@ -197,2 +197,83 @@ /**

);
test
(
'Access Functions',
(fTestComplete)=>
{
let _Manyfest = new libManyfest();
let tmpComplexObject = (
{
"Name": "Yadda",
"TheFunction": (pValue) => { return `Value is: ${pValue}`; }
});
Expect(_Manyfest.getValueAtAddress(tmpComplexObject, 'Name'))
.to.equal('Yadda');
Expect(_Manyfest.getValueAtAddress(tmpComplexObject, 'TheFunction()'))
.to.equal('Value is: undefined');
Expect(_Manyfest.getValueAtAddress(tmpComplexObject, 'TheFunction(Name)'))
.to.equal('Value is: Yadda');
fTestComplete();
}
);
test
(
'Complex Functions that Mutate State and deal with Parameters',
(fTestComplete)=>
{
// Create a compmlex mock object to check metadata on.
let _MockObject = (
{
"Name": "Yadda",
"TheFunction": (pValue) => { return `Value is: ${pValue}`; },
"ComplexFunction": (pValue, pOutput) => { return `Value is: ${pValue} and would output as ${pOutput}`; },
"Behaviors":
{
"Value": 0,
"Increment": function ()
{
this.Value++; return this.Value;
},
"SillyObject": function()
{
return { Cost: 1.00, Name: 'Beanie Baby', Stores: ['Aberdeen', 'Seattle', 'Tacoma'] }
},
"FormatOutput": function () { return `My magic value is: ${this.Value}`; }
},
"Manyfest":
{
Scope:'Function.Mock',
Descriptors:
{
"metadata.creator":
{
Name:'Creator',
Hash:'Creator'
}
}
},
"Data": _SampleDataArchiveOrgFrankenberry
});
let _Manyfest = new libManyfest(_MockObject.Manyfest);
Expect(_Manyfest.getValueAtAddress(_MockObject, 'Name')).to.equal('Yadda');
Expect(_Manyfest.getValueAtAddress(_MockObject, 'TheFunction()')).to.equal('Value is: undefined');
Expect(_Manyfest.getValueAtAddress(_MockObject, 'TheFunction(Name)')).to.equal('Value is: Yadda');
Expect(_Manyfest.getValueAtAddress(_MockObject, 'ComplexFunction(Name,Name)')).to.equal('Value is: Yadda and would output as Yadda');
// This is stupid but works
Expect(_Manyfest.getValueAtAddress(_MockObject, 'ComplexFunction(Name,TheFunction(Manyfest.Descriptors["metadata.creator"].Hash))'))
.to.equal('Value is: Yadda and would output as Value is: Creator');
Expect(_Manyfest.getValueAtAddress(_MockObject, 'Behaviors.Increment()'))
.to.equal(1);
Expect(_Manyfest.getValueAtAddress(_MockObject, 'Behaviors.SillyObject().Stores[0]')).to.equal('Aberdeen');
fTestComplete();
}
);
}

@@ -199,0 +280,0 @@ );

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc