本文整理匯總了TypeScript中undefined.forEach函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript forEach函數的具體用法?TypeScript forEach怎麽用?TypeScript forEach使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了forEach函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: classifier
topic.actions.forEach((action: ActionCollection) => { // eslint-disable-line no-unused-vars
const phrases = action.phrases;
const key = action.action;
const thisClassifier = new classifier();
const otherPhrases = _.difference(allPhrases, phrases);
// console.log(value);
phrases.forEach(phrase => thisClassifier.addDocument(phrase, 'true'));
otherPhrases.forEach(phrase => thisClassifier.addDocument(phrase, 'false'));
thisClassifier.train();
// console.log(`--${key}--`);
//
// const othersChecked = otherPhrases.map(phrase => thisClassifier.classify(phrase)).map((classified, index) => {
// if (classified === 'true') {
// // console.log('other', index, otherPhrases[index], thisClassifier.getClassifications(otherPhrases[index]));
// return otherPhrases[index];
// }
// return null;
// });
//
// const selfChecked = phrases.map(phrase => thisClassifier.classify(phrase)).map((classified, index) => {
// if (classified === 'false') {
// // console.log('self', index, value[index], thisClassifier.getClassifications(value[index]));
// return phrases[index];
// }
// // console.log(value[index], thisClassifier.getClassifications(value[index]));
// return null;
// });
// console.log('other:', otherPhrases.length, ' self:', value.length);
// console.log('passed for other', _.compact(othersChecked));
// console.log('failed for home', _.compact(selfChecked));
classifiers[key] = thisClassifier;
});
示例2: require
config.plugins.forEach((plugin) => {
const CommandApp = require(plugin);
if (!Array.isArray(CommandApp)) {
return app.registerApp(CommandApp);
}
return CommandApp.forEach(PluginApp => app.registerApp(PluginApp));
});
示例3: require
const actual = (file: string) => {
const data = require(path.join(srcDir, file));
const hash: Record<string, any> = {};
data.forEach((item: any) => {
for (const key in item) {
hash[key] = item[key];
}
});
return {
hash,
get: (subnet: string) => {
const item = hash[subnet];
assert(item);
return item;
},
};
};
示例4: require
(() => {
"use strict";
const path = require("path");
let config = require('../config/config.json');
config.serverRoot = path.join(__dirname, '../');
const routes = require(config.serverRoot + 'config/routes.json');
const fs = require("fs");
const http = require('http');
const https = require('https');
const bodyParser = require('body-parser')
const express = require('express');
const exphbs = require('express-handlebars');
const app = express();
//set view engine
if (config.handlebarsTemplateEngine) {
app.set('views', config.serverRoot + '/views');
const exphbsOptions = {
defaultLayout: 'main',
layoutsDir: config.serverRoot + '/views/layouts',
partialsDir: config.serverRoot + '/views/partials',
extname: ".view.html"
};
app.engine('.view.html', exphbs(exphbsOptions));
app.set('view engine', '.view.html');
app.enable('view cache');
}
//setting the static folder fo the app
app.use(express.static(path.join(config.serverRoot, '../src/public')));
//routing
//loop through the routes.json file
//connecting the right controller
//for each route and create it
routes.forEach((route) => {
const controller = require(config.serverRoot + '/controllers/' + route.controller + '.ctrl');
let middlewares = [];
//load middlewares if exist for this route
if (typeof route.middlewares !== "undefined" && route.middlewares.length) {
route.middlewares.forEach((midName) => {
const m = require(config.serverRoot + '/middlewares/' + midName + '.mid.ts');
middlewares.push(m);
});
}
app.all(route.path, middlewares, controller);
});
//reducing the http header size
//by removing x-powered-by
app.disable('x-powered-by');
//set the http server
if (config.httpServer) {
const httpServer = http.createServer(app);
httpServer.listen(config.httpPort, () => {
console.log(`${config.appName} http server listening on port ${config.httpPort}`);
});
}
//set the https server
if (config.httpsServer) {
const sslConfig = {
key: fs.readFileSync(config.serverRoot + 'config/ssl/file.pem'),
cert: fs.readFileSync(config.serverRoot + 'config/ssl/file.crt')
};
const httpsServer = https.createServer(sslConfig, app);
httpsServer.listen(config.httpsPort, () => {
console.log(`${config.appName} https server listening on port ${config.httpsPort}`);
});
}
})();