@cashfarm/lang
Version:
Extends TypeScript/Javascript with basic classes and functions
65 lines • 1.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const util = require("util");
const fqn_1 = require("./fqn");
let NumberWrapper = class NumberWrapper extends Number {
get [Symbol.toStringTag]() {
console.log('toStringTag', this.constructor.name);
return this.constructor.name;
}
toJSON() {
return this.primitiveValue;
}
valueOf() {
return this.primitiveValue;
}
toString() {
return String(this.primitiveValue);
}
[Symbol.toPrimitive](hint) {
if ('string' === hint)
return this.toString();
return this.primitiveValue;
}
[util.inspect.custom](depth, options) {
return `${this.primitiveValue}`;
}
};
NumberWrapper = tslib_1.__decorate([
fqn_1.FQN('@cashfarm/lang:NumberWrapper')
], NumberWrapper);
exports.NumberWrapper = NumberWrapper;
let StringWrapper = class StringWrapper extends String {
constructor(value) {
super(value);
Object.setPrototypeOf(this, new.target.prototype);
}
get [Symbol.toStringTag]() {
console.log('toStringTag', this.constructor.name);
return this.constructor.name;
}
toJSON() {
return this.primitiveValue;
}
valueOf() {
return this.primitiveValue;
}
toString() {
return this.primitiveValue;
}
[Symbol.toPrimitive](hint) {
if ('number' === hint)
throw new Error(`A ${this[Symbol.toStringTag]} cannot be converted to a number`);
return this.primitiveValue;
}
[util.inspect.custom](depth, options) {
return `'${this.primitiveValue}'`;
}
};
StringWrapper = tslib_1.__decorate([
fqn_1.FQN('@cashfarm/lang:StringWrapper'),
tslib_1.__metadata("design:paramtypes", [String])
], StringWrapper);
exports.StringWrapper = StringWrapper;
//# sourceMappingURL=primitiveWrappers.js.map