Skip to content

Instantly share code, notes, and snippets.

View nicholasxjy's full-sized avatar
🖖
AFK

xue nicholasxjy

🖖
AFK
View GitHub Profile
@nicholasxjy
nicholasxjy / toblob.js
Created November 14, 2017 07:20
base 64 to blob
export function b64toBlob(data, contentType = '', sliceSize = 512) {
const byteCharacters = atob(data)
const byteArrays = []
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize)
const byteNumbers = new Array(slice.length)
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i)
}
const byteArray = new Uint8Array(byteNumbers)
[
{
"name": {
"en": {
"official": "Republic of Albania",
"common": "Albania"
},
"zh": {
"official": "阿尔巴尼亚共和国",
"common": "阿尔巴尼亚"
[
{
"name": {
"en": {
"official": "Republic of Albania",
"common": "Albania"
},
"zh": {
"official": "阿尔巴尼亚共和国",
"common": "阿尔巴尼亚"
@nicholasxjy
nicholasxjy / titleCase.js
Created May 9, 2017 03:32
titlecase string in js
function titleCase(str) {
str = str.toLowerCase()
return str.charAt(0).toUpperCase() + str.slice(1)
}
<link rel="icon" type="image/png" href="./src/favicon.png">
@nicholasxjy
nicholasxjy / numWithCommas.js
Created March 1, 2017 02:31
format number with commas
export function numberWithCommas(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
@nicholasxjy
nicholasxjy / formatTime.js
Created March 1, 2017 02:29
generic format time
function parseTime(time, format = 'y-m-d h:i:s') {
if (!time) {
return '0000-00-00 00:00:00'
}
const date = time instanceof Date ? time : new Date(parseInt(time, 10))
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,