Giter VIP home page Giter VIP logo

notations's Introduction

Antimatter Dimensions Notations

NPM Codacy Badge

All the notations that are included in the current version of Antimatter Dimensions, and the upcoming Reality Update.

See them in action here.

Setup

CDN

The simplest way to use this package is to include these scripts in your HTML page:

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/break_infinity.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@antimatter-dimensions/notations"></script>

You can also grab specific versions here:

npm

npm install @antimatter-dimensions/notations

There is no default export. The correct way to import notations is:

import * as ADNotations from "@antimatter-dimensions/notations";

Use

All the notations are included inside ADNotations object:

const scientific = new ADNotations.ScientificNotation();

The main method that notations provide is format(value, places, placesUnder1000)

  • value can be Decimal, number or string which you want to format
  • places is used to format mantissa when number is greater than 1000
  • placesUnder1000 is used to format the number when it is lesser than 1000
const scientific = new ADNotations.ScientificNotation();

// Outputs "1000.00"
console.log(scientific.format(1000, 2, 2));
// Outputs "1.00e100"
console.log(scientific.format("1e100", 2, 0));
// Outputs "1e100"
console.log(scientific.format(new Decimal(1e100), 0, 0));

You can configure some formatting aspects via ADNotations.Settings object:

const scientific = new ADNotations.ScientificNotation();

// Outputs "1e100,000"
console.log(scientific.format("1e100000", 2, 2));

// Outputs "1e100000"
ADNotations.Settings.exponentCommas.show = false;
console.log(scientific.format("1e100000", 2, 2));

// Outputs "Infinite"
ADNotations.Settings.isInfinite = decimal => decimal.gte(1e100);
console.log(scientific.format(1e101, 2, 2));

Configuration settings:

  • Settings.isInfinite - function that determines if a Decimal value is infinite (default is decimal => decimal.gte(Decimal.MAX_VALUE))
  • Settings.exponentCommas.show - show commas in formatted output (default is true)
  • Settings.exponentCommas.min - lower bound for exponent to be formatted with commas (default is 100000)
  • Settings.exponentCommas.max - upper bound for exponent to be formatted with commas (default is 1000000000)

Extend

Creating your own notations is very simple! Just extend base class Notation and implement the required methods get name() and formatDecimal:

class SimpleNotation extends ADNotations.Notation {
  get name() {
    return "Simple";
  }

  formatDecimal(value, places) {
    return `Mantissa: ${value.mantissa.toFixed(places)}, Exponent: ${value.exponent}`;
  }
}

You can also extend existing notations (like EmojiNotation does) and override other methods, but this is a more advanced case which you can figure out by looking at the source code of existing notations.

Community Notations

To use community notations, download community pack from the releases page. The community pack can be used separately from the base pack. To access community notations from your code, use ADCommunityNotations instead of ADNotations. Apart from that, the usage pattern is the same as with the base pack

If you want your notation to be publicly available via this library, you should start by adding your notation to a src/community folder and making a pull request with it.

After your PR is merged (which means that one of the maintainers decided that it is good enough), you can reach out to AD devs about adding it to a base game. There is no guarantee that it will be added, but all well-made notations will be available as a community pack.

Build

First, clone the repo

git clone https://github.com/antimatter-dimensions/notations.git
cd notations

Then install npm dependencies

npm install

And then run build command which will build all packs to the dist directory and to the docs directory.

npm run build

To build the AD pack or community pack separately, use build:ad or build:community command.

Contributing

  1. Be reasonable when commiting something.
  2. Be original when making a new notation.

Acknowledgements

Special thanks to the authors of notations:

Thanks to the authors of community notations:

Additional thanks to Omsi for the scaffolding of docs page.

notations's People

Contributors

dan-simon avatar dependabot[bot] avatar dependabot-preview[bot] avatar buck4437 avatar razenpok avatar earthernsence avatar ivansanchez avatar edricchan03 avatar ducdat0507 avatar omsi6 avatar patashu avatar alpeme14w2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.