cleanup, api, databuddy
This commit is contained in:
13
node_modules/@dank-inc/data-buddy/lib/index.d.ts
generated
vendored
Normal file
13
node_modules/@dank-inc/data-buddy/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
declare type DataRecord = {
|
||||
id: string;
|
||||
};
|
||||
export declare type DataBuddyParams<T extends DataRecord> = T[];
|
||||
export declare class DataBuddy<T extends DataRecord> {
|
||||
data: T[];
|
||||
constructor(records: T[]);
|
||||
get: () => T[];
|
||||
getOne: (id: string) => T | null;
|
||||
update: (id: string, params: Partial<T>) => T | false;
|
||||
delete: (id: string) => boolean;
|
||||
}
|
||||
export {};
|
43
node_modules/@dank-inc/data-buddy/lib/index.js
generated
vendored
Normal file
43
node_modules/@dank-inc/data-buddy/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DataBuddy = void 0;
|
||||
var DataBuddy = (function () {
|
||||
function DataBuddy(records) {
|
||||
var _this = this;
|
||||
this.get = function () {
|
||||
return _this.data;
|
||||
};
|
||||
this.getOne = function (id) {
|
||||
return _this.data.find(function (record) { return record.id === id; }) || null;
|
||||
};
|
||||
this.update = function (id, params) {
|
||||
var index = _this.data.findIndex(function (record) { return record.id === id; });
|
||||
if (!index)
|
||||
return false;
|
||||
var record = _this.data[index];
|
||||
_this.data[index] = __assign(__assign({}, record), params);
|
||||
return _this.data[index];
|
||||
};
|
||||
this.delete = function (id) {
|
||||
var index = _this.data.findIndex(function (record) { return record.id === id; });
|
||||
if (!index)
|
||||
return false;
|
||||
_this.data.splice(index, 1);
|
||||
return true;
|
||||
};
|
||||
this.data = records;
|
||||
}
|
||||
return DataBuddy;
|
||||
}());
|
||||
exports.DataBuddy = DataBuddy;
|
Reference in New Issue
Block a user