@9r3i/mfirebase 中文文档教程
Mobile Firebase
使用 firebase 库的简单方法。
Usage
const Firebase=new MFirebase;
Firebase.init(firebaseConfig);
Primitive Usage
<script type="module" src="mfirebase.js"></script>
Installation
npm i @9r3i/mfirebase
Test
/* authentication */
const auth=new Firebase.Auth;
auth.createUser('email@gmail.com','password',pre);
auth.signIn('email@gmail.com','password',pre);
auth.signOut(pre);
/* database */
const db=new Firebase.DB('users'),
id='0001',
username='9r3i',
password=password;
db.set(id,{username:username,password:password},pre);
db.get(id,pre);
/* storage */
const storage=new Firebase.Storage('images'),
input=document.createElement('input');
storage.get('grey.jpg',url=>{
var img=new Image;
img.src=url;
img.style.maxWidth='300px';
document.body.appendChild(img);
});
document.body.appendChild(input);
input.type='file';
input.onchange=function(e){
var file=this.files[0],
fr=new FileReader;
fr.onloadend=function(e){
var data=e.target.result;
pre({
type:'reader',
data:file,
url_length:data.length,
upto:Math.ceil(data.length/file.size*100),
});
storage.set(file.name,data,pre);
};
fr.readAsDataURL(file);
};
/* output log */
function pre(e){
console.log(e);
}
Mobile Firebase
Simple way to use firebase library.
Usage
const Firebase=new MFirebase;
Firebase.init(firebaseConfig);
Primitive Usage
<script type="module" src="mfirebase.js"></script>
Installation
npm i @9r3i/mfirebase
Test
/* authentication */
const auth=new Firebase.Auth;
auth.createUser('email@gmail.com','password',pre);
auth.signIn('email@gmail.com','password',pre);
auth.signOut(pre);
/* database */
const db=new Firebase.DB('users'),
id='0001',
username='9r3i',
password=password;
db.set(id,{username:username,password:password},pre);
db.get(id,pre);
/* storage */
const storage=new Firebase.Storage('images'),
input=document.createElement('input');
storage.get('grey.jpg',url=>{
var img=new Image;
img.src=url;
img.style.maxWidth='300px';
document.body.appendChild(img);
});
document.body.appendChild(input);
input.type='file';
input.onchange=function(e){
var file=this.files[0],
fr=new FileReader;
fr.onloadend=function(e){
var data=e.target.result;
pre({
type:'reader',
data:file,
url_length:data.length,
upto:Math.ceil(data.length/file.size*100),
});
storage.set(file.name,data,pre);
};
fr.readAsDataURL(file);
};
/* output log */
function pre(e){
console.log(e);
}