Skip to content

Commit 560f701

Browse files
committed
Primera version cronometro OK
1 parent 1aa47b0 commit 560f701

File tree

105 files changed

+9328
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+9328
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
package-lock.json

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
test.js
2+
package-lock.json
3+
node_modules/
4+
lib/
5+
documentation/
6+
tsconfig.doc.json

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Cronometro
2+
Un cronometro que cuenta y descuenta
3+
4+
## Instalación
5+
6+
```
7+
npm install proyecto-2c-crono
8+
```
9+
10+
## Uso
11+
12+
### Contador
13+
```
14+
const modulo = require('proyecto-2c-crono');
15+
16+
const cont = new modulo.Contador(2);
17+
18+
var d = cont.start().subscribe(
19+
data => {
20+
console.log(data);
21+
if (data === 'FINISH') {
22+
d.unsubscribe();
23+
}
24+
}
25+
);
26+
//Espera estos resultados
27+
00:00:00
28+
00:00:01
29+
FINISH
30+
31+
```
32+
33+
### Descontador
34+
```
35+
const modulo = require('proyecto-2c-crono');
36+
37+
const cont = new modulo.Descontador(4);
38+
39+
var d = cont.start().subscribe(
40+
data => {
41+
console.log(data);
42+
if (data === 'FINISH') {
43+
d.unsubscribe();
44+
}
45+
}
46+
);//Espera estos resultados
47+
00:00:04
48+
00:00:03
49+
00:00:02
50+
00:00:01
51+
FINISH
52+
```

dist/constants.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Constantes de tiempo
3+
*/
4+
export declare enum Tiempo {
5+
SG_MIN = 60,
6+
SG_HORA = 3600,
7+
HORAS_DIA = 24,
8+
SG_DIA = 86400
9+
}

dist/constants.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
/**
4+
* Constantes de tiempo
5+
*/
6+
var Tiempo;
7+
(function (Tiempo) {
8+
Tiempo[Tiempo["SG_MIN"] = 60] = "SG_MIN";
9+
Tiempo[Tiempo["SG_HORA"] = 3600] = "SG_HORA";
10+
Tiempo[Tiempo["HORAS_DIA"] = 24] = "HORAS_DIA";
11+
Tiempo[Tiempo["SG_DIA"] = 86400] = "SG_DIA";
12+
})(Tiempo = exports.Tiempo || (exports.Tiempo = {}));

dist/contador.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Cuenta de manera ascendente de 1 en 1
3+
*/
4+
export declare class Contador {
5+
/**
6+
* @ignore
7+
*/
8+
valorLImite: number;
9+
/**
10+
* @ignore
11+
*/
12+
constructor(limite?: number);
13+
/**
14+
* CUenta de 0 hasta el límite establecido
15+
*/
16+
start(): import("../../../../../../../../Volumes/DATA/Udemy/Proyects/NPM-Projects-Course/nodets/proyecto-2c-crono/node_modules/rxjs/internal/Observable").Observable<string>;
17+
}

dist/contador.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const interval_1 = require("rxjs/internal/observable/interval");
4+
const map_1 = require("rxjs/internal/operators/map");
5+
const conversion_1 = require("./conversion");
6+
/**
7+
* Cuenta de manera ascendente de 1 en 1
8+
*/
9+
class Contador {
10+
/**
11+
* @ignore
12+
*/
13+
constructor(limite = 5) {
14+
/**
15+
* @ignore
16+
*/
17+
this.valorLImite = -1;
18+
this.valorLImite = limite;
19+
}
20+
/**
21+
* CUenta de 0 hasta el límite establecido
22+
*/
23+
start() {
24+
return interval_1.interval(1000).pipe(map_1.map((sg) => {
25+
return conversion_1.convertirSgAFormatoReloj(sg, 1, this.valorLImite);
26+
}));
27+
}
28+
}
29+
exports.Contador = Contador;

dist/conversion.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Convierte los segundos en HH:MM:SS
3+
* @param sg Segundos del momento
4+
* @param tipo 1: COntador / 2: Descontador
5+
* @param limite Valor limite hasta el momento que funcionará
6+
*/
7+
export declare function convertirSgAFormatoReloj(sg: number, tipo: number, limite: number): string;

dist/conversion.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const constants_1 = require("./constants");
4+
/**
5+
* Convierte los segundos en HH:MM:SS
6+
* @param sg Segundos del momento
7+
* @param tipo 1: COntador / 2: Descontador
8+
* @param limite Valor limite hasta el momento que funcionará
9+
*/
10+
function convertirSgAFormatoReloj(sg, tipo, limite) {
11+
if (tipo === 1 && limite === sg || tipo === 2 && sg === 0) {
12+
return 'FINISH';
13+
}
14+
// COnseguir el tiempo formateado para devolverlo
15+
// Horas
16+
const horas = Math.floor((sg % constants_1.Tiempo.SG_DIA) / constants_1.Tiempo.SG_HORA);
17+
// Minutos
18+
const minutos = Math.floor((sg % constants_1.Tiempo.SG_HORA) / constants_1.Tiempo.SG_MIN);
19+
// segundos
20+
const sgs = Math.floor((sg % constants_1.Tiempo.SG_MIN));
21+
return adaptarAlReloj(horas, minutos, sgs);
22+
}
23+
exports.convertirSgAFormatoReloj = convertirSgAFormatoReloj;
24+
/**
25+
* @ignore
26+
*/
27+
function adaptarAlReloj(horas, minutos, sg) {
28+
const h = darNumeroFormatoCorrecto(horas);
29+
const m = darNumeroFormatoCorrecto(minutos);
30+
const s = darNumeroFormatoCorrecto(sg);
31+
return `${h}:${m}:${s}`;
32+
}
33+
/**
34+
* @ignore
35+
*/
36+
function darNumeroFormatoCorrecto(n) {
37+
return (n < 10) ? '0'.concat(String(n)) : String(n);
38+
}

dist/descontador.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Descuenta de uno en uno desde el valor establecido hasta 0
3+
*/
4+
export declare class Descontador {
5+
/**
6+
* @ignore
7+
*/
8+
valorInicial: number;
9+
/**
10+
* @ignore
11+
*/
12+
constructor(valor?: number);
13+
/**
14+
* Va descontando del valor inicial introducido hasta 0
15+
*/
16+
start(): import("../../../../../../../../Volumes/DATA/Udemy/Proyects/NPM-Projects-Course/nodets/proyecto-2c-crono/node_modules/rxjs/internal/Observable").Observable<string>;
17+
}

0 commit comments

Comments
 (0)