New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

recordarray

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

recordarray - npm Package Compare versions

Comparing version
0.0.4
to
0.0.5
+5
-3
package.json
{
"name": "recordarray",
"version": "0.0.4",
"version": "0.0.5",
"description": "Array Class Extension for Records",

@@ -20,3 +20,3 @@ "main": "src/RecordArray.js",

"author": "Francis Carelse",
"license": "",
"license": "MIT",
"bugs": {

@@ -28,4 +28,6 @@ "url": "https://github.com/fcarelse/recordarray/issues"

"babel-eslint": "^10.0.3",
"eslint-config-prettier": "^6.5.0"
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.5.0",
"mocha": "^7.0.1"
}
}
# RecordArray
Zero Dependency Extension of Javascript Array class with record handling
> **Note:** Further information on https://recordarray.js.ie/
Zero Dependency Extension of Javascript Array class with record data handling capabilities
> **Note:** Further information on <a href="https://recordarray.js.ie/" target="_blank">recordarray.js.ie</a>
> or <a href="https://recordarray.com/" target="_blank">recordarray.com</a>
## Installation
```bash
npm install recordarray
```
## **Usage:**

@@ -9,3 +16,3 @@ ```javascript

const users = RecordArray([
const users = new RecordArray([
{id: 1, name: 'Admin', type: 'admin'},

@@ -23,3 +30,4 @@ {id: 2, name: 'Bob', type: 'guest'},

.listValues('name')
.join(', ') );
.join(', ')
);
// Output: "Sam, Bob"

@@ -26,0 +34,0 @@

@@ -27,2 +27,8 @@ /** RecordArray

RecordArray.prototype.asyncEach = async function(cb){
for(let i=0;i<this.length;i++){
await cb(this[i], i);
}
};
module.exports = RecordArray;

@@ -41,9 +47,14 @@ // // Extend the Array class via old method.

RecordArray.prototype.findBy = function(field, value, options) {
// Test field is string primitive or string object.
if(typeof field != 'string' && !(field instanceof String))
throw new TypeError('Field Name parameter required');
// Create a RecordArray to be returned
var arr = new RecordArray();
// If no parameters then return empty RecordArray.
if(arguments.length == 0) return arr;
// Test field is not string primitive or string object then return.
if(typeof field != 'string' && !(field instanceof String))
return arr;
// Ensure there is an options object
if(!(options instanceof Object)){
if(!(options instanceof Object) || options == null){
// Check if boolean to become the strict option

@@ -57,6 +68,9 @@ if(options instanceof Boolean || typeof options == 'boolean')

}
// Force strict option to boolean
options.strict = !!options.strict;
// If value not defined then just return the empty array
if (value === undefined) return arr;
// If null or undefined value to search for then enforce strict equality

@@ -68,8 +82,12 @@ if (value === null) options.strict = true;

record = this[i];
// Find a matching field
field = Object.keys(record).filter(key=>
// Check the trim option
options.trim?
// Compare field with trimmed key
key.trim()==field:
// Otherwise compare field with key

@@ -79,9 +97,13 @@ key==field

if (
const compared = options.trim?
record[field].toString().trim():
record[field];
if(
// field should not be undefined
field !== undefined &&
// stored value is not undefined
record[field] !== undefined &&
compared !== undefined &&
// and apply strictness in comparison as per option between stored value and matching value
((!options.strict && record[field] == value) || Object.is(record[field], value))
((!options.strict && compared == value) || Object.is(compared, value))
// Then append record to return RecordArray

@@ -328,2 +350,6 @@ ){

<<<<<<< HEAD
// faulty. Comparing objects at the moment not keys or value.
=======
>>>>>>> 28b654453ba193264c27b177cf2469293dcc4be6
RecordArray.compareRecords = (record1, record2, strict)=>{

@@ -439,3 +465,7 @@ // Default "strict" to true

*/
<<<<<<< HEAD
RecordArray.compare = (RA1, RA2, options) => {
=======
RecordArray.compare = (RA1, RA2, strict, identical) => {
>>>>>>> 28b654453ba193264c27b177cf2469293dcc4be6
// Assert RA1 is an Array

@@ -442,0 +472,0 @@ if (!(RA1 instanceof Array))

@@ -26,17 +26,6 @@ const assert = require('assert');

describe('findBy()', ()=>{
it('should throw exception due to no field given', function() {
() => {
testRA.findBy();
},
/^TypeError: Field Name parameter required$/
// assert.throws(
// ()=>{
// testRA.findBy();
// },
// {
// name: 'TypeError',
// message: 'Field Name parameter required'
// }
// );
it('Should return empty RecordArray if no parameters supplied', function() {
const res = testRA.findBy();
assert.ok(res instanceof RecordArray, 'Returned must be RecordArray')
assert.ok(res.length == 0, 'Returned must have no length')
});

@@ -60,3 +49,3 @@ });

assert.deepEqual(
testRA.findBy('key', 'blue', {trim: true}),
testRA.findBy('key', 'blue'),
new RecordArray([

@@ -70,12 +59,14 @@ {id: 3, name: 'Cat', key: 'blue'},

it('Should find records using non core field allowing trim option', function() {
assert.deepEqual(
testRA.findBy('key', 'blue', {trim: true}),
new RecordArray([
{id: 3, name: 'Cat', key: 'blue'},
{id: 6, name: 'Fred', key: ' blue '},
{id: 7, name: 'Greg', key: ' blue'},
{id: 8, name: 'Harry', key: 'blue '},
{id: 9, name: 'Ian', key: 'blue'}
]),
it.skip('Should find records using non core field allowing trim option', function() {
const res = testRA.findBy('key', 'blue', {trim: true});
const expected = new RecordArray([
{id: 3, name: 'Cat', key: 'blue'},
{id: 6, name: 'Fred', key: ' blue '},
{id: 7, name: 'Greg', key: ' blue'},
{id: 8, name: 'Harry', key: 'blue '},
{id: 9, name: 'Ian', key: 'blue'}
]);
console.log(res);
console.log(expected);
assert.ok( RecordArray.compareRecords(res, expected),
'Should find records with trimmed key equal to value'

@@ -82,0 +73,0 @@ );