如何将opening_hours.js包含在节点.js脚本中
How to include opening_hours.js into a node.js script?
我想在node.js shell脚本中使用opening_hours.js。该库及其依赖项 SunCalc 在本地可用:
- JS/suncalc.js
- JS/opening_hours.js
我想在脚本中使用opening_hours.js如下:
#!/usr/bin/env node
// TODO: load libraries
var oh = new opening_hours('We 12:00-14:00');
感兴趣的可能是 javascript 文件中的以下摘录:
从opening_hours.js:
// make the library accessible for the outside world {{{
if (typeof exports === 'object') {
var moment, SunCalc, i18n;
// For Node.js.
SunCalc = root.SunCalc || require('suncalc');
try { // as long as it is an optional dependency
moment = root.moment || require('moment');
} catch (error_pass) { error_pass }
try { // as long as it is an optional dependency
i18n = require('./locales/core');
} catch (error_pass) { error_pass }
module.exports = factory(SunCalc, moment, i18n, holiday_definitions, word_error_correction, lang);
} else {
// For browsers.
root.opening_hours = factory(root.SunCalc, root.moment, root.i18n, holiday_definitions, word_error_correction, lang);
}
//* }}} */
从SunCalc.js:
// export as AMD module / Node module / browser variable
if (typeof define === 'function' && define.amd) define(SunCalc);
else if (typeof module !== 'undefined') module.exports = SunCalc;
else window.SunCalc = SunCalc;
问题是opening_hours.js
希望SunCalc作为NPM模块安装。您需要更新您发布的代码中的 require
语句以指向本地 SunCalc 文件:
// make the library accessible for the outside world {{{
if (typeof exports === 'object') {
var moment, SunCalc, i18n;
// For Node.js.
SunCalc = root.SunCalc || require('./suncalc'); // CHANGED
try { // as long as it is an optional dependency
moment = root.moment || require('moment');
} catch (error_pass) { error_pass }
try { // as long as it is an optional dependency
i18n = require('./locales/core');
} catch (error_pass) { error_pass }
module.exports = factory(SunCalc, moment, i18n, holiday_definitions, word_error_correction, lang);
} else {
// For browsers.
root.opening_hours = factory(root.SunCalc, root.moment, root.i18n, holiday_definitions, word_error_correction, lang);
}
//* }}} */
相关文章:
- jQuery/JS包含运算符或类似运算符
- 通过.js包含或调用php或html文件
- 如何使用JS包含文件或PHP代码
- 拥有Gruntname文件,并通过Gruntfile.js包含带有源文件名的横幅
- undercore.js-包含和减少之间的关系
- 如何使用Jade正确地将Fusioncharts.js包含在Node Express项目中
- 绘制图表.js包含 ajax 数据和响应式.一些问题和疑问
- 如何将 gridster.js 包含在 Ember 应用程序中
- 链接在被 Angular JS 包含时不再有效
- 节点.js包含类文件
- 如何将 Controller.js 包含在 ng-include HTML 页面中
- Elixir + Gulp + Laravel,根据URL的不同,具有不同的JS包含物
- 将多个.js包含移动到一个包含的正确方法
- 如何将opening_hours.js包含在节点.js脚本中
- 扩展js包含的模板
- node-js包含的路由文件不允许端点
- 如何使用angular.js包含.js文件
- 如何将node.js包含到静态html中
- Backbone.js:包含多个具有相同ID的模型的集合
- 使用Angular.js包含多选选项时出现TypeError