diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7c68b07 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# https://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..17f167d --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,29 @@ +{ + "env": { "browser": true, "commonjs": true }, + "extends": "eslint:recommended", + "parserOptions": { "ecmaVersion": 5 }, + "rules": { + "block-scoped-var": "error", + "consistent-return": "error", + "eqeqeq": "error", + "guard-for-in": "error", + "no-bitwise": "error", + "no-caller": "error", + "no-extra-parens": "off", + "no-extend-native": "error", + "no-loop-func": "error", + "no-new": "error", + "no-param-reassign": "error", + "no-return-assign": "error", + "no-sequences": "error", + "no-unused-expressions": "error", + "no-use-before-define": "error", + "no-undef": "error", + "no-eq-null": "error", + "radix": ["error", "always"], + "indent": ["error", 2, { "SwitchCase": 1 }], + "quotes": ["error", "double"], + "semi": ["error", "always"], + "strict": ["error", "global"] + } +} diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 0000000..b79b995 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,19 @@ +--- +name: Bug report +about: Report an issue +title: "" +labels: bug +assignees: "" +--- + +**Describe the bug** +A clear and concise description of the bug. + +**To Reproduce** +A minimal code example (preferably a runnable example on [Try PureScript](https://try.purescript.org)!) or steps to reproduce the issue. + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/change-request.md b/.github/ISSUE_TEMPLATE/change-request.md new file mode 100644 index 0000000..a2ee685 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/change-request.md @@ -0,0 +1,21 @@ +--- +name: Change request +about: Propose an improvement to this library +title: "" +labels: "" +assignees: "" +--- + +**Is your change request related to a problem? Please describe.** +A clear and concise description of the problem. + +Examples: + +- It's frustrating to have to [...] +- I was looking for a function to [...] + +**Describe the solution you'd like** +A clear and concise description of what a good solution to you looks like, including any solutions you've already considered. + +**Additional context** +Add any other context about the change request here. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..c47a263 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: PureScript Discourse + url: https://discourse.purescript.org/ + about: Ask and answer questions here. + - name: Functional Programming Slack + url: https://functionalprogramming.slack.com + about: For casual chat and questions (use https://fpchat-invite.herokuapp.com to join). diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..d8780f7 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,11 @@ +**Description of the change** +Clearly and concisely describe the purpose of the pull request. If this PR relates to an existing issue or change proposal, please link to it. Include any other background context that would help reviewers understand the motivation for this PR. + +--- + +**Checklist:** + +- [ ] Added the change to the changelog's "Unreleased" section with a link to this PR and your username +- [ ] Linked any existing issues or proposals that this pull request should close +- [ ] Updated or added relevant documentation in the README and/or documentation directory +- [ ] Added a test for the contribution (if applicable) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0b3ca67 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,51 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up PureScript toolchain + uses: purescript-contrib/setup-purescript@main + + - name: Cache PureScript dependencies + uses: actions/cache@v2 + with: + key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }} + path: | + .spago + output + + - name: Set up Node toolchain + uses: actions/setup-node@v1 + with: + node-version: "12.x" + + - name: Cache NPM dependencies + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Install NPM dependencies + run: npm install + + - name: Build the project + run: npm run build + + - name: Run tests + run: npm run test diff --git a/.gitignore b/.gitignore index 72524cf..5a54e2f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,13 @@ -/bower_components/ -/node_modules/ -/.pulp-cache/ -/output/ -/.psci* -/src/.webpack.js -.psc-ide-port +.* +!.gitignore +!.github +!.editorconfig +!.eslintrc.json + +output +generated-docs +bower_components + +node_modules package-lock.json +*.lock diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3ee97af..0000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: node_js -dist: trusty -sudo: required -node_js: stable -install: - - npm install -g bower - - npm install - - bower install --production -script: - - npm run -s build - - bower install - - npm run -s test -after_success: -- >- - test $TRAVIS_TAG && - echo $GITHUB_TOKEN | pulp login && - echo y | pulp publish --no-push diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3db9d6b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,97 @@ +# Changelog + +Notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +Breaking changes (😱!!!): + +New features: + +Bugfixes: + +Other improvements: + +## [v4.0.1](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v4.0.1) - 2019-02-09 + +- Fixed issue where negative numbers with padding would be printed like `00-0.5` rather than `-000.5` +- Fixed issue where negative years would print similarly and would not parse + +## [v4.0.0](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v4.0.0) - 2018-06-26 + +- Update to PS@0.12 @thomashoneyman + +## [v3.0.1](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v3.0.1) - 2017-12-07 + +Bug fixes: +- Enable timestamp parsing @tippenein + +Other changes: +- Update README and tests @tippenein +- Remove self import @paulyoung + +## [v3.0.0](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v3.0.0) - 2017-09-11 + +- Added formats for week day (@tippenein) + +## [v2.1.0](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v2.1.0) - 2017-08-08 + +- Added `Ord` instance for `FormatterCommand` + +## [v2.0.2](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v2.0.2) - 2017-07-19 + +- fix for 24 and `{12,0}{am,pm}` cases #26 + +## [v2.0.1](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v2.0.1) - 2017-07-11 + +- fix YYYY formatting #23 + +## [v2.0.0](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v2.0.0) - 2017-06-27 + +- Added support for Intervals +- Type of `DateTime.Formatter` has changed (BREAKING) +- Type of `Number.Formatter` has changed (BREAKING) + +## [v1.0.1](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v1.0.1) - 2017-05-13 + +- Fixed `Hours24` to pad to two digits when printing + +## [v1.0.0](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v1.0.0) - 2017-04-21 + +- Updated for PureScript 0.11 + +## [v0.4.0](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v0.4.0) - 2017-04-15 + +- Added `MinutesTwoDigits`, `SecondsTwoDigits`, `MillisecondsShort`, and `MillisecondsTwoDigits` (@sectore) + +## [v0.3.1](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v0.3.1) - 2017-03-23 + +- Fixed `DayOfMonthTwoDigits` to zero-pad as necessary when printing (@korayal) + +## [v0.3.0](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v0.3.0) - 2017-03-22 + +- Added support for single-digit day-of-month parsing (@negator) + +## [v0.2.0](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v0.2.0) - 2017-03-07 + +- Updated dependencies + +## [v0.1.3](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v0.1.3) - 2017-03-01 + +- Fix `bower.json` for Pursuit publishing + +## [v0.1.1](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v0.1.1) - 2017-02-24 + +- Fixed behaviour of two-digit year formatting (@dgendill) + +## [v0.1.0](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v0.1.0) - 2016-11-03 + +- 0.10 updates + +## [0.0.5](https://github.com/purescript-contrib/purescript-formatters/releases/tag/0.0.5) - 2016-09-18 + +- Fixed AM/PM behavior @doolse + +## [0.0.1](https://github.com/purescript-contrib/purescript-formatters/releases/tag/0.0.1) - 2016-07-21 + +- Initial release \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..68d9a71 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,5 @@ +# Contributing to Formatters + +Thanks for your interest in contributing to `formatters`! We welcome new contributions regardless of your level of experience or familiarity with PureScript. + +Every library in the Contributors organization shares a simple handbook that helps new contributors get started. With that in mind, please [read the short contributing guide on purescript-contrib/governance](https://github.com/purescript-contrib/governance/blob/main/contributing.md) before contributing to this library. diff --git a/README.md b/README.md index 661f702..ef8ca81 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,24 @@ -# purescript-formatters +# Formatters -[![Latest release](http://img.shields.io/github/release/slamdata/purescript-formatters.svg)](https://github.com/slamdata/purescript-formatters/releases) -[![Build status](https://travis-ci.org/slamdata/purescript-formatters.svg?branch=master)](https://travis-ci.org/slamdata/purescript-formatters) +[![CI](https://github.com/purescript-contrib/purescript-formatters/workflows/CI/badge.svg?branch=main)](https://github.com/purescript-contrib/purescript-formatters/actions?query=workflow%3ACI+branch%3Amain) +[![Release](https://img.shields.io/github/release/purescript-contrib/purescript-formatters.svg)](https://github.com/purescript-contrib/purescript-formatters/releases) +[![Pursuit](https://pursuit.purescript.org/packages/purescript-formatters/badge)](https://pursuit.purescript.org/packages/purescript-formatters) +[![Maintainer: garyb](https://img.shields.io/badge/maintainer-garyb-teal.svg)](https://github.com/garyb) +[![Maintainer: thomashoneyman](https://img.shields.io/badge/maintainer-thomashoneyman-teal.svg)](https://github.com/thomashoneyman) A PureScript alternative to numeral.js, moment.js, etc. ## Installation +Install `formatters` with [Spago](https://github.com/purescript/spago): + +```sh +spago install formatters ``` -bower install purescript-formatters -``` -## Number formatters +## Quick start + +**Number formatters** Formatter has following properties + Number of digits before dot @@ -20,8 +27,7 @@ Formatter has following properties + Should thousands be separated by comma + Should output string have abbreviations (like `K` or `M`) -Number will be padded with zeros to have at least this number of leading zeros. -This doesn't restrict number to have more digits then leading zeros in format string. +Number will be padded with zeros to have at least this number of leading zeros. This doesn't restrict number to have more digits then leading zeros in format string. + `0000.0` will show 4 digits: `12 → "0012.0"`, `1234 → "1234.0"` + `00.0` will show only 2 digits : `12 → "12.0"`, `1234 → "1234.0"` @@ -40,7 +46,7 @@ For abbreviation one could use `a` flag. In general it tries to find the closest then use formatter to result of division of input number and that power. + `0a`: `1234567 → "1M"`, `1 → "1"` -## Date/Time formatters +**Date/Time formatters** This is a subset of common format/parse strings currently supported. @@ -69,4 +75,23 @@ Full list is defined [here](https://github.com/slamdata/purescript-formatters/bl ## Documentation -Module documentation is published on Pursuit: [http://pursuit.purescript.org/packages/purescript-formatters](http://pursuit.purescript.org/packages/purescript-formatters) +`formatters` documentation is stored in a few places: + +1. Module documentation is [published on Pursuit](https://pursuit.purescript.org/packages/purescript-formatters). +2. Written documentation is kept in the [docs directory](./docs). +3. Usage examples can be found in [the test suite](./test). + +If you get stuck, there are several ways to get help: + +- [Open an issue](https://github.com/purescript-contrib/purescript-formatters/issues) if you have encountered a bug or problem. +- [Search or start a thread on the PureScript Discourse](https://discourse.purescript.org) if you have general questions. You can also ask questions in the `#purescript` and `#purescript-beginners` channels on the [Functional Programming Slack](https://functionalprogramming.slack.com) ([invite link](https://fpchat-invite.herokuapp.com/)). + +## Contributing + +You can contribute to `formatters` in several ways: + +1. If you encounter a problem or have a question, please [open an issue](https://github.com/purescript-contrib/purescript-formatters/issues). We'll do our best to work with you to resolve or answer it. + +2. If you would like to contribute code, tests, or documentation, please [read the contributor guide](./CONTRIBUTING.md). It's a short, helpful introduction to contributing to this library, including development instructions. + +3. If you have written a library, tutorial, guide, or other resource based on this package, please share it on the [PureScript Discourse](https://discourse.purescript.org)! Writing libraries and learning resources are a great way to help this library succeed. diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..49f432b --- /dev/null +++ b/docs/README.md @@ -0,0 +1,3 @@ +# Formatters Documentation + +This directory contains documentation for `formatters`. If you are interested in contributing new documentation, please read the [contributor guidelines](../CONTRIBUTING.md) and [What Nobody Tells You About Documentation](https://documentation.divio.com) for help getting started. diff --git a/package.json b/package.json index 0399d39..ad3ecca 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,10 @@ { "private": true, "scripts": { - "clean": "rimraf output && rimraf .pulp-cache", - "build": "pulp build -- --censor-lib --strict", - "test": "pulp test" + "build": "eslint src && spago build --purs-args '--censor-lib --strict'", + "test": "spago test --no-install" }, "devDependencies": { - "pulp": "^12.3.0", - "purescript": "^0.12.0", - "purescript-psa": "^0.6.0", - "rimraf": "^2.6.2" + "eslint": "^7.6.0" } } diff --git a/packages.dhall b/packages.dhall new file mode 100644 index 0000000..b5baf39 --- /dev/null +++ b/packages.dhall @@ -0,0 +1,4 @@ +let upstream = + https://github.com/purescript/package-sets/releases/download/psc-0.13.8-20200922/packages.dhall sha256:5edc9af74593eab8834d7e324e5868a3d258bbab75c5531d2eb770d4324a2900 + +in upstream diff --git a/spago.dhall b/spago.dhall new file mode 100644 index 0000000..96f0667 --- /dev/null +++ b/spago.dhall @@ -0,0 +1,18 @@ +{ name = "formatters" +, dependencies = + [ "aff" + , "console" + , "datetime" + , "effect" + , "fixed-points" + , "generics-rep" + , "lists" + , "parsing" + , "prelude" + , "psci-support" + , "spec" + , "transformers" + ] +, packages = ./packages.dhall +, sources = [ "src/**/*.purs", "test/**/*.purs" ] +} diff --git a/src/Data/Formatter/Number.js b/src/Data/Formatter/Number.js index c70fe6b..ae12239 100644 --- a/src/Data/Formatter/Number.js +++ b/src/Data/Formatter/Number.js @@ -1,5 +1,7 @@ +"use strict"; -// converts a number to a string of the nearest integer _without_ appending ".0" (like `show` for `Number`) or -// clamping to +/- 2 billion (like when working with `Int`). This is important for performance compared to other -// means of showing an integer potentially larger than +/- 2 billion. -exports.showNumberAsInt = function (n) { return Math.round(n).toString(); } +// Converts a number to a string of the nearest integer _without_ appending ".0" +// (like `show` for `Number`) or clamping to +/- 2 billion (like when working +// with `Int`). This is important for performance compared to other means of +// showing an integer potentially larger than +/- 2 billion. +exports.showNumberAsInt = function (n) { return Math.round(n).toString(); }; diff --git a/test/src/Main.purs b/test/src/Main.purs index 9d925cf..ef5affb 100644 --- a/test/src/Main.purs +++ b/test/src/Main.purs @@ -2,15 +2,16 @@ module Test.Main where import Prelude -import Test.Interval (intervalTest) +import Effect (Effect) +import Effect.Aff (launchAff_) import Test.DateTime (datetimeTest) +import Test.Interval (intervalTest) import Test.Number (numberTest) import Test.Spec.Reporter.Console (consoleReporter) -import Effect (Effect) -import Test.Spec.Runner (run) +import Test.Spec.Runner (runSpec) main ∷ Effect Unit -main = run [consoleReporter] do +main = launchAff_ $ runSpec [consoleReporter] do intervalTest datetimeTest numberTest