<script src="https://htmlguyllc.github.io/jPack/dist/jpack.bundled.min.js"></script>
<script>
const $user = {
id: 1, //pretend these came from your server and it's being output in your HTML's <head> section
fname: 'Bob',
lname: 'Jenkins',
email: 'bob@yahoo.com',
permissions: JSON.parse(JSON.stringify(['admin', 'edit-stuff'])), //your server will need to provide JSON to JS to parse
};
</script>
<h1>Results:</h1>
<results>
</results>
JavaScript
/**
jPack User Demo
https://htmlguyllc.github.io/jPack/#user
*/
//instantiate the user with all values provided from your server
const curUser = new jpack.User($user);
//we're going to put the user's data in this elem to demonstrate the class' abilities
var el = jpack.dom.getElement('results');
//show some functionality
el.innerHTML += 'ID: ' + curUser.getId();
el.innerHTML += '<hr>Fname: ' + curUser.getFname();
curUser.setFname('Jennie');
el.innerHTML += '<hr>Fname: ' + curUser.getFname();
el.innerHTML += '<hr>Lname: ' + curUser.getLname();
el.innerHTML += '<hr>Full Name: ' + curUser.getName();
el.innerHTML += '<hr>Email: ' + curUser.getEmail();
el.innerHTML += '<hr>Phone: ' + curUser.getPhone();
el.innerHTML += '<hr>Has Permission (should): ' + (curUser.hasPermission('admin') ? 'Yes' : 'No');
curUser.removePermission('admin');
el.innerHTML += '<hr>Has Permission (shouldn\'t): ' + (curUser.hasPermission('admin') ? 'Yes' : 'No');
el.innerHTML += '<hr>Has Permission (shouldn\'t): ' + (curUser.hasPermission('delete-stuff') ? 'Yes' : 'No');
curUser.addPermission('delete-stuff');
el.innerHTML += '<hr>Has Permission (should): ' + (curUser.hasPermission('delete-stuff') ? 'Yes' : 'No');
curUser.setAdditionalData({
auth0Key:'23582395823'
});
el.innerHTML += '<hr>Auth0 Key: ' + curUser.getDataItem('auth0Key');
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.