Skip to content

Commit 9951c6d

Browse files
committed
fix(getIndex): Improve documentation
1 parent 6a8ee73 commit 9951c6d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/JsonDB.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,18 @@ export class JsonDB {
173173

174174
/**
175175
* Returns the index of the object that meets the criteria submitted.
176-
* @param dataPath
177-
* @param id the value of the index
176+
* @param dataPath base dataPath from where to start searching
177+
* @param searchValue value to look for in the dataPath
178+
* @param propertyName name of the property to look for searchValue
178179
*/
179-
public getIndex(dataPath: string, value: (string | number), item:string = 'id'): number {
180+
public getIndex(dataPath: string, searchValue: (string | number), propertyName:string = 'id'): number {
180181
const result = this.getData(dataPath);
181182
if (!Array.isArray(result)) {
182183
throw new DataError(`DataPath: ${dataPath} is not an array.`, 11)
183184
}
184185
const path = this.processDataPath(dataPath);
185186
const data = this.retrieveData(path, false);
186-
return data.map(function (element:any) {return element[item];}).indexOf(value);
187+
return data.map(function (element:any) {return element[propertyName];}).indexOf(searchValue);
187188
}
188189

189190
/**

0 commit comments

Comments
 (0)