Code Monkey home page Code Monkey logo

weekstart's Introduction

weekstart

NPM version

Library to get first day of week.

getWeekStartByRegion('MAC');   // 0

getWeekStartByLocale('arq');   // 6

The library is based on the following data from Unicode (especially from Common Locale Data Repository) and from ISO:

There are 2 variants of the library having identical API:

  • main - uses base mapping of language code to country code from langRegionMap.
  • full - uses full mapping of language code to country code from fullLangRegionMap.

langRegionMap contains only main language codes. It is data subset from fullLangRegionMap.

Table of contents

Installation

Node

npm install weekstart
bower install weekstart

AMD/UMD, <script>

Use dist/main.js or dist/min/main.js (minified version). Use dist/full.js or dist/min/full.js (minified version) when you need full locale data.

Usage

ECMAScript 6

import {getWeekStartByLocale, getWeekStartByRegion} from 'weekstart';

If you need full data:

import {getWeekStartByLocale, getWeekStartByRegion} from 'weekstart/full';

Node

const getWeekStartByLocale = require('weekstart').getWeekStartByLocale;
const getWeekStartByRegion = require('weekstart').getWeekStartByRegion;

If you need full data:

const getWeekStartByLocale = require('weekstart/full').getWeekStartByLocale;
const getWeekStartByRegion = require('weekstart/full').getWeekStartByRegion;

AMD/UMD

define(['path/to/dist/main.js'], function(weekstart) {
    const getWeekStartByLocale = weekstart.getWeekStartByLocale;
    const getWeekStartByRegion = weekstart.getWeekStartByRegion;
});

If you need full data:

define(['path/to/dist/full.js'], function(weekstart) {
    const getWeekStartByLocale = weekstart.getWeekStartByLocale;
    const getWeekStartByRegion = weekstart.getWeekStartByRegion;
});

Bower, <script>

<!-- Use bower_components/weekstart/dist/main.js and bower_components/weekstart/dist/full.js if the library was installed by Bower -->
<script type="text/javascript" src="path/to/dist/main.js"></script>
<script type="text/javascript">
    // weekstart is available via weekstart field of window object
    const getWeekStartByLocale = weekstart.getWeekStartByLocale;
    const getWeekStartByRegion = weekstart.getWeekStartByRegion;
</script>

If you need full data use path/to/dist/full.js instead of path/to/dist/main.js.

Examples

getWeekStartByRegion('dj');   // 6
getWeekStartByRegion('No');   // 1
getWeekStartByRegion('CAN');   // 0
getWeekStartByRegion(462);   // 5

getWeekStartByLocale('Jam');   // 0
getWeekStartByLocale('Fa');   // 6
getWeekStartByLocale('vi');   // 1
getWeekStartByLocale('es_MX');   // 0
getWeekStartByLocale('az-Arab-IRN');   // 6

In the following examples results are given for the function from full.js. The same calls for the function from main.js will return 1.

getWeekStartByLocale('CCP');   // 0
getWeekStartByLocale('UZ-arab');   // 6

API

getWeekStartByLocale(locale): number

Return first day of week for locale identifier: 0 - Sunday, 1 - Monday, 2 - Tuesday, 3 - Wednesday, 4 - Thursday, 5 - Friday, 6 - Saturday.

getWeekStartByRegion(regionCode): number

Return first day of week for country/region code: 0 - Sunday, 1 - Monday, 2 - Tuesday, 3 - Wednesday, 4 - Thursday, 5 - Friday, 6 - Saturday.

See docs for details.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

License

Licensed under the MIT license.

weekstart's People

Contributors

gamtiq avatar just-boris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

weekstart's Issues

Source of data

First of all, thank you for making this package. I was searching something similar for a long time :D.

I have two questions:

  • What is the source of the data?
  • What is the difference between base and full data?

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.