how to hide api key in javascript code example

Example 1: Javascript check for hash in URL

if (location.href.indexOf("#") != -1) {
    //current url has a #hash in it
}

Example 2: js delete object in map

my_map.delete(id)

Example 3: javascript uniqie id

function uuid() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  });
}

var userID=uuid();//something like: "ec0c22fa-f909-48da-92cb-db17ecdb91c5"

Example 4: javascript clone object

var sheep={"height":20,"name":"Melvin"};
var clonedSheep=JSON.parse(JSON.stringify(sheep));

//note: cloning like this will not work with some complex objects such as:  Date(), undefined, Infinity
// For complex objects try: lodash's cloneDeep() method or angularJS angular.copy() method

Example 5: C# how to get public key for InternalsVisibleTo

/*
1) Open a command prompt
2) Generate a strong-name key for the project and store it in the file FriendAssemblies.snk:

   sn -k FriendAssemblies.snk

3) Extract the public key from FriendAssemblies.snk and put it into FriendAssemblies.publickey:

   sn -p FriendAssemblies.snk FriendAssemblies.publickey

4) Display the public key stored in the file FriendAssemblies.publickey, and copy it to your clipboard:

   sn -tp FriendAssemblies.publickey
   
5) Update your C# class file with the displayed public key using the "InternalsVisibleTo" attribute:
*/

using System.Runtime.CompilerServices;  
[assembly: InternalsVisibleTo("friend_signed_B, PublicKey=" +
"0024000004800000940000000602000000240000525341310004000001000100e3ae" +
"dce99b7e10823920206f8e46cd5558b4ec7345bd1a5b201ffe71660625dcb8f9a086" +
"87d881c8f65a0dcf042f81475d2e88f3e3e273c8311ee40f952db306c02fbfc5d8bc" +
"6ee1e924e6ec8fe8c01932e0648a0d3e5695134af3bb7fab370d3012d083fa6b8317" +
"9dd3d031053f72fc1f7da8459140b0af5afc4d2804deccb6")]  
internal class Class1  
{  
    ...  
}

Tags:

Php Example