xonecas.io
291
Na

NameMaker / commit 704a3c6

add initial files

Sean2015-07-22 704a3c67a61d551d3ea91910981f4cfd25631471

4 files changed

index.html+6−0
@@ -0,0 +1,6 @@
1+<!doctype html>
2+<html>
3+ <body>
4+ <script src="script-compiled.js"></script>
5+ </body>
6+</html>
run.sh+16−0
@@ -0,0 +1,16 @@
1+#!/bin/bash
2+
3+PWD=`dirname $0`
4+mkdir -p $PWD/logs
5+touch $PWD/logs/babel.log
6+
7+babel script.js --watch --out-file script-compiled.js &> $PWD/logs/babel.log &
8+BABEL_PID=$!
9+
10+function finish {
11+ kill $BABEL_PID
12+ rm -rf $PWD/logs
13+}
14+trap finish EXIT
15+
16+tail -n 100 -f $PWD/logs/*
script-compiled.js+56−0
@@ -0,0 +1,56 @@
1+"use strict";
2+
3+var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) define …
4+
5+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6+
7+var ADJECTIVES = "different,used,important,every,large,available,popular,able,basic,known,various,difficult,several,united,historical,hot,useful,mental,scared,additional,emotional,old,political,similar,healthy,financial,medical,traditional,federal,entire,strong,actual,significant,successful,electrical,expensive,pregnant,intelligent,interesting,poor,happy,responsible,cute,helpful,recent,willing,nice,wonderful,impossible,serious,huge,rare,technical,typical,competitive,critical,electronic,immediate …
8+
9+var NAMES = "time,year,people,way,day,man,thing,woman,life,child,world,school,state,family,student,group,country,problem,hand,part,place,case,week,company,system,program,question,work,government,number,night,Mr,point,home,water,room,mother,area,money,storey,fact,month,lot,right,study,book,eye,job,word,business";
10+
11+var MyMath = (function () {
12+ function MyMath() {
13+ _classCallCheck(this, MyMath);
14+ }
15+
16+ _createClass(MyMath, null, [{
17+ key: "range",
18+ value: function range(min, max) {
19+ return Math.floor(Math.random() * (max - min) + min);
20+ }
21+ }]);
22+
23+ return MyMath;
24+})();
25+
26+var NameMaker = (function () {
27+ function NameMaker() {
28+ _classCallCheck(this, NameMaker);
29+
30+ this.nouns = NAMES.split(',');
31+ this.adjectives = ADJECTIVES.split(',');
32+ }
33+
34+ _createClass(NameMaker, [{
35+ key: "getAdjective",
36+ value: function getAdjective() {
37+ var len = this.adjectives.length;
38+ return this.adjectives[MyMath.range(0, len)];
39+ }
40+ }, {
41+ key: "getNoun",
42+ value: function getNoun() {
43+ var len = this.nouns.length;
44+ return this.nouns[MyMath.range(0, len)];
45+ }
46+ }, {
47+ key: "go",
48+ value: function go() {
49+ var noun = this.getNoun(),
50+ adjective = this.getAdjective();
51+ return adjective + " " + noun;
52+ }
53+ }]);
54+
55+ return NameMaker;
56+})();
script.js+35−0
@@ -0,0 +1,35 @@
1+var ADJECTIVES = "different,used,important,every,large,available,popular,able,basic,known,various,difficult,several,united,historical,hot,useful,mental,scared,additional,emotional,old,political,similar,healthy,financial,medical,traditional,federal,entire,strong,actual,significant,successful,electrical,expensive,pregnant,intelligent,interesting,poor,happy,responsible,cute,helpful,recent,willing,nice,wonderful,impossible,serious,huge,rare,technical,typical,competitive,critical,electronic,immediate …
2+
3+var NAMES = "time,year,people,way,day,man,thing,woman,life,child,world,school,state,family,student,group,country,problem,hand,part,place,case,week,company,system,program,question,work,government,number,night,Mr,point,home,water,room,mother,area,money,storey,fact,month,lot,right,study,book,eye,job,word,business"
4+
5+
6+class MyMath {
7+ static range (min, max) {
8+ return Math.floor(Math.random() * (max - min) + min);
9+ }
10+}
11+
12+
13+class NameMaker {
14+ constructor() {
15+ this.nouns = NAMES.split(',');
16+ this.adjectives = ADJECTIVES.split(',');
17+ }
18+
19+ getAdjective() {
20+ var len = this.adjectives.length;
21+ return this.adjectives[MyMath.range(0, len)];
22+ }
23+
24+ getNoun() {
25+ var len = this.nouns.length;
26+ return this.nouns[MyMath.range(0, len)];
27+ }
28+
29+ go() {
30+ var noun = this.getNoun(),
31+ adjective = this.getAdjective();
32+ return `${adjective} ${noun}`
33+ }
34+}
35+