Skip to content

Commit ff18014

Browse files
committed
Use ES6 modules, build for CJS and AMD
1 parent a957085 commit ff18014

File tree

12 files changed

+121
-47
lines changed

12 files changed

+121
-47
lines changed

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
node_modules
2-
examples/app.js
3-
examples/react-globalize.js
1+
node_modules/
2+
dist/

Gruntfile.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module.exports = function(grunt) {
2+
grunt.loadNpmTasks("grunt-esperanto");
3+
4+
grunt.initConfig({
5+
esperanto: {
6+
amd: {
7+
options: {
8+
type: "amd"
9+
},
10+
expand: true,
11+
cwd: "src",
12+
src : ["**.js", "!index.js"],
13+
dest: "dist/amd/"
14+
},
15+
cjs: {
16+
options: {
17+
type: "cjs"
18+
},
19+
expand: true,
20+
cwd: "src",
21+
src : ["**.js"],
22+
dest: "dist/"
23+
24+
}
25+
}
26+
});
27+
28+
grunt.registerTask("esperanto-cjs-cleanup", function() {
29+
var done = this.async();
30+
var srcFiles = grunt.file.expand("dist/**.js").map(function(filepath) {
31+
var newContent;
32+
var content = grunt.file.read(filepath);
33+
34+
// Remove entries like /^require("globalize/currency");$/
35+
newContent = content.replace(/require\('globalize\/.*/g, "");
36+
if (content !== newContent) {
37+
grunt.file.write(filepath, newContent);
38+
}
39+
});
40+
});
41+
42+
grunt.registerTask("build", ["esperanto", "esperanto-cjs-cleanup"]);
43+
grunt.registerTask("default", ["build"]);
44+
};

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Kris Borchers
3+
Copyright (c) 2015 Kris Borchers, Rafael Xavier de Souza @rxaviers
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

index.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-globalize",
33
"version": "0.2.0",
44
"description": "Bringing the i18n functionality of Globalize, backed by CLDR, to React",
5-
"main": "index.js",
5+
"main": "dist/index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},

src/currency.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
import generator from "./generator";
3+
import "globalize/currency";
4+
5+
export default React.createClass(generator("formatCurrency", ["value", "currency", "options"]));

src/date.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
import generator from "./generator";
3+
import "globalize/date";
4+
5+
export default React.createClass(generator("formatDate", ["value", "options"]));

src/generator.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from "react";
2+
import Globalize from "globalize";
3+
4+
function capitalizeFirstLetter(string) {
5+
return string.charAt(0).toUpperCase() + string.slice(1);
6+
}
7+
8+
function generator(fn, argArray, options) {
9+
var Fn = capitalizeFirstLetter(fn);
10+
options = options || {};
11+
return {
12+
displayName: Fn,
13+
format: function() {
14+
return this.instance[fn].apply(this.instance, this.args);
15+
},
16+
render: function() {
17+
var formatted;
18+
var componentProps = this.props;
19+
this.instance = Globalize;
20+
this.args = argArray.map(function(element) {
21+
return componentProps[element];
22+
});
23+
24+
if (this.props["locale"]) {
25+
this.instance = Globalize(this.props["locale"]);
26+
}
27+
28+
return React.DOM.span(null, this.format());
29+
}
30+
}
31+
};
32+
33+
export default generator;

src/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import FormatCurrency from "./currency";
2+
import FormatDate from "./date";
3+
import FormatMessage from "./message";
4+
import FormatNumber from "./number";
5+
import FormatRelativeTime from "./relative-time";
6+
7+
export default {
8+
FormatCurrency: FormatCurrency,
9+
FormatDate: FormatDate,
10+
FormatMessage: FormatMessage,
11+
FormatNumber: FormatNumber,
12+
FormatRelativeTime: FormatRelativeTime
13+
};

src/message.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Globalize from "globalize";
2+
import React from "react";
3+
import generator from "./generator";
4+
import "globalize/message";
5+
import "globalize/plural";
6+
7+
export default React.createClass(generator("formatMessage", ["path", "variables"]));

0 commit comments

Comments
 (0)