Socket
Socket
Sign inDemoInstall

ember-cli-moment-shim

Package Overview
Dependencies
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-cli-moment-shim - npm Package Compare versions

Comparing version 3.7.0 to 3.7.1

103

index.js

@@ -10,3 +10,2 @@ /* globals require, module, process */

const funnel = require('broccoli-funnel');
const concat = require('broccoli-concat');
const stew = require('broccoli-stew');

@@ -20,68 +19,2 @@ const chalk = require('chalk');

function getLocaleDefinitionModules(requestingTree) {
let options = this._options;
const singleModule = options.singleModule;
if (requestingTree === 'addon' && !singleModule) {
return;
}
if (requestingTree === 'vendor' && singleModule) {
return;
}
let localeTree;
if (
Array.isArray(options.includeLocales) &&
options.includeLocales.length
) {
localeTree = funnel(this.momentNode, {
srcDir: 'locale',
destDir: 'moment/locales',
include: options.includeLocales.map(
locale => new RegExp(locale + '.js$')
)
});
}
if (singleModule) {
// Turn the locales into a hash key/value pairs.
const keyValuePairs = map(localeTree, function(content, relativePath) {
const locale = path.basename(relativePath, '.js');
return `'${locale}': function() { ${content} },`;
});
// This function becomes defineLocale(locale);
const header = `
export default function(locale) {
if (typeof FastBoot === 'undefined') {
const locales = {
`;
const footer = `
};
if (locales[locale]) {
locales[locale]();
}
}
}
`;
const concatenatedDefinitionIIFEs = concat(keyValuePairs, {
header,
footer,
inputFiles: ['**/*'],
outputFile: 'ember-cli-moment-shim/define-locale.js'
});
let babelAddon = this.addons.find(addon => addon.name === 'ember-cli-babel');
return babelAddon.transpileTree(concatenatedDefinitionIIFEs);
} else {
return map(
localeTree,
content => `if (typeof FastBoot === 'undefined') { ${content} }`
);
}
}
module.exports = {

@@ -131,3 +64,3 @@ name: 'moment',

} else {
if (Array.isArray(options.includeLocales) && !options.singleModule) {
if (Array.isArray(options.includeLocales)) {
options.includeLocales.forEach(locale => {

@@ -155,3 +88,2 @@ this.import('vendor/moment/locales/' + locale + '.js', {

let config = defaults(projectConfig, {
singleModule: false,
momentPath: momentPath,

@@ -219,14 +151,9 @@ includeTimezone: null,

treeForAddon() {
const superValue = this._super.apply(this, arguments);
const definitionModules = getLocaleDefinitionModules.call(this, 'addon');
return mergeTrees([superValue, definitionModules].filter(Boolean));
},
treeForVendor() {
treeForVendor(vendorTree) {
let trees = [];
let options = this._options;
const superValue = this._super.apply(this, arguments);
trees.push(superValue);
if (vendorTree) {
trees.push(vendorTree);
}

@@ -243,2 +170,17 @@ trees.push(

if (
Array.isArray(options.includeLocales) &&
options.includeLocales.length
) {
let localeTree = funnel(this.momentNode, {
srcDir: 'locale',
destDir: 'moment/locales',
include: options.includeLocales.map(
locale => new RegExp(locale + '.js$')
)
});
trees.push(localeTree);
}
if (options.includeTimezone) {

@@ -294,7 +236,4 @@ let timezonePath;

const definitionModules = getLocaleDefinitionModules.call(this, 'vendor');
trees.push(definitionModules);
return map(
mergeTrees(trees.filter(Boolean)),
mergeTrees(trees),
content => `if (typeof FastBoot === 'undefined') { ${content} }`

@@ -301,0 +240,0 @@ );

{
"name": "ember-cli-moment-shim",
"version": "3.7.0",
"version": "3.7.1",
"description": "Brings moment and moment-timezone into your Ember applications",

@@ -33,3 +33,2 @@ "keywords": [

"ember-cli-babel": "^6.6.0",
"broccoli-concat": "^3.2.2",
"broccoli-funnel": "^2.0.0",

@@ -36,0 +35,0 @@ "broccoli-merge-trees": "^2.0.0",

@@ -83,56 +83,2 @@ # ember-cli-moment-shim

### Single module use
The default behavior for loading moment locales is an IIFE which is added into
the `vendor.js` file. The consequence of that is that you have no control over
when that code is run. That code also triggers [setting of the moment locale](https://github.com/moment/moment/blob/f6c7069/src/lib/locale/locales.js#L132),
which means that at arbitrary times in your application you don't know what the
locale is.
Included in `ember-cli-moment-shim` is a module that allows you to specify which
localization you would like to load, and when you would like it invoked. This
enables you to configure timing based upon application constraints. (With the
initial state being `en`.)
```js
// config.environment.js
module.exports = function(environment) {
return {
moment: {
includeLocales: ['es', 'fr-ca'],
singleModule: true
}
};
```
```js
// app/routes/applicaton.js
import Route from '@ember/routing/route';
import defineLocale from 'ember-cli-moment-shim/define-locale';
import moment from 'moment';
import { inject as service } from '@ember/service';
export default Route.extend({
moment: service(),
beforeModel() {
const desiredLocale = 'en-us';
// This adds the configuration for *just* the locale you want.
// All locales specified as bundled by `includeLocales` will be available.
defineLocale(desiredLocale);
// Set the locale:
moment.locale(desiredLocale);
// It is possible for the locale in the `ember-moment`-supplied service to
// get out of sync with the locale set in moment itself:
// https://github.com/stefanpenner/ember-moment/blob/b8a262b/addon/services/moment.js#L50-L53
// If using both the service and ES6 approach be sure to keep those values
// consistent.
this.get('moment').setLocale(desiredLocale);
}
});
```
### Write all locales to a folder that is relative to `dist`

@@ -139,0 +85,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc