npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-greeting

v1.0.3

Published

A utility function for React Native that returns a greeting message based on the time of day. Users must provide a custom translation function and can optionally configure custom translation keys.

Downloads

3

Readme

react-native-greeting npm version

A React Native utility function that provides time-based greetings in English and Indonesian. This package is designed to be flexible and customizable with support for basic localization needs.

Features

  • Provides a greeting message based on the current time of day.
  • Supports English ('en') and Indonesian ('id') languages.
  • Allows customization of translation keys for different times of the day.

Installation

npm

npm install react-native-greeting --save

Platform compatibility

This project is compatible with iOS, Android, Windows and macOS.
This project supports both the old (paper) and the new architecture (fabric).
This project is compatible with expo.

Getting Started

If any step seems unclear, please create a pull request.

Usage

Import the getGreeting function from react-native-greeting and use it like so:

import { getGreeting } from 'react-native-greeting';

const name = 'John';
const greeting = getGreeting(name); // Returns greeting in default language (English) based on current time
console.log(greeting); // Output could be: "Good morning, John" or "Good evening, John" depending on the time of day

Custom Language Example

const name = 'Johny';
const greeting = getGreeting(name, 'id'); // Returns greeting in Indonesian
console.log(greeting); // Output: "Selamat pagi, Johny" or "Selamat malam, Johny" based on the time

Custom Greeting Example

const customKeys = {
  morning_greating: 'Hey, good morning! '
};
const greeting = getGreeting('Johny', 'en', customKeys);
console.log(greeting); // Output: "Hey, good morning! Johny"

API

getGreeting(name: string, language?: string, customKeys?: CustomKeys): string

Parameters

| Parameter | Type | Description | |-------------|--------------------------|---------------------------------------------------------------------------------------------------| | name | string | Required. The name of the person to greet. | | language | string (optional) | The language to use for the greeting. Defaults to 'en' (English). | | customKeys| CustomKeys (optional) | An object with optional custom greetings for different times of the day (morning, afternoon, etc). |

CustomKeys Structure

| Key | Type | Description | |----------------------|----------|--------------------------------------------------------------| | morning_greating | string | Optional. Custom greeting for morning (5:00 - 11:59). | | afternoon_greating | string | Optional. Custom greeting for afternoon (12:00 - 17:59). | | evening_greating | string | Optional. Custom greeting for evening (18:00 - 20:59). | | night_greating | string | Optional. Custom greeting for night (21:00 - 4:59). |

Returns: A greeting string in the specified language or with custom keys, adjusted for the time of day.

Time-Based Greeting Logic

The greeting returned by the getGreeting function is based on the current hour of the day:

  • Morning (5:00 - 11:59): Uses the morning_greating key.
  • Afternoon (12:00 - 17:59): Uses the afternoon_greating key.
  • Evening (18:00 - 20:59): Uses the evening_greating key.
  • Night (21:00 - 04:59): Uses the night_greating key.

If the time is outside these ranges, the function defaults to the night_greating.

Customization Examples

Adding More Languages

You can easily add support for return languages by overriding the defaultTranslations object:

Currently supported languageTranslations:

const defaultTranslations: LanguageTranslations = {
  en: {
    morning_greating: 'Good morning, ',
    afternoon_greating: 'Good afternoon, ',
    evening_greating: 'Good evening, ',
    night_greating: 'Good night, '
  },
  id: {
    morning_greating: 'Selamat pagi, ',
    afternoon_greating: 'Selamat siang, ',
    evening_greating: 'Selamat sore, ',
    night_greating: 'Selamat malam, '
  },
};

Contributing

Feel free to contribute by adding more languages or improving the time-based logic. Follow these steps:

  • Fork the repository.
  • Create your feature branch (git checkout -b feature/my-feature).
  • Commit your changes (git commit -am 'Add some feature').
  • Push to the branch (git push origin feature/my-feature).
  • Create a new Pull Request.

License

MIT

Translations

This readme is available in:

📝 Author

👤 Johny Lie

🌱 Show your support

Please ⭐️ this repository if this project helped you!