APIS de JS

Índice

  1.  APIS De HTML5
  2. API de NodeJS
  3. API de Google

APIS DE HTML5

API de Almacenamiento

  var original = document.getElementById("original").value;
  if (window.localStorage) localStorage.original = original;

Mecanismos de almacenamiento  

1. locallocaStorage

2. sessionStorage

API de Geolocalización

     function getPos(position) {
         var lat = position.coords.latitude,
             lon = position.coords.longitude;
         var img = "http://maps.googleapis.com/maps/api/staticmap?center="
                    +lat+","+lon+"&zoom=15&size=500x300&sensor=false";
         document.getElementById('mapa').innerHTML = "<img src='"+img+"'>";
     }

API de Speech

var speaker = new SpeechSynthesisUtterance(); 
speaker.voice = 'Google Español'; 
speaker.lang = 'es-ES';
speaker.text = 'Texto de prueba'; 
speechSynthesis.speak(speaker); 
speechSynthesis.getVoices();

API de Audio y Video

<button onClick="audio.play()">Play/Continue</button>
<button onClick="audio.pause()">Pause</button>
<script>
    var audio = new Audio(url);
</script>

API de Notificaciones

<script>
     title = '¡Ha recibido un correo!';
     options = {
         body: 'Correo de la ULL',
         tag: 'idmsg1',
         icon: 'imagen'
     };
     Notification.requestPermission(function(status) {
         console.log('User Notification Permission: ' + status);
         new Notification(title, options);
     });
</script>

API de dispositivos

/*Acelerómetro*/

window.addEventListener('devicemotion', function(e) {
  document.getElementById('accelx').value = e.acceleration.x;
  document.getElementById('accely').value = e.acceleration.y;
  document.getElementById('accelz').value = e.acceleration.z;
});

/*Vibración*/

navigator.vibrate(500); 

/*Batería*/

var battery = navigator.battery || navigator.mozBattery || navigator.webkitBattery;

function updateBatteryStatus() {
  console.log("Battery status: " + battery.level * 100 + " %");

  if (battery.charging) {
    console.log("Battery is charging"); 
  }
}

API de NODE

Console

console.log('hello world');

/*Prints: hello world, to stdout*/


console.error(new Error('Whoops, something bad happened'));

/*Prints: [Error: Whoops, something bad happened], to stderr*/

const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);

/*Prints: Danger Will Robinson! Danger!, to stderr*/

Errores

const fs = require('fs');
fs.readFile('a file that does not exist', (err, data) => {
  if (err) {
    console.error('There was an error reading the file!', err);
    return;
  }
});

try {
  const m = 1;
  const n = 0;
  const x = m / n;
} catch (err) {
    console.error('Error, n is 0');
}

Assert

const assert = require('assert');

assert(true);
/*OK*/
assert(1);
/*OK*/
assert(false);
/*throws "AssertionError: false == true"*/
assert(0);
/*throws "AssertionError: 0 == true"*/
assert(false, 'it\'s false');
/*throws "AssertionError: it's false"*/

Crypto

const crypto = require('crypto');

const secret = 'abcdefg';
const hash = crypto.createHmac('sha256', secret)
                   .update('I love cupcakes')
                   .digest('hex');
console.log(hash);

Child Process

const spawn = require('child_process').spawn;
const ls = spawn('ls', ['-lh', '/usr']);

ls.stdout.on('data', (data) => {
  console.log(`stdout: ${data}`);
});

ls.stderr.on('data', (data) => {
  console.log(`stderr: ${data}`);
});

ls.on('close', (code) => {
  console.log(`child process exited with code ${code}`);
});

Process


process.argv;
process.cwd();
process.env.VAR;
process.chdir(directory);
process.getuid();
process.getegid();
process.cpuUsage();
process.kill(pid, signal);

Readline

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question('What do you think of Node.js? ', (answer) => {
  /*TODO: Log the answer in a database*/
  console.log(`Thank you for your valuable feedback: ${answer}`);

  rl.close();
});

Google API

Google API

  1. Google Analytics API

  2. Blogger API

  3. CustomSearch API

  4. Drive API

  5. Glass Mirror API

  6. URL Shortener API

  7. YouTube API

  8. Gmail API

Gracias por su atención