本文整理汇总了TypeScript中event-stream.map函数的典型用法代码示例。如果您正苦于以下问题:TypeScript map函数的具体用法?TypeScript map怎么用?TypeScript map使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了map函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createReadStream
.pipe(map((file, callback) => {
let variableLine, variableName, defaultValue, multiline;
createReadStream(file.path, { flags: 'r'})
.pipe(split())
.pipe(map((line, callback) => {
if (line.charAt(0) === '$') {
variableLine = line.split(/:(.+)/);
variableName = variableLine[0];
defaultValue = variableLine[1];
// If there is a semicolon then it isn't a multiline value
multiline = line.indexOf(';') > -1 ? false : true;
if (!multiline && line.indexOf('!default') > -1) {
addVariable(variableName, defaultValue, file);
}
} else if (multiline === true) {
defaultValue += '\n' + line;
// If the line has a semicolon then we've found the end of the value
if (line.indexOf(';') > -1 && line.indexOf('!default') > -1) {
addVariable(variableName, defaultValue, file);
multiline = false;
}
}
callback();
}));
callback();
}).on('end', () => {
示例2: getBrowserCode
export function getBrowserCode(appName: string, opts?: PrebootOptions, done?: Function): any {
let deferred = Q.defer();
let clientCode = '';
// check cache first (as long as it wasn't disabled)
let cacheKey = JSON.stringify(opts);
// opts can be undefined
if (opts && !opts.disableCodeCache && browserCodeCache[cacheKey]) {
return Q.when(browserCodeCache[cacheKey]);
}
// get the browser code
getBrowserCodeStream(appName, opts)
.pipe(eventStream.map(function(file, cb) {
clientCode += file.contents;
cb(null, file);
}))
.on('error', function(err) {
if (done) {
done(err);
}
deferred.reject(err);
})
.on('end', function() {
if (done) {
done(null, clientCode);
}
browserCodeCache[cacheKey] = clientCode;
deferred.resolve(clientCode);
});
return deferred.promise;
}
示例3: getBrowserCode
export function getBrowserCode(opts?: PrebootOptions, done?: Function): any {
let deferred = Q.defer();
let clientCode = '';
// check cache first
let cacheKey = JSON.stringify(opts);
if (browserCodeCache[cacheKey]) {
return Q.when(browserCodeCache[cacheKey]);
}
// get the browser code
getBrowserCodeStream(opts)
.pipe(eventStream.map(function(file, cb) {
clientCode += file.contents;
cb(null, file);
}))
.on('error', function(err) {
if (done) {
done(err);
}
deferred.reject(err);
})
.on('end', function() {
if (done) {
done(null, clientCode);
}
browserCodeCache[cacheKey] = clientCode;
deferred.resolve(clientCode);
});
return deferred.promise;
}
示例4: templateCache
function templateCache(options: NgTemplatesOptions) {
return es.map(function(file: any, callback: (err: any, htmlMinifierfile: any) => void) {
var template = '$templateCache.put("<%= url %>","<%= contents %>");';
var url;
file.path = path.normalize(file.path);
if(typeof options.path === 'function') {
url = path.join(options.path(file.path, file.base));
} else {
url = path.join(file.path);
url = url.replace(file.base, '');
};
if (process.platform === 'win32') {
url = url.replace(/\\/g, '/');
}
let contents = file.contents.toString();
if(options.htmlMinifier) {
contents = minify(contents, options.htmlMinifier);
}
contents = require('js-string-escape')(contents);
file.contents = Buffer.from(lodashTemplate(template)({
url: url,
contents: contents,
file: file
}), 'utf8');
callback(null, file);
});
}
示例5: task
task('docs.sassVariables', () => {
let variables = [];
const outputFile = 'tmp/sass.json';
function addVariable(variableName, defaultValue, file) {
const entities = new AllHtmlEntities();
defaultValue = entities.encode(defaultValue);
defaultValue = defaultValue.replace('!default;', '');
variables.push({
name: variableName,
defaultValue: defaultValue.trim(),
file: relative('./', file.path)
});
}
return src('./src/**/*.scss')
.pipe(map((file, callback) => {
let variableLine, variableName, defaultValue, multiline;
createReadStream(file.path, { flags: 'r'})
.pipe(split())
.pipe(map((line, callback) => {
if (line.charAt(0) === '$') {
variableLine = line.split(/:(.+)/);
variableName = variableLine[0];
defaultValue = variableLine[1];
// If there is a semicolon then it isn't a multiline value
multiline = line.indexOf(';') > -1 ? false : true;
if (!multiline && line.indexOf('!default') > -1) {
addVariable(variableName, defaultValue, file);
}
} else if (multiline === true) {
defaultValue += '\n' + line;
// If the line has a semicolon then we've found the end of the value
if (line.indexOf(';') > -1 && line.indexOf('!default') > -1) {
addVariable(variableName, defaultValue, file);
multiline = false;
}
}
callback();
}));
callback();
}).on('end', () => {
const config = require('../../config.json');
console.log(`Writing to file at /driftyco/ionic/${outputFile}`);
console.log(`Place this file in /driftyco/ionic-site/${config.v2DocsDir}/theming/overriding-ionic-variables in order to update the docs`);
mkdirp.sync('tmp');
writeFileSync(outputFile, JSON.stringify(variables));
}));
});
示例6: pipelineFunction
export default function pipelineFunction(event?: gulp.WatchEvent) {
const files: string[] = event !== undefined ? [event.path] : [
root.application.scripts.typescripts().toString(),
root.application.scripts.typings().Not(),
//`${Folders.clientUnitTests}/**/*.ts`,
//`!${Folders.clientUnitTests}/typings/**/*.ts`,
//`${Folders.gulp}/**/*.ts`,
//`!${Folders.gulp}/typings/**/*.ts`
];
const reporter = es.map((file, cb) => {
if (event !== undefined) {
const failures = JSON.parse(file.tslint.output);
if (failures.length === 0) {
const prefix = `[${gutil.colors.cyan('gulp-tslint')}]`;
const fileName = path.basename(event.path);
gutil.log(prefix, gutil.colors.green(`${fileName} doesn't have errors`));
}
}
});
const getConfiguration = () => {
return JSON.parse(fs.readFileSync('tslint.json'));
};
const config = {
configuration: getConfiguration()
};
return gulp.src(files)
.pipe(tslint(config))
.pipe(tslint.report('verbose', {
emitError: false,
summarizeFailureOutput: true
}))
.pipe(reporter);
};