master
yutent 2022-03-18 19:04:12 +08:00
parent 5400d17989
commit 92f7e3f0a9
1 changed files with 43 additions and 29 deletions

View File

@ -1,38 +1,52 @@
if (!String.prototype.size) {
Object.defineProperty(String.prototype, 'size', {
get() {
var n = 0
for (let it of this) {
n++
}
return n
}
})
/**
* 增强版 String
*/
export class SString {
#origin = ''
#list = []
Object.defineProperty(String.prototype, 'at16', {
value(n) {
var tmp = []
for (let it of this) {
tmp.push(it)
}
return tmp[n]
constructor(str = '') {
this.#origin = str
for (let it of str) {
this.#list.push(it)
}
})
Object.defineProperty(String.prototype, 'split16', {
value(pipe) {
if (pipe === '') {
var tmp = []
for (let it of this) {
tmp.push(it)
}
return tmp
} else {
return this.split(pipe)
}
get length() {
return this.#list.length
}
at(index = 0) {
if (this.length > 0) {
while (index < 0) {
index += this.length
}
return this.#list[index]
}
}
split() {
return this.#list
}
forEach(callback) {
for (let i in this.#list) {
if (callback(this.#list[i], i) === false) {
break
}
}
})
return this
}
toString() {
return this.#origin
}
}
/**
* 特殊版 Enum
*/
export class Enum {
#dict_k = Object.create(null)
#dict_v = Object.create(null)