Skip to content
/ nyinaa Public

A collection of reusable functions & utilities (timers, validation, sanitization, ranges, logging, ...)

License

Notifications You must be signed in to change notification settings

aberba/nyinaa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nyinaa

A collection of reusable functions & utilities (timers, validators, sanitizers, ranges, logging, ...)

Installation

To install this package from the Dub package repository, you may add nyinaa as dependency in your dub.json file and the package will be downloaded automatically during project build if it's not downloaded already.

{
    "dependencies": {
        "nyinaa": "~>0.0.3"
    }
}

You may also fetch the latest version manually in the command-line:

dub add nyinaa

Example

import nyinaa.timers : setInterval, stopInterval;

import std.stdio : writeln;
import std.datetime : seconds;
import core.thread.osthread : Thread;

void main()
{
	// "tid" of type Tid can be referenced
	// to stop setInterval()
	auto tid = setInterval(1000.seconds, { writeln("tick"); });
	auto tid2 = setInterval(3000.seconds, { writeln("tock"); });
	Thread.sleep(12.seconds);

	// stop running setInterval()
	stopInterval(tid);
	stopInterval(tid2);

	// OR keep running timers
	// using import core.thread.osthread: thread_joinAll;
    // thread_joinAll();
}

Implemented functions - Validators

Validators - for user data (e.g. form data)

  • isEmail()
  • isIP()
  • isIPv4()
  • isIPv6()
  • isUUID()
  • isUUIDv3()
  • isUUIDv4()
  • isUUIDv5()

Example

import nyinaa.validators;

assert(isIP("192.169.0.0"));
assert(isIP("2001:db8:0:1:1:1:1:1"));
assert(!isIP("192.169.0.500"));
assert(!isIP("2001:db8:0:1:1:1:1:1xxx"));

assert(isIPv4("127.0.0.1"));
assert(!isIPv4("127.0.0.500"));

Implemented functions - Timers

Time-based utility functions

  • setInterval()
  • stopInterval()

Implemented functions - Sanitizers

Sanitizing data

  • stripTags()

Implemented functions - Image

Image related operation

  • isImageDataURI()
  • bufferFromDataURI()

Implemented functions - Range

Handy functions for use in range related tasks

  • concreteRange()
  • orElse()
  • then()

Documentation

See the documentation for the various functions and examples on how to use them.

To-do

Any generic validator form validation, etc. is welcomed

About

A collection of reusable functions & utilities (timers, validation, sanitization, ranges, logging, ...)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages