Git Product home page Git Product logo

tatau's Introduction

tatau

tatau
(verb) to count, calculate, add up, enumerate, tally.

A Javascript / Typescript package which translates between numerals and te reo Māori text.

Tatau is dependency-less. Installing it will not add any additional dependencies to your project.

Demo

You can see tatau in use on the demo site.

Installation

Add tatau to your project.

npm install tatau

Usage

Convert numerals to te reo Māori

Explicit types added for clarity

import { tatau } from 'tatau';

const tuhi = console.log;

let value: number = 51;
let tau: string = tatau(value);
tuhi(tau); // rima tekau mā tahi

Decimals are rounded to their integer part.

value = 107.924;
tau = tatau(value);
tuhi(tau); // kotahi rau mā whitu  
  
value = -3.14;
tau = tatau(value);
tuhi(tau); // kore toru

Specify options you want to apply.

value = 4;
tau = tatau(value, { ordinalOutput: true });
tuhi(tau); // tuawhā

Convert te reo Māori to numerals

Explicit types added for clarity
NB: Converting te reo to numerals is not yet supported

import { tatau } from 'tatau';

const tuhi = console.log;

const tau: string = 'rima tekau mā tahi';

const value: number = tatau(tau);

tuhi(value); // 51

Options

Use the TatauOptions interface for additional configuration.

The default values are as follows:

Option Default Description
ordinalInput false Set to true when the input being provided is an ordinal number, e.g. 7th or tuawhitu. The default input is cardinal numbers. NB: Ordinal Input is not yet supported.
ordinalOutput false Set to true when you want the output to be an ordinal number, e.g. 7th or tuawhitu. The default output is cardinal numbers.

Usage as a class

Create a new instance of the Tatau class to allow you to define TatauOptions once. Then options are not passed as the second parameter.

The methods available on the Tatau class are:

Method Description
options Get or set the current TatauOptions
tatau Convert your value

Example:

import { Tatau, TatauOptions } from 'tatau';

const options: TatauOptions = {
    ordinalOutput: true,
};

const tatau = new Tatau(options);

const value = 3;

const tau = tatau.tatau(value);

console.log({
    tau,                        // tuatoru
    options: tatau.options,     // { ordinalOutput: true }
});

Use .options to change options on an existing instance.

tatau.options = { ordinalOutput: false };

const tau = tatau.tatau(value);

console.log({
    tau,                        // toru
    options: tatau.options,     // { ordinalOutput: false }
});

tatau's People

Contributors

jeff-goodman avatar dependabot[bot] avatar

Watchers

 avatar

tatau's Issues

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.