Randomness plugin for Neovim

⚠️
Work in progress
Required Neovim version: 0.1.0+

This plugin allows generating random values:

  • integers
  • strings
  • UUID
  • hex

Motivation

This is an educational project for me to better understand how Neovim's plugins work. This plugin took heavy inspiration from Randomness albeit being very limited in its functions.

How to use this plugin

Installation

-- using Packer
use "anuarkaliyev23/randomness"

Configuration

randomness = require("randomness")

-- Mind the colon!
randomness:setup()

You can provide custom configuration table to setup() function.

randomness = require("randomness")
config = require("randomness.config"):New()

-- Mind the colon!
randomness:setup(config)

Default Configuration

config = {
	logLevel = 'info',
	defaults = {
		integers = {
			min = 0,
			max = 100,
		},

		arrays = {
			options = {
				delimiter = ",",
				openingBracket = "[",
				closingBracket =  "]",
			},
			length = 10,
		},

		strings = {
			length = 12,
			options = {
				allowLetters = true,
				allowDigits = false,
				quotes = '"'
			}
		}

	}
}

Every call to require("randomness.config"):New() will create exact copy of aforementioned table

API

API exposes several methods to generate random values

randomness = require("randomness")

-- IN ALL CASES, PARAMETERS WILL BE SUBSTITUTED WITH DEFAULTS IF OMITTED

--- @param min integer
--- @param max integer
-- Generates random integer in range [min, max]
randomness:Integer(min, max)

--- @param min integer
--- @param max integer
--- @param count integer
--- @param arrayConfig table -- specifies how array should be serialized to string
-- Generates integer array of given `count` length. Every integer will be in [min, max] range.
randomness:Integers(min, max, count, arrayConfig)


--- @param length integer
--- @param stringOptions StringOptions
-- Generates random string and inserts it under current cursor position
randomness:String(length, stringOptions)


--- @param length integer
--- @param stringOptions StringOptions
--- @param count integer
--- @param arrayOptions ArrayOptions
-- Generates random strings array and inserts it under current cursor position
randomness.Strings(length, stringOptions, count, arrayOptions)

More detailed API and function signature can be found at init.lua

This API methods should be remapped to your preference.

Plugin do not provide any default mappings.

See also