mirror of
https://github.com/ION606/archivebot.git
synced 2026-06-06 07:52:57 +00:00
Started adding slash commands, doesn't work though
This commit is contained in:
+33
-3
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var getSideChannel = require('side-channel');
|
||||
var utils = require('./utils');
|
||||
var formats = require('./formats');
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
@@ -55,6 +56,8 @@ var isNonNullishPrimitive = function isNonNullishPrimitive(v) {
|
||||
|| typeof v === 'bigint';
|
||||
};
|
||||
|
||||
var sentinel = {};
|
||||
|
||||
var stringify = function stringify(
|
||||
object,
|
||||
prefix,
|
||||
@@ -69,9 +72,30 @@ var stringify = function stringify(
|
||||
format,
|
||||
formatter,
|
||||
encodeValuesOnly,
|
||||
charset
|
||||
charset,
|
||||
sideChannel
|
||||
) {
|
||||
var obj = object;
|
||||
|
||||
var tmpSc = sideChannel;
|
||||
var step = 0;
|
||||
var findFlag = false;
|
||||
while ((tmpSc = tmpSc.get(sentinel)) !== void undefined && !findFlag) {
|
||||
// Where object last appeared in the ref tree
|
||||
var pos = tmpSc.get(object);
|
||||
step += 1;
|
||||
if (typeof pos !== 'undefined') {
|
||||
if (pos === step) {
|
||||
throw new RangeError('Cyclic object value');
|
||||
} else {
|
||||
findFlag = true; // Break while
|
||||
}
|
||||
}
|
||||
if (typeof tmpSc.get(sentinel) === 'undefined') {
|
||||
step = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof filter === 'function') {
|
||||
obj = filter(prefix, obj);
|
||||
} else if (obj instanceof Date) {
|
||||
@@ -138,6 +162,9 @@ var stringify = function stringify(
|
||||
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix
|
||||
: prefix + (allowDots ? '.' + key : '[' + key + ']');
|
||||
|
||||
sideChannel.set(object, step);
|
||||
var valueSideChannel = getSideChannel();
|
||||
valueSideChannel.set(sentinel, sideChannel);
|
||||
pushToArray(values, stringify(
|
||||
value,
|
||||
keyPrefix,
|
||||
@@ -152,7 +179,8 @@ var stringify = function stringify(
|
||||
format,
|
||||
formatter,
|
||||
encodeValuesOnly,
|
||||
charset
|
||||
charset,
|
||||
valueSideChannel
|
||||
));
|
||||
}
|
||||
|
||||
@@ -246,6 +274,7 @@ module.exports = function (object, opts) {
|
||||
objKeys.sort(options.sort);
|
||||
}
|
||||
|
||||
var sideChannel = getSideChannel();
|
||||
for (var i = 0; i < objKeys.length; ++i) {
|
||||
var key = objKeys[i];
|
||||
|
||||
@@ -266,7 +295,8 @@ module.exports = function (object, opts) {
|
||||
options.format,
|
||||
options.formatter,
|
||||
options.encodeValuesOnly,
|
||||
options.charset
|
||||
options.charset,
|
||||
sideChannel
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user