add xml-escape typings (#35449)

This commit is contained in:
Charles Kenney 2019-05-14 17:55:43 -04:00 committed by Nathan Shively-Sanders
parent 7594a53576
commit 216d877abf
4 changed files with 52 additions and 0 deletions

13
types/xml-escape/index.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
// Type definitions for xml-escape 1.1
// Project: https://github.com/miketheprogrammer/xml-escape
// Definitions by: Charles Kenney <https://github.com/charliekenney23>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Escape an XML string
*
* @param string String of XML to escape
* @param ignore Characters to ignore
*/
declare function escape(string: string, ignore?: string): string;
export = escape;

View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "xml-escape-tests.ts"]
}

View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}

View File

@ -0,0 +1,20 @@
/// <reference types="node" />
import xmlEscape = require("xml-escape");
const xml = `
<message>
<to>Barack Obama</to>
<from>Joe Biden</from>
<subject>Cats</subject>
<content>I freakin' love cats!!&!</content
</message>
`;
const fullEscaped = xmlEscape(xml); // $ExpectType string
const preservingApostrophe = xmlEscape(xml, "&"); // $ExpectType string
console.info({
fullEscaped,
preservingApostrophe
});