fix linting errors
This commit is contained in:
parent
e63411e91c
commit
c96a8ada50
|
@ -1,2 +1,2 @@
|
||||||
/* Record.js | MIT | https://github.com/n2geoff/record.js */
|
/* Record.js | MIT | https://github.com/n2geoff/record.js */
|
||||||
;(function(root,factory){if(typeof module==="object"&&module.exports){module.exports=factory(root.Record)}else{root.Record=factory(root.Record)}})(this,function(me){class Record{constructor(init,opts){this.store=(opts||{}).store;this.debug=(opts||{}).debug;this.records=Array.isArray(init)?init:[]}_log(){if(!this.debug){console.log(...arguments)}}add(entry){if(Array.isArray(entry)){entry.forEach(i=>{if(!entry.id){entry.id=Math.random().toString(36).substr(2,9)}this.records.push(entry);return entry})}else{if(!entry.id){entry.id=Math.random().toString(36).substr(2,9)}this.records.push(entry);return entry}}find(key){if(!key){return this.records}if(typeof key==="string"||typeof key==="number"){return this.records.filter(record=>{return record.id===key})}let value=Object.keys(key);return this.records.filter(record=>{if(value.indexOf("id")!==-1){return record.id===key.id}return value.every(obj=>{return record[value]===key[value]})})}remove(entry){if(!entry||Array.isArray(entry)){this._log(console.error("remove() accepts a single object"));return[]}let entries=this.find(entry);entries.forEach(item=>{this.records.splice(this.records.indexOf(item),1)});return entries}clear(){this.records=[]}count(){return this.records.length}save(){if(this.storage){}}dump(){}}return Record});
|
(function(root,factory){"use strict";if(typeof module==="object"&&module.exports){module.exports=factory(root.Record)}else{root.Record=factory(root.Record)}})(this,function(){"use strict";class Record{constructor(init,opts){this.store=(opts||{}).store;this.debug=(opts||{}).debug;this.records=Array.isArray(init)?init:[]}_log(){if(!this.debug){console.log(...arguments)}}add(entry){if(Array.isArray(entry)){entry.forEach(()=>{if(!entry.id){entry.id=Math.random().toString(36).substr(2,9)}this.records.push(entry);return entry})}else{if(!entry.id){entry.id=Math.random().toString(36).substr(2,9)}this.records.push(entry);return entry}}find(key){if(!key){return this.records}if(typeof key==="string"||typeof key==="number"){return this.records.filter(record=>{return record.id===key})}let value=Object.keys(key);return this.records.filter(record=>{if(value.indexOf("id")!==-1){return record.id===key.id}return value.every(val=>{return record[val]===key[val]})})}remove(entry){if(!entry||Array.isArray(entry)){this._log(console.error("remove() accepts a single object"));return[]}let entries=this.find(entry);entries.forEach(item=>{this.records.splice(this.records.indexOf(item),1)});return entries}clear(){this.records=[]}count(){return this.records.length}save(){if(this.storage){}}dump(){}}return Record});
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
'use strict';
|
/* Record.js | MIT | https://github.com/n2geoff/record.js */
|
||||||
|
(function (root, factory) {
|
||||||
(function(root, factory) {
|
"use strict";
|
||||||
if(typeof module === "object" && module.exports) {
|
if (typeof module === "object" && module.exports) {
|
||||||
module.exports = factory(root.Record);
|
module.exports = factory(root.Record);
|
||||||
} else {
|
} else {
|
||||||
root.Record = factory(root.Record);
|
root.Record = factory(root.Record);
|
||||||
}
|
}
|
||||||
|
|
||||||
}(this, function(me) {
|
}(this, function () {
|
||||||
|
"use strict";
|
||||||
/*
|
/*
|
||||||
* Record.js
|
* Record.js
|
||||||
*
|
*
|
||||||
|
@ -61,9 +61,9 @@
|
||||||
*/
|
*/
|
||||||
add(entry) {
|
add(entry) {
|
||||||
|
|
||||||
if(Array.isArray(entry)) {
|
if (Array.isArray(entry)) {
|
||||||
entry.forEach((i) => {
|
entry.forEach(() => {
|
||||||
if(!entry.id) {
|
if (!entry.id) {
|
||||||
entry.id = Math.random().toString(36).substr(2, 9);
|
entry.id = Math.random().toString(36).substr(2, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@
|
||||||
return entry;
|
return entry;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if(!entry.id) {
|
if (!entry.id) {
|
||||||
entry.id = Math.random().toString(36).substr(2, 9);
|
entry.id = Math.random().toString(36).substr(2, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,12 +103,12 @@
|
||||||
find(key) {
|
find(key) {
|
||||||
|
|
||||||
// return all records
|
// return all records
|
||||||
if(!key) {
|
if (!key) {
|
||||||
return this.records;
|
return this.records;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find by id
|
// find by id
|
||||||
if(typeof key === 'string' || typeof key === 'number') {
|
if (typeof key === "string" || typeof key === "number") {
|
||||||
return this.records.filter((record) => {
|
return this.records.filter((record) => {
|
||||||
return record.id === key;
|
return record.id === key;
|
||||||
});
|
});
|
||||||
|
@ -121,12 +121,12 @@
|
||||||
return this.records.filter((record) => {
|
return this.records.filter((record) => {
|
||||||
|
|
||||||
// id trumps all
|
// id trumps all
|
||||||
if(value.indexOf('id') !== -1) {
|
if(value.indexOf("id") !== -1) {
|
||||||
return record.id === key.id;
|
return record.id === key.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return value.every((obj) => {
|
return value.every((val) => {
|
||||||
return record[value] === key[value];
|
return record[val] === key[val];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -147,8 +147,8 @@
|
||||||
remove(entry) {
|
remove(entry) {
|
||||||
|
|
||||||
// use clear() to remove all
|
// use clear() to remove all
|
||||||
if(!entry || Array.isArray(entry)) {
|
if (!entry || Array.isArray(entry)) {
|
||||||
this._log(console.error('remove() accepts a single object'));
|
this._log(console.error("remove() accepts a single object"));
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,15 +177,13 @@
|
||||||
|
|
||||||
// save to localstorage
|
// save to localstorage
|
||||||
save() {
|
save() {
|
||||||
if(this.storage) {
|
if (this.storage) {
|
||||||
|
// check for localStorage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dump() {}
|
dump() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Record;
|
return Record;
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue