You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constpocket=pickpocket({name: ['name is a required','name must be a string'],email: ['email is a required field','email must be an email']});pocket.any();
true
All
Retrieve all data within pocket
constpocket=pickpocket({name: ['name is a required','name must be a string'],email: ['email is a required field','email must be an email']});pocket.all();
{
name: ['name is a required', 'name must be a string'],
email: ['email is a required field', 'email must be an email']
}
constpocket=pickpocket({name: ['name is a required','name must be a string'],email: ['email is a required field','email must be an email']});pocket.list();
[
'name is a required',
'name must be a string',
'email must be an email',
'email is a required field',
]
Set
Set entirety of pocket data
constpocket=pickpocket({name: ['name is a required','name must be a string'],email: ['email is a required field','email must be an email']});pocket.set({name: ['eyy'],something: ['ohh']});
Forget
Forget all pocket data
constpocket=pickpocket({name: ['name is a required','name must be a string'],email: ['email is a required field','email must be an email']});pocket.forget();pocket.all();// {}
Has
Determine if specified field "has" items
constpocket=pickpocket({tag: [],name: [],email: ['email is a required','email must be an email'],});pocket.has('tag');// falsepocket.has('name');// falsepocket.has('email');// truepocket.has('something_else');// false
Get
Get _first_ item from specific field
constpocket=pickpocket({tag: [],name: [],email: ['email is a required','email must be an email'],});pocket.get('email');
List Field
List items for specific field
constpocket=pickpocket({tag: [],name: [],email: ['email is a required','email must be an email'],});pocket.list('email');
['email is a required', 'email must be an email']
Add
Add item to specific field
constpocket=pickpocket({tag: [],name: [],email: ['email is a required','email must be an email'],});pocket.add('tag','simplified');pocket.list('tag');// ['simplified'];pocket.add('email','extrafied');pocket.list('email');// ['email is a required', 'email must be an email', 'extrafied']
Set Field
Set specified field items
constpocket=pickpocket({tag: [],name: [],email: ['email is a required','email must be an email'],});pocket.set('email',['set','email','items','list']);pocket.list('email');
['set', 'email', 'items', 'list']
Forget Field
Forget items on the specified field
constpocket=pickpocket({tag: [],name: [],email: ['email is a required','email must be an email'],});pocket.forget('email');pocket.list('email');
[]
Utilization
Pickpocket.js (Simplified)
Example One: Form Error Messages (Organized Per Field)
Common Example
constpickpocket=require('pickpocket.js');consterrors=pickpocket({name: ['name is required','name is not a string','name needs to be cool'],email: ['email field must be an email']});// errors.all()// errors.list()// errors.any()// errors.add('name', 'message')// errors.list('email')// errors.has(field)// errors.set({})// errors.set('email', [])// errors.forget()// errors.forget('email')// etc...
Example Two: Human Life Cycle (Organized By Life Moments: Life Moments Have Callback Functions)
Small, simple, and to the point collection around common data structures (Form Field with list of Error messages, Hook Events with list of callbacks, etc...)