Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
shysolocup authored Mar 24, 2023
1 parent 77932ab commit 940c277
Showing 1 changed file with 76 additions and 2 deletions.
78 changes: 76 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,43 @@ class Stew {
containsFor(array) { return this.includesFor(array); }


// dump
dump(file, replacer=null, indent=null) {
try {
const fs = require('fs');

fs.writeFileSync(file, this.stringify(replacer, indent));

return Stew.parse(fs.readFileSync(file, 'utf8'));
}
catch(err) {}
}


// properties
get properties() {
let proto = Stew.prototype;
let names = Object.getOwnPropertyNames(proto);
let methods = {};

Object.getOwnPropertyNames(this).forEach( (name) => {
methods[name] = Object.getOwnPropertyDescriptors(this)[name].value;
names.unshift(name);
});

Object.getOwnPropertyNames(proto).forEach( (name) => {
methods[name] = Object.getOwnPropertyDescriptors(proto)[name].value;
});

return {
names: names,
descriptors: Object.getOwnPropertyDescriptors(proto),
methods: methods
}
}
get props() { return this.properties; }


// toPrimitive
[Symbol.toPrimitive](hint) {
if (hint === "string") {
Expand Down Expand Up @@ -697,7 +734,7 @@ class Soup {

else if (type instanceof Map || (typeof type == "string" && type.toLowerCase() == 'map'))
return new Map(
(this.type=="pair") ? Object.entries(this.insides) : this.insides
(this.type=="pair") ? Object.entries(this.insides) : Soup.from(this.insides).entries
);

else if (type instanceof Stew || (typeof type == "string" && type.toLowerCase() == 'stew')) return new Stew(this.insides);
Expand All @@ -709,7 +746,7 @@ class Soup {
else if (type instanceof Object || (typeof type == "string" && type.toLowerCase() == 'object') || (type == null && this.type == "pair"))
return Object.fromEntries(
(this.type=="pair") ? Object.entries(this.insides)
: this.insides
: Soup.from(this.insides).entries
);
}
merge(type=null, joiner='') { return this.pour(type, joiner); }
Expand Down Expand Up @@ -1016,6 +1053,43 @@ class Soup {
remDupes() { return this.deleteDupes(); }


// dump
dump(file, replacer=null, indent=null) {
try {
const fs = require('fs');

fs.writeFileSync(file, this.stringify(replacer, indent));

return Soup.parse(fs.readFileSync(file, 'utf8'));
}
catch(err) {}
}


// properties
get properties() {
let proto = Soup.prototype;
let names = Object.getOwnPropertyNames(proto);
let methods = {};

Object.getOwnPropertyNames(this).forEach( (name) => {
methods[name] = Object.getOwnPropertyDescriptors(this)[name].value;
names.unshift(name);
});

Object.getOwnPropertyNames(proto).forEach( (name) => {
methods[name] = Object.getOwnPropertyDescriptors(proto)[name].value;
});

return {
names: names,
descriptors: Object.getOwnPropertyDescriptors(proto),
methods: methods
}
}
get props() { return this.properties; }


// toPrimitive
[Symbol.toPrimitive](hint) {
if (hint === "string") {
Expand Down

0 comments on commit 940c277

Please sign in to comment.