open-index/open-npm huggingface dataset:
npm package: @gamestdio/clock
Description: A simple clock/ticker implementation to track elapsed/delta time.
Author: Endel Dreyer
Latest version: 1.1.9

@gamestdio/clock [![Build Status](https://secure.travis-ci.org/gamestdio/clock.js.png?branch=master)](http://travis-ci.org/gamestdio/clock.js)
===

A simple clock/ticker implementation to track delta/elapsed time.

**2kb minified**

API
---

- `new Clock([useInterval=false])`
- `clock.start([useInterval=false])`
- `clock.stop()`
- `clock.tick()`
- `clock.elapsedTime`
- `clock.deltaTime`
- `clock.currentTime`

Usage example
---

There's two ways you can use clock.js: manual or automatic.

**Automatic**

By initializing `Clock` with `true` as the first argument, a interval will be
created, in which `tick()` is called 60 times per second.

```typescript
import * as Clock from '@gamestdio/clock';
let clock = new Clock(true);
```

You can also call `start(true)` to create the interval.

```javascript
import * as Clock from '@gamestdio/clock';
let clock = new Clock();
clock.start(true);
```

**Manual usage**

You call `tick()` manually in your existing loop.

```typescript
import * as Clock from '@gamestdio/clock';
var clock = new Clock();

setInterval(function() {
  clock.tick();
  console.log("Delta time: ", clock.deltaTime);
  console.log("Elapsed time: ", clock.elapsedTime);
  console.log("Current time: ", clock.currentTime);
}, 1000 / 60);
```


License
---

MIT
npm package: @gamestdio/easing
Description: Collection of easing equations for JavaScript / TypeScript
Author: Matt DesLauriers
Latest version: 1.0.0

# @gamestdio/easing

This is a grab-bag of [Robert Penner's easing equations](http://www.robertpenner.com/easing/), most of the code from [glsl-easings](https://www.npmjs.org/package/glsl-easings). Pull requests for optimizations are welcome.

## Usage

[![NPM](https://nodei.co/npm/@gamestdio/easing.png)](https://nodei.co/npm/@gamestdio/easing/)

Each easing has its own file which can be required individually. The entry point also exports all eases with camelCase, so `require('eases/expo-in-out')` becomes `require('eases').expoInOut`.

Full list of eases:

```js
import { backInOut } from './back-in-out';
import { backIn } from './back-in';
import { backOut } from './back-out';
import { bounceInOut } from './bounce-in-out';
import { bounceIn } from './bounce-in';
import { bounceOut } from './bounce-out';
import { circInOut } from './circ-in-out';
import { circIn } from './circ-in';
import { circOut } from './circ-out';
import { cubicInOut } from './cubic-in-out';
import { cubicIn } from './cubic-in';
import { cubicOut } from './cubic-out';
import { elasticInOut } from './elastic-in-out';
import { elasticIn } from './elastic-in';
import { elasticOut } from './elastic-out';
import { expoInOut } from './expo-in-out';
import { expoIn } from './expo-in';
import { expoOut } from './expo-out';
import { linear } from './linear';
import { quadInOut } from './quad-in-out';
import { quadIn } from './quad-in';
import { quadOut } from './quad-out';
import { quartInOut } from './quart-in-out';
import { quartIn } from './quart-in';
import { quartOut } from './quart-out';
import { quintInOut } from './quint-in-out';
import { quintIn } from './quint-in';
import { quintOut } from './quint-out';
import { sineInOut } from './sine-in-out';
import { sineIn } from './sine-in';
import { sineOut } from './sine-out';
```

All easing functions only remap a time value, and all have the same signature.

#### ```v = ease(t)```

Where `t` is typically a value between 0 and 1, and it returns a new float that has been eased.

## License

MIT, see [LICENSE.md](http://github.com/mattdesl/eases/blob/master/LICENSE.md) for details.
npm package: @gamestdio/keycode
Description: Use human key names instead of keycode numbers for your keyboard bindings.
Author: Endel Dreyer
Latest version: 2.0.0

# @gamestdio/keycode

Use human key names instead of keycode numbers for your keyboard bindings.

**1.7kb minified**

## Warning

The [`which`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/which) and [`keyCode`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode) properties are in the process of being deprecated by the browsers.

After mainstream adoption, you would rather use the new [`key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) or [`code`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code) attributes in `KeyboardEvent`.

By the time of this writing, IE/Edge still doesn't support the new `KeyboardEvent.key` / `KeyboardEvent.code` API. See: https://caniuse.com/#feat=keyboardevent-code

## Usage example

```typescript
import Keycode from "@gamestdio/keycode";

document.addEventListener('keyup', function(e) {
  if (e.which == Keycode.ENTER) {
    console.log("User pressed ENTER key")
  }
})
```

## License

MIT
npm package: @gamestdio/leaderboard
Description: Minimalist Leaderboard Module for Node.js using MongoDB.
Author: Endel Dreyer
Latest version: 0.1.7

# @gamestdio/leaderboard

Minimalist Leaderboard Module for Node.js using MongoDB.

This module uses [MongoDB's TTL feature](https://docs.mongodb.com/manual/tutorial/expire-data/) in order to avoid maintenance of leaderboard records.

*Note: It would be nice to have support for multiple databases, such as MySQL, Postgres, etc. Pull-requests are welcome!*

## Usage

### Installation

```
npm install mongodb
npm install @gamestdio/leaderboard
```

### Import and set up

```typescript
import { MongoClient } from "mongodb";
import { Leaderboard } from "@gamestdio/leaderboard";

// Setup your MongoDB connection.
const client = new MongoClient("mongodb://...");
const db = client.db("your_database");

// Initialize the leaderboard.
const leaderboard = new Leaderboard(db);
```

### Creating a leaderboard

You may have as many leaderboards as you'd like to.

```typescript
// creating a daily leaderboard (records are removed after 24h)
leaderboard.create("day", { ttl: 1 * 60 * 60 * 24 });

// creating a daily leaderboard (records are removed after 7 days)
leaderboard.create("week", { ttl: 1 * 60 * 60 * 24 * 7 });

// creating a montly leaderboard (records are removed after 30 days)
leaderboard.create("month", { ttl: 1 * 60 * 60 * 24 * 30 });
```

### Inserting scores into the leaderboard

```typescript
leaderboard.store("day", { id: "unique user id here", score: 50 });
```

### Querying for scores

```typescript
leaderboard.list("day").then((rows) => {
    console.log(rows);
});
```

### Getting exact position of player

```typescript
leaderboard.position("day", "unique user id here").then((position) => {
    console.log(position) // => 1 ~ 9999...
});
```

### Get scores surrounding player

```typescript
leaderboard.surrounding("day", "unique user id here", { limit: 3 }).then((scores) => {
    console.log(scores) ; /* => [
        { id: 'player7', score: 60, createdAt: 2018-05-04T02:54:55.836Z },
        { id: 'player3', score: 50, createdAt: 2018-05-04T02:54:55.825Z },
        { id: 'player2', score: 30, createdAt: 2018-05-04T02:54:55.824Z },
        { id: 'unique user id here', score: 25, createdAt: 2018-05-04T02:54:55.826Z },
        { id: 'player1', score: 10, createdAt: 2018-05-04T02:54:55.823Z },
        { id: 'player6', score: 3, createdAt: 2018-05-04T02:54:55.828Z },
        { id: 'player5', score: 1, createdAt: 2018-05-04T02:54:55.827Z }
    ]*/
}),
```


## License

MIT
npm package: @gamestdio/mathf
Description: A collection of common math functions.
Author: Endel Dreyer
Latest version: 1.0.1

# @gamestdio/mathf

A collection of common math functions for JavaScript/TypeScript.

## Installation

```
npm install @gamestdio/mathf
```

## Usage

```typescript
import { lerpAngle, rad2Deg } from "@gamestdio/mathf";

let targetAngle = Math.PI * rad2Deg;
sprite.rotation = lerpAngle(sprite.rotation, targetAngle, 0.1);
```

## References
- https://github.com/likerRr/mathf-js
- https://docs.unity3d.com/ScriptReference/Mathf.html

## License

MIT
npm package: @gamestdio/playing-cards
Description: Data structures and algorithms for playing card games.
Author: Endel Dreyer
Latest version: 0.1.0

<div align="center">
    <img src="header.png?raw=true" />
    <h2>Data structures and algorithms for playing card games.</h2>
</div>

### Installation:

```
npm install @gamestdio/playing-cards
```

### API

```typescript
import { Deck, Suite } from "@gamestdio/playing-cards";

const deck = new Deck({
    suites: [Suite.Diamonds, Suite.Hearts, Suite.Spades, Suite.Clubs]
    jokers: 4,
    shuffle: false
});

console.log(deck.cards);
```

## License

MIT
npm package: @gamestdio/scorm
Description: SCORM 1.2/2004 Wrapper for JavaScript/TypeScript
Author: Endel Dreyer
Latest version: 0.1.3

# @gamestdio/scorm

> SCORM 1.2/2004 Wrapper for JavaScript/TypeScript

Integrate your e-learning course with SCORM 1.2/2004 LMS.

This implementation is highly based on a battle tested version from
[pipwerks/scorm-api-wrapper](https://github.com/pipwerks/scorm-api-wrapper).

## Why?

No SCORM wrapper had support for modern JavaScript/TypeScript.

## Usage

```typescript
import { scorm } from "@gamestdio/scorm";

// initialize connection with parent/opener windows
scorm.initialize();

scorm.set('cmi.core.lesson_status', 'Not Attempted');
scorm.commit();

// finish e-learning session
scorm.terminate();
```

## Testing

1. Create a free account on [SCORM Cloud](https://cloud.scorm.com)
2. Download and include one of the [XML Schema Definition files](https://scorm.com/scorm-explained/technical-scorm/content-packaging/xml-schema-definition-files/) into your package.
3. Edit the `imsmanifest.xml` to meet your needs.
4. Upload your e-learning course to SCORM Cloud.

## References

- [SCORM 1.2 Run-Time Environment](http://xml.coverpages.org/SCORM-12-RunTimeEnv.pdf)
- [SCORM 2004 Guide for Programmers](https://www.adlnet.gov/public/uploads/SCORM_Users_Guide_for_Programmers.pdf)
- [Wikipedia: Sharable_Content_Object_Reference_Model](https://en.wikipedia.org/wiki/Sharable_Content_Object_Reference_Model)

## License

MIT
npm package: @gamestdio/signals
Description: Minimal Signal implementation for JavaScript.
Author: Endel Dreyer
Latest version: 1.0.0

# @gamestdio/signals

Light-weight, strongly-typed messaging system.

## Usage

```typescript
import { Signal } from "@gamestdio/signals";

let signal = new Signal();

signal.add((data) => {
    console.log(data.message);
});

signal.dispatch({ message: "hello signal!" });
```

## License

[MIT](LICENSE)
npm package: @gamestdio/state-listener
Description: Deeply compare JavaScript objects and listen to changes.
Author: Endel Dreyer
Latest version: 3.1.0

# @gamestdio/state-listener [![Build status](https://travis-ci.org/gamestdio/state-listener.svg?branch=master)](https://travis-ci.org/gamestdio/state-listener)

> Deeply compare JavaScript objects and listen to changes. Used in
[colyseus.js](http://github.com/gamestdio/colyseus.js)

[![Sauce Test Status](https://saucelabs.com/browser-matrix/deltalistener.svg)](https://saucelabs.com/u/deltalistener)

## Usage

This library is meant for listening to changes in a JavaScript object.

```typescript
import { StateContainer } from "@gamestdio/state-listener"

// Create the container instance.
let container = new StateContainer({
    entities: {
        one: { x: 10, y: 10 }
    }
});
```

### Listening to changes

```typescript
container.listen("entities/:id/:attribute", (change: DataChange) => {
    console.log(change.path.id, change.path.attribute, change.operation, change.value);
});

// Setting new data into the container will trigger the matching listeners
container.set({ entities: { one: { x: 20 } } });

// Console output
// => "one", "x", "replace", 20
// => "one", "y", "remove", undefined
```

On this example, two properties has been changed (`"entities/one/x"`, and
`"entities/one/y"`). Thus, the callback will be triggered twice.

### Fallback listener

You can use a fallback listener when you're not sure how exactly the change will
come. Useful during development process.

Please note that `change.path` in the fallback listener will be an array
containing the full path to the property that has changed.

```typescript
container.listen((change: DataChange) => {
    console.log(change.path, change.operation, change.value);
})

// Setting new data into the container will trigger the matching listeners
container.set({ entities: { one: { x: 20 } } });

// Console output
// => ["entities", "one", "x"], "replace", 20
// => ["entities", "one", "y"], "remove", undefined
```

See [tests](test/delta_test.ts) for more usage examples.

Registering custom placeholders
---

Registering the placeholder:

```typescript
container.registerPlaceholder(":xyz", /([xyz])/);
```

Using the matcher:

```typescript
container.listen("entity/:id/:xyz", (change: DataChange) => {
    myEntities[ change.path.id ][ change.path.xyz ] = change.value;
});
```

Built-in placeholders
---

- `:id`: `/([a-zA-Z0-9\-_]+)/`
- `:number`: `/([0-9]+)/`
- `:string`: `/(\w+)/`
- `:axis`: `/^([xyz])$/`
- `:*`: `/(.*)/`

When any other name is used starting with `:` (e.g. `:example`), `*` will be
used by default.

Inspiration
---

The [`compare`](src/compare.ts) method is highly based on
[fast-json-patch](https://github.com/Starcounter-Jack/JSON-Patch/)
implementation.

License
---

MIT
npm package: @gamestdio/timeline
Description: Timelines implementation for lag compensation techniques in networked games.
Author: Endel Dreyer
Latest version: 0.3.5

@gamestdio/timeline [![Build Status](https://secure.travis-ci.org/gamestdio/timeline.png?branch=master)](http://travis-ci.org/gamestdio/timeline)
===

[![Greenkeeper badge](https://badges.greenkeeper.io/gamestdio/timeline.svg)](https://greenkeeper.io/)

Timelines implementation for lag compensation techniques in networked games.
Use it both on server and/or client-side according to your needs.

- Take snapshots of game state
- Interpolates and extrapolates values based on snapshots taken.

API
---

- `createTimeline([ maxSnapshots=10 ])` - Create a Timeline instance
- `Timeline#takeSnapshot( state[, elapsedMs ] )` - Record state on timeline history
- `Timeline#at( elapsedMs[, interpolate=true ] )` - Get `Proxy` object containing interpolated values between recorded states.
- `Timeline#offset( elapsedMs[, interpolate=true ] )` - Same as `#at`, but from the last snapshot taken.

Example
---

```javascript
import { createTimeline } from '@gamestdio/timeline'

var timeline = createTimeline()

// first game state snapshot
timeline.takeSnapshot({
  player: { x: 100 },
  enemy: { x: 0 }
})

setTimeout(() => {
  // take second game state snapshot after 1000ms

  timeline.takeSnapshot({
    player: { x: 0 },
    enemy: { x: 100 }
  })

  //
  // Retrieving a previous state
  //
  console.log( timeline.at( 0 ).player.x )
  // => 100
  console.log( timeline.at( 0 ).enemy.x )
  // => 0

  //
  // Interpolating data from known states
  //
  console.log( timeline.at( 500 ).player.x )
  // => 49.75124378109453
  console.log( timeline.at( 500 ).enemy.x )
  // => 50.24875621890547

  //
  // Extrapolating data between an unknown state
  //
  console.log( timeline.at( 1500 ).player.x )
  // => -49.25373134328358
  console.log( timeline.at( 1500 ).enemy.x )
  // => 149.2537313432836

}, 1000)
```

To execute this example run the following command:

```
node --harmony --harmony-proxies example/usage.js
```

References
---

- [Timelines: simplifying the programming of lag compensation for the next generation of networked games](http://link.springer.com/article/10.1007/s00530-012-0271-3#Sec17)

License
---

MIT
npm package: @gamestdio/timer
Description: Timing Events tied to @gamestdio/clock
Author: Endel Dreyer
Latest version: 1.4.2

# @gamestdio/timer

Timing Events tied to [colyseus/clock](https://github.com/colyseus/clock).

`ClockTimer` is a subclass of `Clock`, which adds methods to handle timeout and
intervals relying on `Clock`'s ticks.

## Why?

Once built-in `setTimeout` and `setInterval` relies on CPU load, functions may
delay an unexpected amount of time to execute. Having it tied to a clock's time
is guaranteed to execute in a precise way.

Therefore there is ideally one single CPU clock for all the timers and then they are executed in sequence.

See a quote from [W3C Timers Specification](http://www.w3.org/TR/2011/WD-html5-20110525/timers.html):

> This API does not guarantee that timers will fire exactly on schedule. Delays
> due to CPU load, other tasks, etc, are to be expected.

It does however guarantees an order of « does this timer should execute based on elapsed time since last tick call ? » based on when they were registered.

In classic timer if we have a `setInterval` of `0`ms it will fill the event loop timer queue with callbacks (like A LOT) and if we have another of `1000`ms interval it will be executed only after many of the `0`ms callbacks are executed. This is not the case with `ClockTimer`, as it loops through all timers and checks if they should be executed there are more chance that the `1000`ms callback will be executed in time.

You can also call `.tick()` manually to check all the timers at once on a specific important time.

Other cool stuff is that you manage all your timers in one place and therefore you can clear all of them at once. This is useful for example when you want to clear all timers when a game is over. Or when using those is irrelevant.

## API

**Clock**

- `setInterval(handler, time, ...args)` -> `Delayed`
- `setTimeout(handler, time, ...args)` -> `Delayed`
- `duration(ms: number)` -> `Promise<void>` - Convenience method to wait for a duration in async functions or promises. See associated JSdoc for more details.
- `clear()` - clear all intervals and timeouts, and throw any promise created with `duration`.

**Delayed**

- `clear()` -> `void` - Clear timeout/interval
- `reset()` -> `void` - Reset elapsed time
- `active` -> `Boolean` - Is it still active?
- `pause()` -> `void` - Pause the execution
- `resume()` -> `void` - Continue the execution
- `paused` -> `Boolean` - Is is paused?

## License

MIT