1.0.118 • Published 2 years ago

yow v1.0.118

Weekly downloads
142
License
ISC
Repository
github
Last release
2 years ago

Yow

Toolbox for Node. Contains stuff you only wished was there in the first place.

Installation

npm install yow --save

Methods

General Purpose

var sprintf = require('yow/sprintf');
var vsprintf = require('yow/vsprintf');
var once = require('yow/once');
var merge = require('yow/merge');
  • sprintf(args) - Just as you would expect. Uses the npm module 'sprintf-js'.
  • vsprintf(args) - Just as you would expect. Uses the npm module 'sprintf-js'.
  • once(fn, context) - Call a function just once and return the same result.
  • merge({}, objects...) - Like Object.assign() but does a deep merge.

File System

var mkdir = require('yow/mkdir')
var mkpath = require('yow/mkpath');
var fileExists = require('yow/fileExists');
var readJSON = require('yow/readJSON');
var writeJSON = require('yow/writeJSON');
  • mkdir(path) - Creates the directory you specify.
  • mkpath(path) - Creates the directory you specify. It will create multiple directories if they do not exit.
  • fileExists(path) - Nothing fancy, it just returns true/false.
  • readJSON(fileName) - Reads a JSON file and returns the contents.
  • writeJSON(fileName, object) - Writes an object to a JSON file.

Type Checks

var isArray = require('yow/isArray');
var isNumber = require('yow/isNumber');
var isString = require('yow/isString');
var isDate = require('yow/isDate');
var isFunction = require('yow/isFunction');
var isObject = require('yow/isObject');
var isInteger = require('yow/isInteger');
var isFloat = require('yow/isFloat');
  • isType(object, type) - Returns true/false if typeof equals 'type'.
  • isArray(object) - Is object an array?
  • isNumber(object) - Is object a JavaScript Number object?
  • isString(object) - Is object a String object?
  • isDate(object) - Is object a Date object (and contains a valid date)?
  • isFunction(object) - Is object a function object?
  • isObject(object) - Is object an object? BTW null is not an object.
  • isInteger(object) - Is object an integer?
  • isFloat(object) - Is object a float? Please note that isFloat(1.0) returns false.

Random

var random = require('yow/random');
  • random() - Returns Math.random().
  • random(integer) - Returns a random number from 0 to the integer specified (exclusive).
  • random(min, max) - Returns a random number from min to max (inclusive).
  • random(array) - Returns a randomly chosen object in the specified array.
  • random(object) - Returns a randomly chosen object property.

Also available as require('yow/random')

Range

var range = require('yow/range');
  • range(min, max, step) - Returns an range array generated by min, max, and step.

Console/Logging

require('yow/prefixConsole');
  • prefixConsole(fn) - Adds a prefix to all console methods.

Timer

var Timer = require('yow/timer');
var timer = new Timer();
  • timer.setTimer(delay, fn) - Executes the specified function fn after a delay. Previously set timers are cancelled.

  • timer.cancel() - Cancels the timer.

Request

var Request = require('yow/request');
var request = new Request(options);

A light-weight http/https request module.

function example() {

	var Request = require('yow/request');
	var yahoo = new Request('https://query.yahooapis.com');

	function getQuote(ticker) {
		var query = {};

		query.q        = 'select * from yahoo.finance.quotes where symbol =  "' + ticker + '"';
		query.format   = 'json';
		query.env      = 'store://datatables.org/alltableswithkeys';
		query.callback = '';

		yahoo.get('/v1/public/yql', {query:query}).then(function(response) {
			var quotes = response.body.query.results.quote;

			if (typeof qoutes != 'Array')
				quotes = [quotes];

			console.log(ticker, '=', quotes[0].LastTradePriceOnly);

		})

		.catch (function(error) {
			console.log(error);

		});

	}

	getQuote('AAPL');

};
  • request.request(options) - See https://nodejs.org/api/http.html#http_http_request_options_callback for documentation.
  • request.get(options) - Same as request('GET', options)
  • request.post(options) - Same as request('POST', options)
  • request.delete(options) - Same as request('DELETE', options)
  • request.put(options) - Same as request('PUT', options)
1.0.118

2 years ago

1.0.116

2 years ago

1.0.115

2 years ago

1.0.112

2 years ago

1.0.111

2 years ago

1.0.114

2 years ago

1.0.113

2 years ago

1.0.110

3 years ago

1.0.109

3 years ago

1.0.108

5 years ago

1.0.107

5 years ago

1.0.106

5 years ago

1.0.105

5 years ago

1.0.104

5 years ago

1.0.103

5 years ago

1.0.102

5 years ago

1.0.101

5 years ago

1.0.100

5 years ago

1.0.99

5 years ago

1.0.98

5 years ago

1.0.97

5 years ago

1.0.96

5 years ago

1.0.95

6 years ago

1.0.94

6 years ago

1.0.93

6 years ago

1.0.92

6 years ago

1.0.91

6 years ago

1.0.90

6 years ago

1.0.89

6 years ago

1.0.88

6 years ago

1.0.87

6 years ago

1.0.86

6 years ago

1.0.85

6 years ago

1.0.84

7 years ago

1.0.83

7 years ago

1.0.82

7 years ago

1.0.81

7 years ago

1.0.80

7 years ago

1.0.79

7 years ago

1.0.78

7 years ago

1.0.76

7 years ago

1.0.75

7 years ago

1.0.73

7 years ago

1.0.72

7 years ago

1.0.71

7 years ago

1.0.70

7 years ago

1.0.69

7 years ago

1.0.68

7 years ago

1.0.66

7 years ago

1.0.65

7 years ago

1.0.64

7 years ago

1.0.63

7 years ago

1.0.62

7 years ago

1.0.61

7 years ago

1.0.60

7 years ago

1.0.59

7 years ago

1.0.58

7 years ago

1.0.57

7 years ago

1.0.56

7 years ago

1.0.55

7 years ago

1.0.54

7 years ago

1.0.53

7 years ago

1.0.52

7 years ago

1.0.51

7 years ago

1.0.50

7 years ago

1.0.49

7 years ago

1.0.48

7 years ago

1.0.46

7 years ago

1.0.45

7 years ago

1.0.44

7 years ago

1.0.43

7 years ago

1.0.41

7 years ago

1.0.39

7 years ago

1.0.38

7 years ago

1.0.37

7 years ago

1.0.36

7 years ago

1.0.35

7 years ago

1.0.33

7 years ago

1.0.32

7 years ago

1.0.31

7 years ago

1.0.30

7 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

8 years ago

1.0.25

8 years ago

1.0.24

8 years ago

1.0.22

8 years ago

1.0.20

8 years ago

1.0.19

8 years ago

1.0.18

8 years ago

1.0.17

8 years ago

1.0.16

8 years ago

1.0.15

8 years ago

1.0.14

8 years ago

1.0.13

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.0

8 years ago