Comparing version 0.6.2 to 1.0.0
{ | ||
"name": "abl-utils", | ||
"title": "ABL - utils", | ||
"version": "0.6.2", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
@@ -28,7 +28,5 @@ "description": "description", | ||
"debug": "2.2.0", | ||
"escape-string-regexp": "1.0.5", | ||
"lodash": "4.8.2", | ||
"moment-config-trejgun": "git://github.com/TrejGun/moment-config-trejgun.git#v0.0.4", | ||
"qs": "6.1.0", | ||
"rrule": "2.1.0" | ||
"qs": "6.1.0" | ||
}, | ||
@@ -35,0 +33,0 @@ "devDependencies": { |
"use strict"; | ||
import crypto from "crypto"; | ||
import {getObject} from "abl-lang/build/index"; | ||
import configs from "./configs/config"; | ||
export function getType(variable) { | ||
@@ -14,35 +14,13 @@ return Object.prototype.toString.call(variable); | ||
export function getRandomString(length = 64, type = 3) { | ||
const chars = [ | ||
"0123456789", | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
]; | ||
const randomBytes = crypto.randomBytes(length); | ||
const result = new Array(length); | ||
let cursor = 0; | ||
for (let i = 0; i < length; i++) { | ||
cursor += randomBytes[i]; | ||
result[i] = chars[type][cursor % chars[type].length]; | ||
} | ||
return result.join(""); | ||
export function formatUrl({protocol, hostname, port}) { | ||
// url.format puts port 80 which we don't need | ||
return `${protocol}://${hostname}${port === "80" ? "" : `:${port}`}`; | ||
} | ||
export function getRandomElementFromArray(array = []) { | ||
return array[Math.floor(Math.random() * array.length)]; | ||
export function getServerUrl(env = process.env.NODE_ENV) { | ||
return formatUrl(configs[env].server); | ||
} | ||
export function tpl(template, data) { | ||
return template.replace(/(\$\{([^\{\}]+)\})/g, ($0, $1, $2) => getObject($2, data)); | ||
export function getIP(request) { | ||
return request.get("CF-Connecting-IP") || request.ip; | ||
} | ||
export function toDollars(amount) { | ||
return `$${(amount && amount / 100 || 0).toFixed(2)}`; | ||
} | ||
export function formatUrl({protocol, hostname, port}) { | ||
// url.format puts port 80 which we dont need | ||
return `${protocol}://${hostname}${port === "80" ? "" : `:${port}`}`; | ||
} |
@@ -5,10 +5,7 @@ "use strict"; | ||
import querystring from "querystring"; | ||
import {formatUrl} from "./misc"; | ||
import {getServerUrl} from "./misc"; | ||
import {makeError} from "./error"; | ||
import {translate} from "abl-lang"; | ||
import configs from "./configs/config"; | ||
const config = configs[process.env.NODE_ENV]; | ||
function _send(request, response) { | ||
@@ -60,3 +57,3 @@ return (error) => { | ||
const last = Math.ceil(count / request.query.pageSize); | ||
const url = `${formatUrl(config.server)}${request.route.path}?`; | ||
const url = `${getServerUrl()}${request.route.path}?`; | ||
@@ -63,0 +60,0 @@ response.set("X-First-Page-Url", url + querystring.stringify({ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6
0
3
8763
9
192
- Removedescape-string-regexp@1.0.5
- Removedrrule@2.1.0
- Removedescape-string-regexp@1.0.5(transitive)
- Removedrrule@2.1.0(transitive)