Skip to content

Commit fac8583

Browse files
authored
Merge pull request #2 from Daniihh/satisfy-tests
Satisfy All Tests
2 parents b7cc7b1 + b34d2fe commit fac8583

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

src/tools.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ defineProperties(Object, {
438438
},
439439

440440
getType(item: any) {
441+
if (item === null) return "null";
442+
if (typeof item != "object") return typeof item;
441443
return Object.getPrototypeOf(item).constructor.name;
442444
},
443445

@@ -457,7 +459,7 @@ defineProperties(String.prototype, {
457459
return this.substr(0, 1).toUpperCase() + this.substr(1);
458460
},
459461

460-
escape(nonSpecials: boolean = true) {
462+
escape(nonSpecials: boolean = true) { //TODO: Improve me!
461463
let charArray = this.split("");
462464
if (nonSpecials) charArray = charArray.map((char) => ['"', "'", "\\"].includes(char) ? "\\" + char : char)
463465
charArray = charArray.map((char) => ["\n", "\r", "\t"].includes(char) ? "\\" + {"\n": "n", "\r": "r", "\t": "t"}[char] : char);
@@ -469,28 +471,9 @@ defineProperties(String.prototype, {
469471
},
470472

471473
interpolate(this: string, values: Of<any>) {
472-
let from = 0;
473-
let data: {content: string, type: "string" | "code"}[] = [];
474-
let asString = (obj) =>
475-
obj === null ? "null" : obj === undefined ? "undefined" :
476-
typeof obj.toString == "function" ? obj.toString() :
477-
Object.prototype.toString.call(obj);
478-
let push = (content: string, code?: boolean) =>
479-
data.push({content, "type": code ? "code" : "string"});
480-
[...this.matchAll(/\\?\$/g), null].forEach(val => {
481-
if (val && val[0].startsWith("\\")) return;
482-
let str = this.substring(from, val ? val.index : this.length);
483-
if (str) push(str);
484-
if (val) {
485-
let pos = findPairs(this, {"{": num => ++num, "}": num => --num});
486-
let code = this.substring(val.index + 2, pos - 1);
487-
if (code) push(code, true);
488-
from = pos + 1;
489-
}
490-
});
491-
return data.reduce((acc, val) => acc + (val.type == "code" ?
492-
asString(evaluate(val.content, values)) :
493-
val.content), "");
474+
let charArray = this.split("");
475+
charArray = charArray.map(char => char == "`" ? "\`" : char == "\\" ? "\\\\" : char);
476+
return evaluate("`" + charArray.join("") + "`", values);
494477
}
495478
} as Partial<String>);
496479

@@ -520,8 +503,6 @@ const keywords = ["arguments", "in", "of", "for", "if", "else", "throw", "while"
520503
*/
521504
export function bound<Type extends (...a: any[]) => any>(proto: Object,
522505
key: string, descriptor: TypedPropertyDescriptor<Type>) {
523-
if (proto.constructor == Object) descriptor = proto; //BABEL Fix
524-
525506
let value = descriptor.value;
526507
delete descriptor.writable;
527508
delete descriptor.value;

test/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
77

8-
<script type="module" src="../out/tools.js"></script>
8+
<script>
9+
let module;
10+
import("../out/esmodule-tools.js").then(mod => module = mod);
11+
</script>
912

1013
<title>Document</title>
1114
</head>

test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe("Object", function() {
9292
describe(".getType()", function() {
9393
it('should return the input\'s typeof value if it is not typeof "object"', function() {
9494
let tests = ["Thinking up values for tests is hard.", 8764, Symbol("Another secret!")];
95-
tests.forEach(test => assert.strictEqual(Object.getType(test), typeof type));
95+
tests.forEach(test => assert.strictEqual(Object.getType(test), typeof test));
9696
});
9797

9898
it("should return the inputs's contructor's name if it is typeof is \"object\"", function() {
@@ -115,7 +115,7 @@ describe("String", function() {
115115

116116
describe("#toTitleCase()", function() {
117117
it("should convert the string to title case", function() {
118-
assert.strictEqual("this is my video TITLE".toTitleCase(), "This is My Video Title");
118+
assert.strictEqual("this is my video TITLE".toTitleCase(), "This Is My Video Title");
119119
});
120120
});
121121

0 commit comments

Comments
 (0)