mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 19:09:18 +08:00
add json5 typing
This commit is contained in:
7
json5/json5-test.ts
Normal file
7
json5/json5-test.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
/// <reference path="json5.d.ts" />
|
||||
import JSON5 = require('json5');
|
||||
|
||||
var obj = JSON5.parse("{ key:'val', 'key2':[0,1,2,] } //comment ");
|
||||
var str = JSON5.stringify(obj, null, "\t");
|
||||
console.log(str);
|
||||
|
||||
45
json5/json5.d.ts
vendored
Normal file
45
json5/json5.d.ts
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
// Type definitions for JSON5
|
||||
// Project: http://json5.org/
|
||||
// Definitions by: Jason Swearingen <https://jasonswearingen.github.io>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
|
||||
//commonjs loader
|
||||
declare module "json5" {
|
||||
/**
|
||||
* The following is the exact list of additions to JSON's syntax introduced by JSON5. All of these are optional, and all of these come from ES5.
|
||||
|
||||
Objects
|
||||
|
||||
Object keys can be unquoted if they're valid identifiers. Yes, even reserved keywords (like default) are valid unquoted keys in ES5 [§11.1.5, §7.6]. (More info)
|
||||
|
||||
(TODO: Unicode characters and escape sequences aren’t yet supported in this implementation.)
|
||||
|
||||
Objects can have trailing commas.
|
||||
|
||||
Arrays
|
||||
|
||||
Arrays can have trailing commas.
|
||||
Strings
|
||||
|
||||
Strings can be single-quoted.
|
||||
|
||||
Strings can be split across multiple lines; just prefix each newline with a backslash. [ES5 §7.8.4]
|
||||
|
||||
Numbers
|
||||
|
||||
Numbers can be hexadecimal (base 16).
|
||||
|
||||
Numbers can begin or end with a (leading or trailing) decimal point.
|
||||
|
||||
Numbers can include Infinity, -Infinity, NaN, and -NaN.
|
||||
|
||||
Numbers can begin with an explicit plus sign.
|
||||
|
||||
Comments
|
||||
|
||||
Both inline (single-line) and block (multi-line) comments are allowed.
|
||||
*/
|
||||
var json5: JSON;
|
||||
export = json5;
|
||||
}
|
||||
Reference in New Issue
Block a user