本文整理汇总了TypeScript中ltx.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('Runs successfully with XML Transformation (L1)', (done:MochaDone) => {
let tp = path.join(__dirname, "..", "node_modules","webdeployment-common","Tests","L1XdtTransform.js");
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();
var resultFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XdtTransform', 'Web_test.config')));
var expectFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XdtTransform','Web_Expected.config')));
assert(ltx.equal(resultFile, expectFile) , 'Should Transform attributes on Web.config');
done();
});
示例2: it
it('Runs successfully with XML variable substitution', (done:MochaDone) => {
let tp = path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub.js');
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();
var resultFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XmlVarSub', 'Web_test.config')));
var expectFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XmlVarSub', 'Web_Expected.config')));
assert(ltx.equal(resultFile, expectFile) , 'Should have substituted variables in Web.config file');
var resultFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'Web_test.Debug.config')));
var expectFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'Web_Expected.Debug.config')));
assert(ltx.equal(resultFile, expectFile) , 'Should have substituted variables in Web.Debug.config file');
done();
});
示例3: it
it('Runs successfully with XML variable substitution', (done:MochaDone) => {
let tp = path.join(__dirname, 'L0XmlVarSub.js');
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();
var resultFile = ltx.parse(fs.readFileSync(path.join(__dirname, 'L1XmlVarSub/Web_test.config')));
var expectFile = ltx.parse(fs.readFileSync(path.join(__dirname, 'L1XmlVarSub/Web_Expected.config')));
assert(ltx.equal(resultFile, expectFile) , 'Should have substituted variables in Web.config file');
var resultFile = ltx.parse(fs.readFileSync(path.join(__dirname, 'L1XmlVarSub/Web_test.Debug.config')));
var expectFile = ltx.parse(fs.readFileSync(path.join(__dirname, 'L1XmlVarSub/Web_Expected.Debug.config')));
assert(ltx.equal(resultFile, expectFile) , 'Should have substituted variables in Web.Debug.config file');
var expectedOut = 'Updated history to kudu';
assert(tr.stdout.search(expectedOut) > 0, 'should have said: ' + expectedOut);
done();
});
示例4: initializeDOM
export function initializeDOM(xmlContent) {
xmlDomLookUpTable = {};
headerContent = null;
var xmlDom = ltx.parse(xmlContent);
readHeader(xmlContent);
buildLookUpTable(xmlDom);
return xmlDom;
}
示例5: _updateXmlFile
private static _updateXmlFile(xmlPath: string, updateFn: (xml: any) => any): void {
let xmlString = fs.readFileSync(xmlPath).toString();
// strip BOM; xml parser doesn't like it
if (xmlString.charCodeAt(0) === 0xFEFF) {
xmlString = xmlString.substr(1);
}
let xml = ltx.parse(xmlString);
xml = updateFn(xml);
fs.writeFileSync(xmlPath, xml.root().toString());
}
示例6:
import * as ltx from 'ltx';
ltx.parse('<document/>');
const p = new ltx.Parser();
p.on('tree', (ignored: any) => {});
p.on('error', (ignored: any) => {});
const el = new ltx.Element('root').c('children');
el.c('child', {age: 5}).t('Hello').up()
.c('child', {age: 7}).t('Hello').up()
.c('child', {age: 99}).t('Hello').up();
el.root().toString();
示例7: Error
import * as ltx from 'ltx';
ltx.parse('<document/>');
const getChildTextElement = ltx.parse('<test><child>body text</child></test>') as ltx.Element;
if (getChildTextElement.getChildText('child') !== 'body text') {
throw new Error("body does not match");
}
const p = new ltx.Parser();
p.on('tree', (ignored: any) => {});
p.on('error', (ignored: any) => {});
const el = new ltx.Element('root').c('children');
el.c('child', {age: 5}).t('Hello').up()
.c('child', {age: 7}).t('Hello').up()
.c('child', {age: 99}).t('Hello').up();
el.root().toString();
示例8: Error
}
if (ltx.isElement(any)) {
// $ExpectType Element
any;
}
if (ltx.isText(any)) {
// $ExpectType string
any;
}
str = ltx.escapeXML(str);
str = ltx.unescapeXML(str);
str = ltx.escapeXMLText(str);
str = ltx.unescapeXMLText(str);
el = ltx.parse('<document/>');
el = ltx.parse('<document/>', (null as any) as ltx.Parser);
el = ltx.parse('<document/>', { Parser: (null as any) as typeof ltx.Parser });
el = ltx.parse('<document/>', { Element: (null as any) as typeof ltx.Element });
el = ltx.tag(['document'], 'foo');
str = ltx.tagString(['document'], 'foo');
str = ltx.stringify(el);
str = ltx.stringify(el, 1);
str = ltx.stringify(el, 1, 1);
const getChildTextElement = ltx.parse('<test><child>body text</child></test>');
if (getChildTextElement.getChildText('child') !== 'body text') {
throw new Error('body does not match');
}
示例9: getSourcesFromNuGetConfig
export function getSourcesFromNuGetConfig(configPath: string): IPackageSourceBase[] {
// load content of the user's nuget.config
if (!configPath) {
return [];
}
tl.debug('Getting sources from NuGet.config in this location: ' + configPath);
let xmlString = fs.readFileSync(configPath).toString();
// strip BOM; xml parser doesn't like it
if (xmlString.charCodeAt(0) === 0xFEFF) {
xmlString = xmlString.substr(1);
}
// parse sources xml
let xml: ltx.Element;
try {
xml = ltx.parse(xmlString);
} catch (e) {
throw new Error(tl.loc("NGCommon_NuGetConfigIsInvalid", configPath));
}
// give clearer errors if the user has set an invalid nuget.config
if(!xml.nameEquals(new ltx.Element("configuration"))) {
if(xml.nameEquals(new ltx.Element("packages"))) {
throw new Error(tl.loc(
"NGCommon_NuGetConfigIsPackagesConfig",
configPath,
tl.getVariable("Task.DisplayName")));
}
else {
throw new Error(tl.loc("NGCommon_NuGetConfigIsInvalid", configPath));
}
}
// check that the config contains packageSources entries
let hasSources = false;
let packageSources = xml.getChild("packageSources");
let addPackageSources: ltx.Element[];
if (packageSources) {
addPackageSources = packageSources.getChildren("add");
if (addPackageSources) {
hasSources = true;
}
}
if (!hasSources) {
tl.warning(tl.loc("NGCommon_NoSourcesFoundInConfig", configPath));
return [];
}
// convert to IPackageSourceBase[]
let sources = addPackageSources.reduce((result, current) => {
const k = current.attrs["key"];
const v = current.attrs["value"];
// filter out any invalid entries
if (k != null && v != null) {
let packageSource: IPackageSourceBase = {
feedName: k,
feedUri: v
}
result.push(packageSource);
}
return result;
}, []);
return sources;
}