├── src ├── include.js ├── utility │ ├── index.ts │ ├── hasClass.ts │ └── query.ts ├── event │ ├── index.ts │ ├── direct.ts │ ├── delegate.ts │ └── registry.ts └── index.ts ├── .gitignore ├── dist ├── utility │ ├── index.d.ts │ ├── hasClass.d.ts │ ├── query.d.ts │ ├── index.js │ ├── hasClass.js │ └── query.js ├── event │ ├── direct.d.ts │ ├── delegate.d.ts │ ├── index.d.ts │ ├── index.js │ ├── direct.js │ ├── registry.d.ts │ ├── delegate.js │ └── registry.js ├── index.d.ts ├── tsdom.inc.js ├── index.js └── tsdom.inc.js.map ├── .prettierrc.json ├── tsconfig.json ├── tasks ├── config.js ├── error.js ├── js-lint.js ├── js-module.js └── js-include.js ├── gulpfile.js ├── tests └── index.spec.ts ├── LICENSE ├── package.json ├── README.md └── tslint.json /src/include.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./index').default; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | node_modules/** 3 | npm-debug* 4 | index.html 5 | -------------------------------------------------------------------------------- /src/utility/index.ts: -------------------------------------------------------------------------------- 1 | export * from './query'; 2 | export * from './hasClass'; 3 | -------------------------------------------------------------------------------- /dist/utility/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './query'; 2 | export * from './hasClass'; 3 | -------------------------------------------------------------------------------- /dist/utility/hasClass.d.ts: -------------------------------------------------------------------------------- 1 | declare function hasClass(el: HTMLElement, str: string): boolean; 2 | export { hasClass }; 3 | -------------------------------------------------------------------------------- /dist/event/direct.d.ts: -------------------------------------------------------------------------------- 1 | declare function direct(cb: (ev: Event, el: HTMLElement) => void): (ev: Event) => void; 2 | export { direct }; 3 | -------------------------------------------------------------------------------- /dist/event/delegate.d.ts: -------------------------------------------------------------------------------- 1 | declare function delegate(scope: HTMLElement, query: string, cb: (ev: Event, el: HTMLElement) => void): (ev: Event) => void; 2 | export { delegate }; 3 | -------------------------------------------------------------------------------- /dist/utility/query.d.ts: -------------------------------------------------------------------------------- 1 | declare function query(qry: string, ctx: Element | Document): HTMLElement | HTMLCollectionOf | NodeListOf; 2 | export { query }; 3 | -------------------------------------------------------------------------------- /dist/event/index.d.ts: -------------------------------------------------------------------------------- 1 | import { registry } from './registry'; 2 | import { direct } from './direct'; 3 | import { delegate } from './delegate'; 4 | export { registry, direct, delegate }; 5 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 3, 4 | "semi": true, 5 | "singleQuote": true, 6 | "eslintIntegration": false, 7 | "tslintIntegration": true 8 | } 9 | -------------------------------------------------------------------------------- /dist/utility/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function __export(m) { 3 | for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; 4 | } 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | __export(require("./query")); 7 | __export(require("./hasClass")); 8 | -------------------------------------------------------------------------------- /src/event/index.ts: -------------------------------------------------------------------------------- 1 | import { registry } from './registry'; 2 | import { direct } from './direct'; 3 | import { delegate } from './delegate'; 4 | 5 | /* ----------------------------------- 6 | * 7 | * Events 8 | * 9 | * -------------------------------- */ 10 | 11 | export { registry, direct, delegate }; 12 | -------------------------------------------------------------------------------- /dist/event/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var registry_1 = require("./registry"); 4 | exports.registry = registry_1.registry; 5 | var direct_1 = require("./direct"); 6 | exports.direct = direct_1.direct; 7 | var delegate_1 = require("./delegate"); 8 | exports.delegate = delegate_1.delegate; 9 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "dist", 4 | "noImplicitAny": true, 5 | "target": "es5", 6 | "declaration": true, 7 | "sourceMap": true, 8 | "inlineSourceMap": false, 9 | "inlineSources": false, 10 | "lib": [ 11 | "dom", 12 | "es5", 13 | "es6" 14 | ] 15 | } 16 | } -------------------------------------------------------------------------------- /dist/event/direct.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /* ----------------------------------- 3 | * 4 | * Direct 5 | * 6 | * -------------------------------- */ 7 | Object.defineProperty(exports, "__esModule", { value: true }); 8 | function direct(cb) { 9 | return function (ev) { 10 | var el = ev.currentTarget; 11 | cb(ev, el); 12 | }; 13 | } 14 | exports.direct = direct; 15 | -------------------------------------------------------------------------------- /tasks/config.js: -------------------------------------------------------------------------------- 1 | /* ----------------------------------- 2 | * 3 | * Config 4 | * 5 | * -------------------------------- */ 6 | 7 | module.exports = { 8 | path: { 9 | root: './', 10 | dist: './dist/', 11 | src: './src/', 12 | tests: './tests/', 13 | }, 14 | 15 | uglify: { 16 | compress: { 17 | dead_code: true, 18 | unused: true, 19 | }, 20 | }, 21 | }; 22 | -------------------------------------------------------------------------------- /tasks/error.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | const log = require('fancy-log'); 3 | 4 | /* ----------------------------------- 5 | * 6 | * Error 7 | * 8 | * -------------------------------- */ 9 | 10 | module.exports = function(err) { 11 | const name = chalk.red(err.name + ':'); 12 | const message = err.message; 13 | const output = chalk.yellow(message.replace(/\n|\r/g, '')); 14 | 15 | log(name); 16 | log(output); 17 | }; 18 | -------------------------------------------------------------------------------- /dist/event/registry.d.ts: -------------------------------------------------------------------------------- 1 | export declare type IEvents = Registry; 2 | export interface IEvent { 3 | type: string; 4 | handler: EventListener; 5 | } 6 | export declare type IHandler = (ev: Event, el: HTMLElement) => void; 7 | export declare class Registry { 8 | private list; 9 | constructor(); 10 | find(ev: string): IEvent[]; 11 | add(ev: IEvent): void; 12 | remove(ev: string): void; 13 | } 14 | declare function registry(): Registry; 15 | export { registry }; 16 | -------------------------------------------------------------------------------- /src/event/direct.ts: -------------------------------------------------------------------------------- 1 | /* ----------------------------------- 2 | * 3 | * Direct 4 | * 5 | * -------------------------------- */ 6 | 7 | function direct(cb: (ev: Event, el: HTMLElement) => void) { 8 | return (ev: Event) => { 9 | const el = ev.currentTarget as HTMLElement; 10 | 11 | cb(ev, el); 12 | }; 13 | } 14 | 15 | /* ----------------------------------- 16 | * 17 | * Export 18 | * 19 | * -------------------------------- */ 20 | 21 | export { direct }; 22 | -------------------------------------------------------------------------------- /dist/utility/hasClass.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /* ----------------------------------- 3 | * 4 | * hasClass 5 | * 6 | * -------------------------------- */ 7 | Object.defineProperty(exports, "__esModule", { value: true }); 8 | function hasClass(el, str) { 9 | var result = false; 10 | var value = " " + str + " "; 11 | var clean = (" " + el.className + " ").replace(/[\n\t]/g, ' '); 12 | if (clean.indexOf(value) > -1) { 13 | result = true; 14 | } 15 | return result; 16 | } 17 | exports.hasClass = hasClass; 18 | -------------------------------------------------------------------------------- /src/utility/hasClass.ts: -------------------------------------------------------------------------------- 1 | /* ----------------------------------- 2 | * 3 | * hasClass 4 | * 5 | * -------------------------------- */ 6 | 7 | function hasClass(el: HTMLElement, str: string) { 8 | let result = false; 9 | 10 | const value = ` ${str} `; 11 | const clean = ` ${el.className} `.replace(/[\n\t]/g, ' '); 12 | 13 | if (clean.indexOf(value) > -1) { 14 | result = true; 15 | } 16 | 17 | return result; 18 | } 19 | 20 | /* ----------------------------------- 21 | * 22 | * Export 23 | * 24 | * -------------------------------- */ 25 | 26 | export { hasClass }; 27 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | const gulp = require('gulp'); 2 | const sequence = require('gulp-sequence'); 3 | const config = require('./tasks/config'); 4 | 5 | /* ----------------------------------- 6 | * 7 | * Task 8 | * 9 | * -------------------------------- */ 10 | 11 | function task(task) { 12 | return require('./tasks/' + task)(config, gulp); 13 | } 14 | 15 | /* ----------------------------------- 16 | * 17 | * JS 18 | * 19 | * -------------------------------- */ 20 | 21 | gulp.task('js:module', task('js-module')); 22 | gulp.task('js:include', task('js-include')); 23 | gulp.task('js:lint', task('js-lint')); 24 | 25 | /* ----------------------------------- 26 | * 27 | * Default 28 | * 29 | * -------------------------------- */ 30 | 31 | gulp.task('default', sequence('js:lint', ['js:module', 'js:include'])); 32 | -------------------------------------------------------------------------------- /tests/index.spec.ts: -------------------------------------------------------------------------------- 1 | import 'mocha'; 2 | import * as sinon from 'sinon'; 3 | import { expect } from 'chai'; 4 | 5 | /* ----------------------------------- 6 | * 7 | * Subject 8 | * 9 | * -------------------------------- */ 10 | 11 | import tsdom from '../src/index'; 12 | 13 | /* ----------------------------------- 14 | * 15 | * Tabs 16 | * 17 | * -------------------------------- */ 18 | 19 | describe('tsdom:selector', () => { 20 | let sandbox: sinon.SinonSandbox; 21 | 22 | /* 23 | * ID 24 | */ 25 | describe('(qry = #id)', () => { 26 | beforeEach(() => { 27 | sandbox = sinon.sandbox.create(); 28 | }); 29 | 30 | afterEach(() => { 31 | sandbox.restore(); 32 | }); 33 | 34 | it('calls getElementById() with qry value', () => { 35 | expect(true).to.equal(true); 36 | }); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /dist/utility/query.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /* ----------------------------------- 3 | * 4 | * Variables 5 | * 6 | * -------------------------------- */ 7 | Object.defineProperty(exports, "__esModule", { value: true }); 8 | var regex = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/; 9 | /* ----------------------------------- 10 | * 11 | * Query 12 | * 13 | * -------------------------------- */ 14 | function query(qry, ctx) { 15 | var test; 16 | var match; 17 | if ((test = regex.exec(qry))) { 18 | if ((match = test[3])) { 19 | return ctx.getElementsByClassName(match); 20 | } 21 | if ((match = test[2])) { 22 | return ctx.getElementsByTagName(match); 23 | } 24 | if ((match = test[1])) { 25 | return document.getElementById(match); 26 | } 27 | } 28 | return ctx.querySelectorAll(qry); 29 | } 30 | exports.query = query; 31 | -------------------------------------------------------------------------------- /src/utility/query.ts: -------------------------------------------------------------------------------- 1 | /* ----------------------------------- 2 | * 3 | * Variables 4 | * 5 | * -------------------------------- */ 6 | 7 | const regex = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/; 8 | 9 | /* ----------------------------------- 10 | * 11 | * Query 12 | * 13 | * -------------------------------- */ 14 | 15 | function query(qry: string, ctx: Element | Document) { 16 | let test; 17 | let match; 18 | 19 | if ((test = regex.exec(qry))) { 20 | if ((match = test[3])) { 21 | return ctx.getElementsByClassName(match); 22 | } 23 | 24 | if ((match = test[2])) { 25 | return ctx.getElementsByTagName(match); 26 | } 27 | 28 | if ((match = test[1])) { 29 | return document.getElementById(match); 30 | } 31 | } 32 | 33 | return ctx.querySelectorAll(qry); 34 | } 35 | 36 | /* ----------------------------------- 37 | * 38 | * Export 39 | * 40 | * -------------------------------- */ 41 | 42 | export { query }; 43 | -------------------------------------------------------------------------------- /dist/event/delegate.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var index_1 = require("../index"); 4 | /* ----------------------------------- 5 | * 6 | * Delegate 7 | * 8 | * -------------------------------- */ 9 | function delegate(scope, query, cb) { 10 | return function (ev) { 11 | var $elements = new index_1.Instance(query, scope); 12 | var el = null; 13 | var hit = false; 14 | $elements.each(function (_el) { 15 | var test = ev.target; 16 | if (test === _el) { 17 | hit = true; 18 | el = test; 19 | return; 20 | } 21 | while (test && test !== scope) { 22 | test = test.parentNode; 23 | if (test === _el) { 24 | hit = true; 25 | el = test; 26 | } 27 | } 28 | }); 29 | if (hit) { 30 | cb(ev, el); 31 | } 32 | }; 33 | } 34 | exports.delegate = delegate; 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 James Hill 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/event/delegate.ts: -------------------------------------------------------------------------------- 1 | import { Instance } from '../index'; 2 | 3 | /* ----------------------------------- 4 | * 5 | * Delegate 6 | * 7 | * -------------------------------- */ 8 | 9 | function delegate( 10 | scope: HTMLElement, 11 | query: string, 12 | cb: (ev: Event, el: HTMLElement) => void 13 | ) { 14 | return (ev: Event) => { 15 | const $elements = new Instance(query, scope); 16 | 17 | let el = null; 18 | let hit = false; 19 | 20 | $elements.each(_el => { 21 | let test = ev.target as any; 22 | 23 | if (test === _el) { 24 | hit = true; 25 | el = test; 26 | 27 | return; 28 | } 29 | 30 | while (test && test !== scope) { 31 | test = test.parentNode; 32 | 33 | if (test === _el) { 34 | hit = true; 35 | el = test; 36 | } 37 | } 38 | }); 39 | 40 | if (hit) { 41 | cb(ev, el); 42 | } 43 | }; 44 | } 45 | 46 | /* ----------------------------------- 47 | * 48 | * Export 49 | * 50 | * -------------------------------- */ 51 | 52 | export { delegate }; 53 | -------------------------------------------------------------------------------- /dist/event/registry.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /* ----------------------------------- 3 | * 4 | * IEvents 5 | * 6 | * -------------------------------- */ 7 | Object.defineProperty(exports, "__esModule", { value: true }); 8 | /* ----------------------------------- 9 | * 10 | * Registry 11 | * 12 | * -------------------------------- */ 13 | var Registry = /** @class */ (function () { 14 | function Registry() { 15 | this.list = []; 16 | } 17 | Registry.prototype.find = function (ev) { 18 | var list = this.list; 19 | return list.filter(function (_ev) { return _ev.type === ev; }); 20 | }; 21 | Registry.prototype.add = function (ev) { 22 | this.list.push(ev); 23 | }; 24 | Registry.prototype.remove = function (ev) { 25 | var list = this.list; 26 | this.list = list.filter(function (_ev) { return _ev.type !== ev; }); 27 | }; 28 | return Registry; 29 | }()); 30 | exports.Registry = Registry; 31 | /* ----------------------------------- 32 | * 33 | * Function 34 | * 35 | * -------------------------------- */ 36 | function registry() { 37 | return new Registry(); 38 | } 39 | exports.registry = registry; 40 | -------------------------------------------------------------------------------- /tasks/js-lint.js: -------------------------------------------------------------------------------- 1 | const prettier = require('gulp-prettier-plugin'); 2 | const tslint = require('gulp-tslint'); 3 | const merge = require('merge-stream'); 4 | const error = require('./error'); 5 | 6 | /* ----------------------------------- 7 | * 8 | * Lint 9 | * 10 | * -------------------------------- */ 11 | 12 | module.exports = (config, gulp) => { 13 | const paths = [ 14 | config.path.src + '**/*.ts*', 15 | config.path.tests + '**/*.spec.ts*', 16 | ]; 17 | 18 | return () => { 19 | const format = gulp 20 | .src(paths) 21 | .pipe( 22 | prettier(require('../.prettierrc.json'), { 23 | filter: true, 24 | }) 25 | ) 26 | .pipe(gulp.dest(file => file.base)); 27 | 28 | const linting = gulp 29 | .src(paths) 30 | .pipe( 31 | tslint({ 32 | tslint: require('tslint'), 33 | formatter: 'stylish', 34 | fix: true, 35 | }) 36 | ) 37 | .pipe( 38 | tslint.report({ 39 | summarizeFailureOutput: true, 40 | }) 41 | ); 42 | 43 | return merge(format, linting); 44 | }; 45 | }; 46 | -------------------------------------------------------------------------------- /tasks/js-module.js: -------------------------------------------------------------------------------- 1 | const browserify = require('browserify'); 2 | const tscript = require('gulp-typescript'); 3 | const uglify = require('gulp-uglify'); 4 | const when = require('gulp-if'); 5 | const buffer = require('vinyl-buffer'); 6 | const merge = require('merge2'); 7 | const del = require('del'); 8 | const error = require('./error'); 9 | const project = tscript.createProject('./tsconfig.json'); 10 | 11 | /* ----------------------------------- 12 | * 13 | * Flags 14 | * 15 | * -------------------------------- */ 16 | 17 | const RELEASE = process.argv.includes('--release'); 18 | 19 | /* ----------------------------------- 20 | * 21 | * Main 22 | * 23 | * -------------------------------- */ 24 | 25 | module.exports = function(config, gulp) { 26 | return function() { 27 | return del([config.path.dist + 'tsdom.js*']).then(function() { 28 | const result = gulp.src([config.path.src + '**/*.ts']).pipe(project()); 29 | 30 | return merge([ 31 | result.js 32 | .on('error', error) 33 | .pipe(buffer()) 34 | .pipe(when(RELEASE, uglify(config.uglify))) 35 | .pipe(gulp.dest(config.path.dist)), 36 | result.dts.pipe(gulp.dest(config.path.dist)), 37 | ]); 38 | }); 39 | }; 40 | }; 41 | -------------------------------------------------------------------------------- /tasks/js-include.js: -------------------------------------------------------------------------------- 1 | const browserify = require('browserify'); 2 | const tsify = require('tsify'); 3 | const uglify = require('gulp-uglify'); 4 | const when = require('gulp-if'); 5 | const sourcemaps = require('gulp-sourcemaps'); 6 | const buffer = require('vinyl-buffer'); 7 | const source = require('vinyl-source-stream'); 8 | const del = require('del'); 9 | const error = require('./error'); 10 | 11 | /* ----------------------------------- 12 | * 13 | * Flags 14 | * 15 | * -------------------------------- */ 16 | 17 | const RELEASE = process.argv.includes('--release'); 18 | 19 | /* ----------------------------------- 20 | * 21 | * Include 22 | * 23 | * -------------------------------- */ 24 | 25 | module.exports = function(config, gulp) { 26 | return function() { 27 | return del([config.path.dist + 'tsdom.inc.js*']).then(function() { 28 | return browserify({ 29 | basedir: '.', 30 | debug: true, 31 | standalone: 'tsdom', 32 | entries: [config.path.src + 'include.js'], 33 | cache: {}, 34 | packageCache: {}, 35 | }) 36 | .plugin(tsify) 37 | .bundle() 38 | .on('error', error) 39 | .pipe(source('tsdom.inc.js')) 40 | .pipe(buffer()) 41 | .pipe(when(!RELEASE, sourcemaps.init())) 42 | .pipe(uglify(config.uglify)) 43 | .pipe(when(!RELEASE, sourcemaps.write('./'))) 44 | .pipe(gulp.dest(config.path.dist)); 45 | }); 46 | }; 47 | }; 48 | -------------------------------------------------------------------------------- /src/event/registry.ts: -------------------------------------------------------------------------------- 1 | /* ----------------------------------- 2 | * 3 | * IEvents 4 | * 5 | * -------------------------------- */ 6 | 7 | export type IEvents = Registry; 8 | 9 | /* ----------------------------------- 10 | * 11 | * IEvent 12 | * 13 | * -------------------------------- */ 14 | 15 | export interface IEvent { 16 | type: string; 17 | handler: EventListener; 18 | } 19 | 20 | /* ----------------------------------- 21 | * 22 | * IHandler 23 | * 24 | * -------------------------------- */ 25 | 26 | export type IHandler = (ev: Event, el: HTMLElement) => void; 27 | 28 | /* ----------------------------------- 29 | * 30 | * Registry 31 | * 32 | * -------------------------------- */ 33 | 34 | export class Registry { 35 | private list: IEvent[]; 36 | 37 | public constructor() { 38 | this.list = []; 39 | } 40 | 41 | public find(ev: string) { 42 | const { list } = this; 43 | 44 | return list.filter(_ev => _ev.type === ev); 45 | } 46 | 47 | public add(ev: IEvent) { 48 | this.list.push(ev); 49 | } 50 | 51 | public remove(ev: string) { 52 | const { list } = this; 53 | 54 | this.list = list.filter(_ev => _ev.type !== ev); 55 | } 56 | } 57 | 58 | /* ----------------------------------- 59 | * 60 | * Function 61 | * 62 | * -------------------------------- */ 63 | 64 | function registry() { 65 | return new Registry(); 66 | } 67 | 68 | /* ----------------------------------- 69 | * 70 | * Export 71 | * 72 | * -------------------------------- */ 73 | 74 | export { registry }; 75 | -------------------------------------------------------------------------------- /dist/index.d.ts: -------------------------------------------------------------------------------- 1 | import { IHandler, IEvents } from './event/registry'; 2 | export interface IMeta { 3 | owner?: Instance; 4 | } 5 | export declare class Instance { 6 | [index: number]: HTMLElement; 7 | length: number; 8 | events: IEvents; 9 | private meta; 10 | constructor(qry: string | HTMLElement, ctx?: Element, meta?: IMeta); 11 | get(key: number): HTMLElement; 12 | first(): Instance; 13 | find(qry: string): Instance; 14 | closest(qry: string): Instance; 15 | each(cb: (el: HTMLElement) => void): this; 16 | css(obj: { 17 | [index: string]: string; 18 | }): this; 19 | attr(obj: { 20 | [index: string]: string; 21 | } | string): string; 22 | hasClass(str: string): boolean; 23 | addClass(str: string): this; 24 | removeClass(str: string): this; 25 | toggleClass(str: string): this; 26 | on(ev: string, op1: string | IHandler, op2?: IHandler): this; 27 | off(ev: string): this; 28 | val(val?: string): string; 29 | text(val?: string): string; 30 | data(key: string, val?: string): string; 31 | html(val?: string): string; 32 | append(item: string | Node | HTMLElement): this; 33 | prepend(item: string | Node | HTMLElement): this; 34 | empty(): this; 35 | remove(): void; 36 | toArray(): HTMLElement[]; 37 | } 38 | export declare namespace TSDom { 39 | type Init = (qry: string | HTMLElement, ctx?: Element, meta?: IMeta) => Instance; 40 | class Object extends Instance { 41 | } 42 | } 43 | declare const _default: (qry: string | HTMLElement, ctx?: HTMLElement) => Instance; 44 | export default _default; 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tsdom", 3 | "version": "0.6.9", 4 | "description": "Fast, lightweight JavaScript DOM manipulation utility", 5 | "main": "./dist/index.js", 6 | "types": "./dist/index.d.ts", 7 | "scripts": { 8 | "test": "mocha -r ts-node/register ./tests/**/*.spec.ts" 9 | }, 10 | "keywords": [ 11 | "lightweight", 12 | "fast", 13 | "dom", 14 | "manipulation", 15 | "utility", 16 | "library", 17 | "typescript", 18 | "javascript", 19 | "jhdevuk" 20 | ], 21 | "author": "James Hill", 22 | "license": "MIT", 23 | "repository": { 24 | "type": "git", 25 | "url": "https://github.com/jhdevuk/tsdom" 26 | }, 27 | "devDependencies": { 28 | "@types/chai": "4.1.7", 29 | "@types/mocha": "5.2.5", 30 | "@types/node": "10.12.24", 31 | "@types/sinon": "7.0.5", 32 | "browserify": "16.2.3", 33 | "chai": "4.2.0", 34 | "chalk": "2.4.2", 35 | "del": "3.0.0", 36 | "fancy-log": "1.3.3", 37 | "gulp": "3.9.1", 38 | "gulp-if": "2.0.2", 39 | "gulp-prettier-plugin": "1.3.0", 40 | "gulp-rename": "1.4.0", 41 | "gulp-sequence": "1.0.0", 42 | "gulp-sourcemaps": "2.6.4", 43 | "gulp-tslint": "8.1.3", 44 | "gulp-typescript": "5.0.0", 45 | "gulp-uglify": "3.0.1", 46 | "merge2": "1.2.3", 47 | "mocha": "5.2.0", 48 | "prettier": "1.16.4", 49 | "sinon": "7.2.3", 50 | "ts-node": "8.0.2", 51 | "tsify": "4.0.1", 52 | "tslint": "5.12.1", 53 | "tslint-config-prettier": "1.18.0", 54 | "tslint-eslint-rules": "5.4.0", 55 | "typescript": "3.3.3", 56 | "vinyl-buffer": "1.0.1", 57 | "vinyl-source-stream": "2.0.0" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tsdom 2 | Fast, lightweight DOM manipulation utility with TypeScript definitions. 3 | **1.8kb** gzipped. 4 | ### Install 5 | `npm install --save tsdom` 6 | ### Setup 7 | Add the package to your project using one of the following: 8 | - `let tsdom = require('tsdom')` 9 | - `import tsdom from 'tsdom'` 10 | - `