當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript undefined.forEach函數代碼示例

本文整理匯總了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;
  });
開發者ID:LexieCore,項目名稱:bot-framework,代碼行數:35,代碼來源:classifier.ts

示例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));
  });
開發者ID:Travix-International,項目名稱:frint,代碼行數:9,代碼來源:frint.ts

示例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;
    },
  };
};
開發者ID:runk,項目名稱:node-maxmind,代碼行數:18,代碼來源:integration.test.ts

示例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}`);
		});
	}
})();
開發者ID:spear4life,項目名稱:Socotra,代碼行數:84,代碼來源:main.ts


注:本文中的undefined.forEach函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。