-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
15,501 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# EditorConfig helps developers define and maintain consistent | ||
# coding styles between different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
|
||
indent_style = tab | ||
indent_size = 4 | ||
|
||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.pbxproj -text | ||
# specific for windows script files | ||
*.bat text eol=crlf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# OSX | ||
# | ||
.DS_Store | ||
|
||
# XDE | ||
.expo/ | ||
|
||
# VSCode | ||
.vscode/ | ||
jsconfig.json | ||
|
||
# Xcode | ||
# | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
*.xccheckout | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.ipa | ||
*.xcuserstate | ||
project.xcworkspace | ||
|
||
# Android/IJ | ||
# | ||
.idea | ||
.gradle | ||
local.properties | ||
android.iml | ||
|
||
# Cocoapods | ||
# | ||
example/ios/Pods | ||
|
||
# node.js | ||
# | ||
node_modules/ | ||
npm-debug.log | ||
yarn-debug.log | ||
yarn-error.log | ||
|
||
# BUCK | ||
buck-out/ | ||
\.buckd/ | ||
android/app/libs | ||
android/keystores/debug.keystore | ||
|
||
# Expo | ||
.expo/* | ||
|
||
# generated by bob | ||
lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Override Yarn command so we can automatically setup the repo on running `yarn` | ||
|
||
yarn-path "scripts/bootstrap.js" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Contributing | ||
|
||
✨ Thank you for contributing ✨ | ||
|
||
I want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. | ||
|
||
## Development workflow | ||
|
||
To get started with the project, run `yarn` in the root directory to install the required dependencies for each package: | ||
|
||
```sh | ||
yarn | ||
``` | ||
|
||
> While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development. | ||
While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app. | ||
|
||
To start the packager: | ||
|
||
```sh | ||
yarn example start | ||
``` | ||
|
||
To run the example app on Android: | ||
|
||
```sh | ||
yarn example android | ||
``` | ||
|
||
Make sure your code passes TypeScript. Run the following to verify: | ||
|
||
```sh | ||
yarn typescript | ||
``` | ||
|
||
Remember to add tests for your change if possible. Run the unit tests by: | ||
|
||
```sh | ||
yarn test | ||
``` | ||
|
||
To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativeandroidcurrencyformatter` under `Android`. | ||
|
||
### Scripts | ||
|
||
The `package.json` file contains various scripts for common tasks: | ||
|
||
- `yarn bootstrap`: setup project by installing all dependencies and pods. | ||
- `yarn typescript`: type-check files with TypeScript. | ||
- `yarn test`: run unit tests with Jest. | ||
- `yarn example start`: start the Metro server for the example app. | ||
- `yarn example android`: run the example app on Android. | ||
|
||
### Sending a pull request | ||
|
||
When you're sending a pull request: | ||
|
||
- Prefer small pull requests focused on one change. | ||
- Verify that linters and tests are passing. | ||
- Review the documentation to make sure it looks good. | ||
- Follow the pull request template when opening a pull request. | ||
- For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) Vasyl Stokolosa <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,79 @@ | ||
# react-native-android-currency-formatter | ||
# React Native Android Currency Formatter [![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?hashtags=javascript&original_referer=https%3A%2F%2Fpublish.twitter.com%2F&ref_src=twsrc%5Etfw&text=Validation%20of%20CSV%20file%20against%20user%20defined%20schema%20(returns%20back%20object%20with%20data%20and%20invalid%20messages)&tw_p=tweetbutton&url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fcsv-file-validator&via=shystrukk) # | ||
[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php) | ||
[![npm version](https://badge.fury.io/js/react-native-android-currency-formatter.svg)](https://badge.fury.io/js/react-native-android-currency-formatter) | ||
|
||
Native Module for a currency format with specified FORMAT locale. | ||
|
||
## Installation | ||
|
||
#### npm | ||
```sh | ||
npm install --save react-native-android-currency-formatter | ||
``` | ||
|
||
#### yarn | ||
```sh | ||
yarn add react-native-android-currency-formatter --save | ||
``` | ||
|
||
### For iOS use [Internationalization API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) | ||
|
||
## Usage | ||
|
||
**Read before use [Synchronous Method](https://reactnative.dev/docs/native-modules-android#synchronous-methods)** | ||
|
||
```js | ||
import AndroidCurrencyFormatter from 'react-native-android-currency-formatter'; | ||
|
||
// Synchronous Method | ||
AndroidCurrencyFormatter.numberFormat(30000, 'USD', 'en', 'US') // $30,000.00 | ||
|
||
// Asynchronous Method | ||
AndroidCurrencyFormatter | ||
.numberFormatAsync(1000000.25, 'USD', 'en', 'US') | ||
.then(data => { | ||
// $1,000,000.25 | ||
}); | ||
``` | ||
|
||
## API ## | ||
```js | ||
// Synchronous Method | ||
// Returns currency format or 'N/A' if one of the arguments are not correct | ||
numberFormat(amount, currencyCode, language, country) | ||
|
||
// Asynchronous Method | ||
// Returns Promise with currency format or 'N/A' if one of the arguments are not correct | ||
numberFormatAsync(amount, currencyCode, language, country) | ||
|
||
``` | ||
### amount | ||
Type: `Number` <br> | ||
the number which will be converted to currency | ||
|
||
### currencyCode | ||
Type: `String` <br> | ||
ISO 4217 currency code. [Some codes](https://stackoverflow.com/questions/3536968/get-all-possible-available-currencies/39259097#39259097) | ||
|
||
### language | ||
Type: `String` <br> | ||
An ISO 639 alpha-2 or alpha-3 language code, or a language subtag up to 8 characters in length. | ||
|
||
### country | ||
Type: `String` <br> | ||
An ISO 3166 alpha-2 country code or a UN M.49 numeric-3 area code. | ||
|
||
Check [example/src/App.tsx](example/src/App.tsx) file if you need more details. | ||
|
||
![](example/assets/demo.png) | ||
|
||
## Contributing | ||
|
||
Any contributions you make **are greatly appreciated**. | ||
|
||
Please read the [Contributions Guidelines](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. | ||
|
||
|
||
## License | ||
|
||
MIT © [Vasyl Stokolosa](https://about.me/shystruk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
buildscript { | ||
if (project == rootProject) { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.5.3' | ||
} | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
|
||
def safeExtGet(prop, fallback) { | ||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback | ||
} | ||
|
||
android { | ||
compileSdkVersion safeExtGet('AndroidCurrencyFormatter_compileSdkVersion', 29) | ||
buildToolsVersion safeExtGet('AndroidCurrencyFormatter_buildToolsVersion', '29.0.2') | ||
defaultConfig { | ||
minSdkVersion safeExtGet('AndroidCurrencyFormatter_minSdkVersion', 16) | ||
targetSdkVersion safeExtGet('AndroidCurrencyFormatter_targetSdkVersion', 29) | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
} | ||
} | ||
lintOptions { | ||
disable 'GradleCompatible' | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
maven { | ||
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm | ||
url("$rootDir/../node_modules/react-native/android") | ||
} | ||
google() | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
//noinspection GradleDynamicVersion | ||
implementation "com.facebook.react:react-native:+" // From node_modules | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.reactnativeandroidcurrencyformatter"> | ||
|
||
</manifest> |
49 changes: 49 additions & 0 deletions
49
...src/main/java/com/reactnativeandroidcurrencyformatter/AndroidCurrencyFormatterModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.reactnativeandroidcurrencyformatter; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.module.annotations.ReactModule; | ||
|
||
import java.text.NumberFormat; | ||
import java.util.Currency; | ||
import java.util.Locale; | ||
|
||
@ReactModule(name = AndroidCurrencyFormatterModule.NAME) | ||
public class AndroidCurrencyFormatterModule extends ReactContextBaseJavaModule { | ||
public static final String NAME = "AndroidCurrencyFormatter"; | ||
|
||
public AndroidCurrencyFormatterModule(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public String getName() { | ||
return NAME; | ||
} | ||
|
||
@ReactMethod(isBlockingSynchronousMethod = true) | ||
public String numberFormat(double amount, String currencyCode, String language, String country) { | ||
return getCurrency(amount, currencyCode, language, country); | ||
} | ||
|
||
@ReactMethod() | ||
public void numberFormatAsync(double amount, String currencyCode, String language, String country, Promise promise) { | ||
promise.resolve(getCurrency(amount, currencyCode, language, country)); | ||
} | ||
|
||
private String getCurrency(double amount, String currencyCode, String language, String country) { | ||
try { | ||
Currency currency = Currency.getInstance(currencyCode); | ||
NumberFormat format = NumberFormat.getCurrencyInstance(new Locale(language, country)); | ||
format.setMaximumFractionDigits(currency.getDefaultFractionDigits()); | ||
return format.format(amount); | ||
} catch (Exception e) { | ||
return "N/A"; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...rc/main/java/com/reactnativeandroidcurrencyformatter/AndroidCurrencyFormatterPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.reactnativeandroidcurrencyformatter; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class AndroidCurrencyFormatterPackage implements ReactPackage { | ||
@NonNull | ||
@Override | ||
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
modules.add(new AndroidCurrencyFormatterModule(reactContext)); | ||
return modules; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
} |
Oops, something went wrong.