mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[yaml-front-matter] initial commit (#43307)
This commit is contained in:
parent
7fce7c3827
commit
220266e22c
42
types/yaml-front-matter/index.d.ts
vendored
Normal file
42
types/yaml-front-matter/index.d.ts
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// Type definitions for yaml-front-matter 4.1
|
||||
// Project: https://github.com/dworthen/js-yaml-front-matter#readme
|
||||
// Definitions by: ZHAO Jinxiang <https://github.com/xiaoxiangmoe>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { LoadOptions } from 'js-yaml';
|
||||
|
||||
export function loadFront(
|
||||
content: string | Buffer,
|
||||
options?: LoadOptions,
|
||||
): {
|
||||
readonly [key: string]: any;
|
||||
readonly __content: string;
|
||||
};
|
||||
|
||||
export function loadFront<contentKeyName extends string>(
|
||||
content: string | Buffer,
|
||||
options: LoadOptions & { contentKeyName: contentKeyName },
|
||||
): {
|
||||
readonly [key in contentKeyName]: string;
|
||||
} & {
|
||||
readonly [key: string]: any;
|
||||
};
|
||||
|
||||
export function safeLoadFront(
|
||||
content: string | Buffer,
|
||||
options?: LoadOptions,
|
||||
): {
|
||||
readonly [key: string]: any;
|
||||
readonly __content: string;
|
||||
};
|
||||
|
||||
export function safeLoadFront<contentKeyName extends string>(
|
||||
content: string | Buffer,
|
||||
options: LoadOptions & { contentKeyName: contentKeyName },
|
||||
): {
|
||||
readonly [key in contentKeyName]: string;
|
||||
} & {
|
||||
readonly [key: string]: any;
|
||||
};
|
||||
23
types/yaml-front-matter/tsconfig.json
Normal file
23
types/yaml-front-matter/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"yaml-front-matter-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/yaml-front-matter/tslint.json
Normal file
1
types/yaml-front-matter/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
25
types/yaml-front-matter/yaml-front-matter-tests.ts
Normal file
25
types/yaml-front-matter/yaml-front-matter-tests.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import * as yamlFront from 'yaml-front-matter';
|
||||
|
||||
const hello = yamlFront.loadFront('Hello World').__content;
|
||||
|
||||
const world = yamlFront.loadFront('Hello World', {
|
||||
contentKeyName: 'fileContents'
|
||||
}).fileContents;
|
||||
|
||||
const input = `---
|
||||
post: title one
|
||||
anArray:
|
||||
- one
|
||||
- two
|
||||
subObject:
|
||||
prop1: cool
|
||||
prop2: two
|
||||
reg: !!js/regexp /pattern/gim
|
||||
fun: !!js/function function() { }
|
||||
---
|
||||
content
|
||||
more`;
|
||||
|
||||
const results = yamlFront.loadFront(input);
|
||||
|
||||
console.log(JSON.stringify(results)); // "{"post":"title one","anArray":["one","two"],"subObject":{"obj1":"cool","obj2":"two"},"reg":{},"fun":[null],"__content":"\ncontent\nmore"}"
|
||||
Loading…
Reference in New Issue
Block a user