31 lines
714 B
JavaScript
31 lines
714 B
JavaScript
const crypto = require('crypto');
|
|
|
|
Object.defineProperty(String.prototype, 'md5', {
|
|
enumerable: false,
|
|
configurable: false,
|
|
get() {
|
|
return crypto
|
|
.createHash('md5')
|
|
.update(this.valueOf())
|
|
.digest('hex');
|
|
},
|
|
});
|
|
|
|
Object.defineProperty(String.prototype, 'characterFrequencies', {
|
|
enumerable: false,
|
|
configurable: false,
|
|
get() {
|
|
const frequency = new Map();
|
|
for (const letter of this) {
|
|
frequency.set(letter, (frequency.get(letter) || BigInt(0)) + BigInt(1));
|
|
}
|
|
return frequency;
|
|
},
|
|
});
|
|
|
|
String.prototype.splice = function(...args) {
|
|
const characterArray = this.valueOf().split('');
|
|
characterArray.splice(...args);
|
|
return characterArray.join('');
|
|
};
|