summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toml/README.md5
-rw-r--r--toml/parser.ts20
-rw-r--r--toml/parser_test.ts12
3 files changed, 19 insertions, 18 deletions
diff --git a/toml/README.md b/toml/README.md
index f4ae25857..e30d972f3 100644
--- a/toml/README.md
+++ b/toml/README.md
@@ -94,9 +94,10 @@ will output:
### Parse
```ts
-import { parseFile, parse } from "./parser.ts";
+import { parse } from "./parser.ts";
+import { readFileStrSync } from "../fs/read_file_str.ts";
-const tomlObject = parseFile("file.toml");
+const tomlObject = parse(readFileStrSync("file.toml"));
const tomlString = 'foo.bar = "Deno"';
const tomlObject22 = parse(tomlString);
diff --git a/toml/parser.ts b/toml/parser.ts
index c615c3c1e..cc96322fb 100644
--- a/toml/parser.ts
+++ b/toml/parser.ts
@@ -1,6 +1,4 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { existsSync } from "../fs/exists.ts";
-import { readFileStrSync } from "../fs/read_file_str.ts";
import { deepAssign } from "../util/deep_assign.ts";
import { pad } from "../strings/pad.ts";
@@ -275,12 +273,12 @@ class Parser {
_parseDeclarationName(declaration: string): string[] {
const out = [];
let acc = [];
- let inLitteral = false;
+ let inLiteral = false;
for (let i = 0; i < declaration.length; i++) {
const c = declaration[i];
switch (c) {
case ".":
- if (!inLitteral) {
+ if (!inLiteral) {
out.push(acc.join(""));
acc = [];
} else {
@@ -288,10 +286,10 @@ class Parser {
}
break;
case `"`:
- if (inLitteral) {
- inLitteral = false;
+ if (inLiteral) {
+ inLiteral = false;
} else {
- inLitteral = true;
+ inLiteral = true;
}
break;
default:
@@ -538,11 +536,3 @@ export function parse(tomlString: string): object {
tomlString = tomlString.replace(/\r\n/g, "\n").replace(/\\\n/g, "\n");
return new Parser(tomlString).parse();
}
-
-export function parseFile(filePath: string): object {
- if (!existsSync(filePath)) {
- throw new Error("File not found");
- }
- const strFile = readFileStrSync(filePath);
- return parse(strFile);
-}
diff --git a/toml/parser_test.ts b/toml/parser_test.ts
index 03c733714..4b53945f4 100644
--- a/toml/parser_test.ts
+++ b/toml/parser_test.ts
@@ -1,10 +1,20 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
-import { parseFile, stringify } from "./parser.ts";
+import { existsSync } from "../fs/exists.ts";
+import { readFileStrSync } from "../fs/read_file_str.ts";
+import { parse, stringify } from "./parser.ts";
import * as path from "../fs/path/mod.ts";
const testFilesDir = path.resolve("toml", "testdata");
+function parseFile(filePath: string): object {
+ if (!existsSync(filePath)) {
+ throw new Error(`File not found: ${filePath}`);
+ }
+ const strFile = readFileStrSync(filePath);
+ return parse(strFile);
+}
+
test({
name: "[TOML] Strings",
fn(): void {