Grabbed dndbeyond's source code
``` ~/go/bin/sourcemapper -output ddb -jsurl https://media.dndbeyond.com/character-app/static/js/main.90aa78c5.js ```
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Converts a string from other cases to camelCase
|
||||
* @param string the value to camelCase
|
||||
* @example
|
||||
* camelCase('foo-bar') // 'fooBar'
|
||||
*/
|
||||
export const camelCase = (string: string) => string
|
||||
.replace(/([A-Z])([A-Z])/g, '$1 $2')
|
||||
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
||||
.replace(/[^a-zA-Z\u00C0-\u00ff]/g, ' ')
|
||||
.toLowerCase()
|
||||
.split(' ')
|
||||
.filter(value => value)
|
||||
.map((s, i) => (i > 0 ? s[0].toUpperCase() + s.slice(1) : s))
|
||||
.join('')
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Hashes a value
|
||||
* @param value the value to hash
|
||||
* @param radix the base-n to hash into (default 16)
|
||||
*/
|
||||
export const hash = (value: string = '', radix: number = 16): string => {
|
||||
const string = String(value)
|
||||
let h = 0
|
||||
string.split('').forEach((char: string) => {
|
||||
/* eslint-disable no-bitwise */
|
||||
h = ((h << 5) - h) + char.charCodeAt(0)
|
||||
h &= h // Convert to 32-bit integer
|
||||
/* eslint-enable no-bitwise */
|
||||
})
|
||||
return Math.abs(h).toString(radix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Hashes a Math.random() value, returning it in base16
|
||||
*/
|
||||
export const randomHash = () => hash(Math.random().toString())
|
||||
@@ -0,0 +1,29 @@
|
||||
import { camelCase } from './camelCase'
|
||||
|
||||
type Style = string | Partial<CSSStyleDeclaration>
|
||||
|
||||
/**
|
||||
* Converts a CSS Style string
|
||||
* @param {string | Partial<CSSStyleDeclaration>} style A string to convert, or object to return
|
||||
* @returns {Partial<CSSStyleDeclaration>} a partial CSSStyleDeclaration
|
||||
*/
|
||||
export const parseStyle = (style: Style): Partial<CSSStyleDeclaration> | undefined => {
|
||||
switch (typeof style) {
|
||||
case 'string':
|
||||
return style.split(';').filter(r => r)
|
||||
.reduce((map, rule) => {
|
||||
const name = rule.slice(0, rule.indexOf(':')).trim()
|
||||
const value = rule.slice(rule.indexOf(':') + 1).trim()
|
||||
|
||||
return {
|
||||
...map,
|
||||
[camelCase(name)]: value,
|
||||
}
|
||||
}, {})
|
||||
case 'object':
|
||||
return style
|
||||
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
const pathToArrayPath = (path: string) => {
|
||||
if (path == null || path === '') return []
|
||||
return path.split('.')
|
||||
}
|
||||
|
||||
const resolveArrayPath = (object: any, path: string[]): string | undefined => {
|
||||
const [property, ...subPath] = path
|
||||
if (object == null || property == null) {
|
||||
return undefined
|
||||
}
|
||||
return subPath.length === 0
|
||||
? object[property]
|
||||
: resolveArrayPath(object[property], subPath)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of a path query from an object
|
||||
* @param {any} object the object to search
|
||||
* @param {string} path the path, whose value will be retrieved
|
||||
* @returns {any} the value (undefined if the path doesn't exist)
|
||||
* @example
|
||||
* resolvePath({ foo: { bar: { baz: 3 } } }, 'foo.bar.baz') // 3
|
||||
*/
|
||||
export const resolvePath = (object: any, path: string): any => (
|
||||
resolveArrayPath(object, pathToArrayPath(path))
|
||||
)
|
||||
Reference in New Issue
Block a user