How to use assert-js - 10 common examples

To help you get started, we’ve selected a few assert-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github norberttech / no-game / nodejs / client / src / NoGame / Client / UserInterface / Chat.js View on Github external
addMessage(time, username, message)
    {
        Assert.instanceOf(time, Date);
        Assert.string(username);
        Assert.string(message);

        let msgElement = this._doc.createElement('div');
        msgElement.classList.add('message');

        msgElement.innerHTML = MESSAGE_TEMPLATE
            .replace(
                '__TIME__',
                this._format(time.getHours(), 2) + ':' + this._format(time.getMinutes(), 2) + ':' + this._format(time.getSeconds(), 2)
            ).replace('__USERNAME__', username)
            .replace('__MESSAGE__', message);

        this._packet.appendChild(msgElement);
        this._chatContainer.scrollTop = this._chatContainer.scrollHeight;

    }
github norberttech / no-game / nodejs / server / src / NoGame / Server / Broadcaster.js View on Github external
getConnection(playerId)
    {
        Assert.string(playerId);

        for (let connection of this._connections.values()) {
            if (connection.hasPlayerId && connection.playerId === playerId) {
                return connection;
            }
        }

        throw `Can't find connection for player with id ${playerId}`;
    }
github norberttech / no-game / nodejs / server / src / NoGame / Engine / Map / Area.js View on Github external
getPlayer(playerId)
    {
        Assert.string(playerId);

        if (!this._characters.has(playerId)) {
            throw new Error(`Player with id ${playerId} does not exists.`);
        }

        return this._characters.get(playerId);
    }
github norberttech / no-game / nodejs / server / src / NoGame / Server / Broadcaster.js View on Github external
removeConnection(id)
    {
        Assert.string(id);

        this._connections.delete(id);
    }
github norberttech / no-game / nodejs / client / src / NoGame / Client / Player.js View on Github external
attack(characterId)
    {
        Assert.string(characterId);

        this._targetId = characterId;
    }
github norberttech / no-game / nodejs / client / src / NoGame / Client / Kernel.js View on Github external
constructor(gfxEngine, pathFinder)
    {
        Assert.instanceOf(gfxEngine, Engine);
        Assert.instanceOf(pathFinder, PathFinder);

        this._gfxEngine = gfxEngine;
        this._pathFinder = pathFinder;
        this._version = '1.0.0-DEV';
        this._resetState();
    }
github norberttech / no-game / nodejs / server / src / NoGame / Engine / Map / Area / Tile.js View on Github external
constructor(position, ground, tileLayers, moveSpeedModifier = 0)
    {
        Assert.instanceOf(position, Position);
        Assert.instanceOf(ground, Item);
        Assert.instanceOf(tileLayers, TileLayers);
        Assert.integer(moveSpeedModifier);

        this._position = position;
        this._ground = ground;
        this._tileLayers = tileLayers;
        this._moveSpeedModifier = moveSpeedModifier;
        this._characters = new Map();
        this._monster = null;
    }
github norberttech / no-game / nodejs / server / src / NoGame / Engine / Map / Area / Tile.js View on Github external
constructor(position, ground, tileLayers, moveSpeedModifier = 0)
    {
        Assert.instanceOf(position, Position);
        Assert.instanceOf(ground, Item);
        Assert.instanceOf(tileLayers, TileLayers);
        Assert.integer(moveSpeedModifier);

        this._position = position;
        this._ground = ground;
        this._tileLayers = tileLayers;
        this._moveSpeedModifier = moveSpeedModifier;
        this._characters = new Map();
        this._monster = null;
    }
github norberttech / no-game / nodejs / client / src / NoGame / Client / Gfx / CharacterUI.js View on Github external
constructor(character)
    {
        Assert.instanceOf(character, Character);

        this._character = character;
        this._incomeMessages = [];
    }
github norberttech / no-game / nodejs / server / src / NoGame / Server / Protocol.js View on Github external
constructor(kernel, accounts, characters, incomeMessages, broadcaster, logger)
    {
        Assert.instanceOf(kernel, Kernel);
        Assert.instanceOf(accounts, Accounts);
        Assert.instanceOf(characters, Characters);
        Assert.instanceOf(incomeMessages, IncomeMessageQueue);
        Assert.instanceOf(broadcaster, Broadcaster);

        this._kernel = kernel;
        this._accounts = accounts;
        this._characters = characters;
        this._incomeMessages = incomeMessages;
        this._broadcaster = broadcaster;
        this._logger = logger;
    }

assert-js

Javascript simple assertion library with no dependencies.

MIT
Latest version published 5 years ago

Package Health Score

45 / 100
Full package analysis