Skip to content

Commit

Permalink
Convert to typescript (#7)
Browse files Browse the repository at this point in the history
* convert to typescript

* Improve build options to check strictly

* Remove unnecessary build options
  • Loading branch information
shisama committed Mar 24, 2019
1 parent 28f18c2 commit 557fcef
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .npmignore
Expand Up @@ -2,5 +2,7 @@
.cache
capture
demo
src
.gitignore
renovate.json
renovate.json
tsconfig.json
11 changes: 6 additions & 5 deletions demo/demo.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions demo/demo.bundle.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion demo/demo.js
@@ -1,4 +1,4 @@
import Pulsator from "../pulsator.js";
import Pulsator from "../lib/pulsator.js";

const options = {
width: "20px",
Expand Down
10 changes: 10 additions & 0 deletions lib/pulsator.d.ts
@@ -0,0 +1,10 @@
export default class Pulsator {
private element;
private animation;
constructor(parent: Element, options: unknown);
start(): void;
stop(): void;
pause(): void;
reverse(): void;
getElement(): HTMLElement;
}
47 changes: 47 additions & 0 deletions lib/pulsator.js
@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Pulsator = /** @class */ (function () {
function Pulsator(parent, options) {
this.element = document.createElement("div");
parent.appendChild(this.element);
var style = {
display: "none",
width: "15px",
height: "15px",
borderRadius: "50%",
borderColor: "red",
background: "red",
boxShadow: "0 0 0 rgba(255,0,0, 0.4)"
};
Object.assign(this.element.style, style, options);
this.animation = this.element.animate({
"boxShadow": [
"0 0 0 0 rgba(255,0,0, 1)",
"0 0 0 20px rgba(255,0,0, 0)"
]
}, {
duration: 1500,
iterations: Infinity
});
this.animation.cancel();
}
Pulsator.prototype.start = function () {
this.element.style.display = "block";
this.animation.play();
};
Pulsator.prototype.stop = function () {
this.animation.cancel();
this.element.style.display = "none";
};
Pulsator.prototype.pause = function () {
this.animation.pause();
};
Pulsator.prototype.reverse = function () {
this.animation.reverse();
};
Pulsator.prototype.getElement = function () {
return this.element;
};
return Pulsator;
}());
exports.default = Pulsator;
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions package.json
Expand Up @@ -2,10 +2,13 @@
"name": "pulsator",
"version": "0.2.1",
"description": "Pulse animation with JavaScript.",
"main": "pulsator.js",
"main": "lib/pulsator.js",
"types": "lib/pulsator.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build:demo": "parcel build demo/demo.js -d demo -o demo.bundle.js"
"build": "rimraf lib && tsc",
"build:demo": "parcel build demo/demo.js -d demo -o demo.bundle.js",
"build:all": "npm run build && npm run build:demo"
},
"repository": {
"type": "git",
Expand All @@ -23,6 +26,8 @@
},
"homepage": "https://github.com/shisama/Pulsator-JS#readme",
"devDependencies": {
"parcel-bundler": "^1.12.3"
"parcel-bundler": "^1.12.3",
"rimraf": "^2.6.3",
"typescript": "^3.3.4000"
}
}
11 changes: 8 additions & 3 deletions pulsator.js → src/pulsator.ts
@@ -1,5 +1,7 @@
export default class Pulsator {
constructor(parent, options) {
private element: HTMLElement;
private animation: Animation;
constructor(parent: Element, options: unknown) {
this.element = document.createElement("div");
parent.appendChild(this.element);
const style = {
Expand All @@ -15,10 +17,13 @@ export default class Pulsator {


this.animation = this.element.animate({
boxShadow: ["0 0 0 0 rgba(255,0,0, 1)", "0 0 0 20px rgba(255,0,0, 0)"]
"boxShadow": [
"0 0 0 0 rgba(255,0,0, 1)",
"0 0 0 20px rgba(255,0,0, 0)"
]
}, {
duration: 1500,
iterations: "Infinity"
iterations: Infinity
});
this.animation.cancel();
}
Expand Down
60 changes: 60 additions & 0 deletions tsconfig.json
@@ -0,0 +1,60 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["dom", "es2018"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": true, /* Enable strict null checks. */
"strictFunctionTypes": true, /* Enable strict checking of function types. */
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
"noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}
}

0 comments on commit 557fcef

Please sign in to comment.