Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert online code javascript to python

var bigint = require( 'big-integer' )

var lower = 'abcdefghijklmnopqrstuvwxyz';
var upper = lower.toUpperCase();
var numbers = '0123456789'
var ig_alphabet =  upper + lower + numbers + '-_'
var bigint_alphabet = numbers + lower

function toShortcode( longid )
{
	var o = bigint( longid ).toString( 64 )
	return o.replace(/<(d+)>|(w)/g, (m,m1,m2) =>
	{
		return ig_alphabet.charAt( ( m1 )
		  ? parseInt( m1 ) 
		  : bigint_alphabet.indexOf( m2 ) )
	});
}

function fromShortcode( shortcode )
{
	var o = shortcode.replace( /S/g, m =>
	{
		var c = ig_alphabet.indexOf( m )
		var b = bigint_alphabet.charAt( c ) 
		return ( b != "" ) ? b : `<${c}>`
	} )	
	return bigint( o, 64 ).toString( 10 )
}

toShortcode(  '908540701891980503' ) // s.b. 'ybyPRoQWzX'
fromShortcode( 'ybyPRoQWzX' ) // s.b. '908540701891980503'
Comment

convert online code javascript to python

var bigint = require( 'big-integer' )

var lower = 'abcdefghijklmnopqrstuvwxyz';
var upper = lower.toUpperCase();
var numbers = '0123456789'
var ig_alphabet =  upper + lower + numbers + '-_'
var bigint_alphabet = numbers + lower

function toShortcode( longid )
{
	var o = bigint( longid ).toString( 64 )
	return o.replace(/<(d+)>|(w)/g, (m,m1,m2) =>
	{
		return ig_alphabet.charAt( ( m1 )
		  ? parseInt( m1 ) 
		  : bigint_alphabet.indexOf( m2 ) )
	});
}

function fromShortcode( shortcode )
{
	var o = shortcode.replace( /S/g, m =>
	{
		var c = ig_alphabet.indexOf( m )
		var b = bigint_alphabet.charAt( c ) 
		return ( b != "" ) ? b : `<${c}>`
	} )	
	return bigint( o, 64 ).toString( 10 )
}

toShortcode(  '908540701891980503' ) // s.b. 'ybyPRoQWzX'
fromShortcode( 'ybyPRoQWzX' ) // s.b. '908540701891980503'
Comment

PREVIOUS NEXT
Code Example
Javascript :: can you push more than one item javascript 
Javascript :: Search products by startsWith in javascript 
Javascript :: Find specific string by using includes in javascript 
Javascript :: javascript uuid generator 
Javascript :: Import Bootstrap to React Redux CRUD App 
Javascript :: javascript get each element count / occurrences / frequency from a list 
Javascript :: git revision 
Javascript :: on inline style change 
Javascript :: Check for particular values in the response body 
Javascript :: random bigint javascript 
Javascript :: FTP upload local file 
Javascript :: how to Initialize and fill an array with the specified values in javascript 
Javascript :: convert promise to generator js 
Javascript :: connect to local mongodb node 
Javascript :: nodejs pub sub redis 
Javascript :: kube allow pod deployment on master node 
Javascript :: modify a string in javascript 
Javascript :: if else condition in angular if user enter string value in input integer 
Javascript :: function for making something invisible in gdscript 
Javascript :: javascript Big decimal 
Javascript :: array object make api format javascript 
Javascript :: how to get author in wordpress api react 
Javascript :: Make an array from the HTML Collection to make it iterable 
Javascript :: fiffo in javascript 
Javascript :: code mirror detect change 
Javascript :: pass data from popup js 
Javascript :: datatable editable row update other cell 
Javascript :: id always returing null angular 
Javascript :: angular optional attribute binding 
Javascript :: Method definition shorthand in ES6 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =