dotfiles/vscode/.vscode/extensions/randomfractalsinc.vscode-data-preview-2.3.0/node_modules/bson/lib/code.js
Errol Sancaktar ff17c17e23 vscode
2024-06-14 09:31:58 -06:00

43 lines
1.2 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Code = void 0;
/**
* A class representation of the BSON Code type.
* @public
*/
class Code {
/**
* @param code - a string or function.
* @param scope - an optional scope for the function.
*/
constructor(code, scope) {
this.code = code;
this.scope = scope;
}
/** @internal */
toJSON() {
return { code: this.code, scope: this.scope };
}
/** @internal */
toExtendedJSON() {
if (this.scope) {
return { $code: this.code, $scope: this.scope };
}
return { $code: this.code };
}
/** @internal */
static fromExtendedJSON(doc) {
return new Code(doc.$code, doc.$scope);
}
/** @internal */
[Symbol.for('nodejs.util.inspect.custom')]() {
return this.inspect();
}
inspect() {
const codeJson = this.toJSON();
return `Code("${codeJson.code}"${codeJson.scope ? `, ${JSON.stringify(codeJson.scope)}` : ''})`;
}
}
exports.Code = Code;
Object.defineProperty(Code.prototype, '_bsontype', { value: 'Code' });
//# sourceMappingURL=code.js.map