Skip to content

Instantly share code, notes, and snippets.

View cameronbass's full-sized avatar

Cam Bass cameronbass

View GitHub Profile
const ClickEvent = (input) => {
input.addEventListener('click', () => {
input.select()
})
}
export default ClickEvent
function setHiddenInput (wrapper, options) {
var inputValue = ''
const hiddenInput = wrapper.querySelector(`input[name=${options['inputName']}]`)
const inputs = []
const inputIds = [...Array(options['inputCount']).keys()];
inputIds.forEach($input => {
const foundInput = wrapper.querySelector(`#honeycrisp-single-input-${$input}`)
inputs.push(foundInput)
/**
* @function handleForward
* @param {HTMLElement} nextEl
* Handle the right arrow action
*/
function handleForward(nextEl) {
if (!(nextEl instanceof HTMLInputElement)) { return }
nextEl.focus()
nextEl.select()
const BeforeInputEvent = (input) => {
input.addEventListener('beforeinput', (event) => {
const isNumeric = n => !isNaN(n);
if (!isNumeric(event.data)) {
event.preventDefault()
return
}
})
}
const PasteEvent = (input, wrapper) => {
input.addEventListener('paste', (event) => {
const pasteData = event.clipboardData.getData('text/plain')
const isNumeric = n => !isNaN(n);
if (!isNumeric(pasteData)) {
return
}
const originalInput = input
/**
* Input Generation. Build the necessary inputs
* based on the options defined by the user
*/
import InputGeneration from './input-generation'
/**
* @class Honeycrisp
* @param {HTMLElement} el
* @param {Object} [options]
/**
* Event Listeners. These events will provide
* the behavior necessary to ensure the inputs
* are smooth and responsive.
*/
import PasteEvent from './events/paste'
import BeforeInputEvent from './events/before-input'
import KeydownEvent from './events/keydown'
import InputEvent from './events/input'
import ClickEvent from './events/click'
/**
* @function defaultOptions
* Set options that can be overridden
* when creating the Honeycrisp instance.
*/
function defaultOptions () {
return {
inputClass: 'default-input-class',
wrapperClass: 'default-wrapper-class',
inputCount: 6,
const User = require("../models/user")
exports.register = function (req, res) {
User.register(
new User({
email: req.body.email,
username: req.body.username
}), req.body.password, function (err, msg) {
if (err) {
res.send(err);
@cameronbass
cameronbass / user.js
Created December 9, 2022 02:22
user model for user session auth
const mongoose = require('mongoose');
const passportLocalMongoose = require('passport-local-mongoose');
const Schema = mongoose.Schema;
const UserSchema = new Schema({
username: {
type: String,
required: true,
unique: true
},