1
0
mirror of https://github.com/titanscouting/tra-analysis.git synced 2025-07-28 13:28:50 +00:00
Files
.github
apps
data analysis
website
functions
node_modules
.bin
@firebase
@google-cloud
@grpc
@mrmlnc
@nodelib
@protobufjs
@types
accepts
acorn
acorn-es7-plugin
ajv
ansi-regex
arr-diff
arr-flatten
arr-union
array-filter
array-flatten
array-union
array-uniq
array-unique
arrify
ascli
asn1
assert-plus
assign-symbols
async
asynckit
atob
aws-sign2
aws4
axios
balanced-match
base
bcrypt-pbkdf
body-parser
brace-expansion
braces
buffer-equal-constant-time
buffer-from
bun
bytebuffer
bytes
cache-base
call-me-maybe
call-signature
camelcase
capture-stack-trace
caseless
class-utils
cliui
code-point-at
collection-visit
colour
combined-stream
component-emitter
compressible
concat-map
concat-stream
configstore
content-disposition
content-type
cookie
cookie-signature
copy-descriptor
core-js
core-util-is
cors
create-error-class
crypto-random-string
dashdash
debug
decamelize
decode-uri-component
deep-equal
define-properties
define-property
delayed-stream
depd
destroy
diff-match-patch
dir-glob
dom-storage
dot-prop
duplexify
eastasianwidth
ecc-jsbn
ecdsa-sig-formatter
ee-first
empower
empower-core
encodeurl
end-of-stream
ent
escape-html
espurify
estraverse
etag
expand-brackets
express
extend
extend-shallow
extglob
extsprintf
fast-deep-equal
fast-glob
fast-json-stable-stringify
faye-websocket
fill-range
finalhandler
firebase-admin
firebase-functions
follow-redirects
for-in
forever-agent
form-data
forwarded
fragment-cache
fresh
fs.realpath
functional-red-black-tree
gcp-metadata
gcs-resumable-upload
get-value
getpass
glob
glob-parent
glob-to-regexp
globby
google-auth-library
google-auto-auth
google-gax
google-p12-pem
google-proto-files
graceful-fs
grpc
gtoken
har-schema
har-validator
has-value
has-values
hash-stream-validation
http-errors
http-parser-js
http-signature
iconv-lite
ignore
imurmurhash
indexof
inflight
inherits
invert-kv
ipaddr.js
is
is-accessor-descriptor
is-buffer
is-data-descriptor
is-descriptor
is-extendable
is-extglob
is-fullwidth-code-point
is-glob
is-number
is-obj
is-plain-object
is-stream-ended
is-typedarray
is-windows
isarray
isobject
isstream
jsbn
json-schema
json-schema-traverse
json-stringify-safe
jsonwebtoken
jsprim
lib
CHANGES.md
CONTRIBUTING.md
LICENSE
README.md
package.json
jwa
jws
kind-of
lcid
lodash
lodash.camelcase
lodash.clone
lodash.includes
lodash.isboolean
lodash.isinteger
lodash.isnumber
lodash.isplainobject
lodash.isstring
lodash.merge
lodash.once
log-driver
long
lru-cache
make-dir
map-cache
map-visit
media-typer
merge-descriptors
merge2
methmeth
methods
micromatch
mime
mime-db
mime-types
minimatch
mixin-deep
modelo
ms
nan
nanomatch
negotiator
node-forge
number-is-nan
oauth-sign
object-assign
object-copy
object-keys
object-visit
object.pick
on-finished
once
optjs
os-locale
parseurl
pascalcase
path-dirname
path-is-absolute
path-to-regexp
path-type
performance-now
pify
posix-character-classes
power-assert
power-assert-context-formatter
power-assert-context-reducer-ast
power-assert-context-traversal
power-assert-formatter
power-assert-renderer-assertion
power-assert-renderer-base
power-assert-renderer-comparison
power-assert-renderer-diagram
power-assert-renderer-file
power-assert-util-string-width
process-nextick-args
protobufjs
proxy-addr
pseudomap
psl
pump
pumpify
punycode
qs
range-parser
raw-body
readable-stream
regex-not
repeat-element
repeat-string
request
resolve-url
ret
retry-axios
retry-request
safe-buffer
safe-regex
safer-buffer
send
serve-static
set-value
setprototypeof
signal-exit
slash
snakeize
snapdragon
snapdragon-node
snapdragon-util
source-map
source-map-resolve
source-map-url
split-array-stream
split-string
sshpk
static-extend
statuses
stream-events
stream-shift
string-format-obj
string-width
string_decoder
stringifier
strip-ansi
stubs
through2
to-object-path
to-regex
to-regex-range
tough-cookie
traverse
tslib
tunnel-agent
tweetnacl
type-is
type-name
typedarray
union-value
unique-string
universal-deep-strict-equal
unpipe
unset-value
uri-js
urix
use
util-deprecate
utils-merge
uuid
vary
verror
websocket-driver
websocket-extensions
window-size
wrap-ansi
wrappy
write-file-atomic
xdg-basedir
xmlhttprequest
xtend
y18n
yallist
yargs
index.js
package-lock.json
package.json
node_modules
public
.firebaserc
.gitignore
.runtimeconfig.json
firebase.json
firestore.indexes.json
firestore.rules
package-lock.json
.gitattributes
.gitignore
CONTRIBUTING.md
LICENSE
README.md
tra-analysis/website/functions/node_modules/jsprim
2019-01-06 13:14:45 -06:00
..
2019-01-06 13:14:45 -06:00
2019-01-06 13:14:45 -06:00
2019-01-06 13:14:45 -06:00
2019-01-06 13:14:45 -06:00
2019-01-06 13:14:45 -06:00
2019-01-06 13:14:45 -06:00

jsprim: utilities for primitive JavaScript types

This module provides miscellaneous facilities for working with strings, numbers, dates, and objects and arrays of these basic types.

deepCopy(obj)

Creates a deep copy of a primitive type, object, or array of primitive types.

deepEqual(obj1, obj2)

Returns whether two objects are equal.

isEmpty(obj)

Returns true if the given object has no properties and false otherwise. This is O(1) (unlike Object.keys(obj).length === 0, which is O(N)).

hasKey(obj, key)

Returns true if the given object has an enumerable, non-inherited property called key. For information on enumerability and ownership of properties, see the MDN documentation.

forEachKey(obj, callback)

Like Array.forEach, but iterates enumerable, owned properties of an object rather than elements of an array. Equivalent to:

for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
                callback(key, obj[key]);
        }
}

flattenObject(obj, depth)

Flattens an object up to a given level of nesting, returning an array of arrays of length "depth + 1", where the first "depth" elements correspond to flattened columns and the last element contains the remaining object . For example:

flattenObject({
    'I': {
        'A': {
            'i': {
                'datum1': [ 1, 2 ],
                'datum2': [ 3, 4 ]
            },
            'ii': {
                'datum1': [ 3, 4 ]
            }
        },
        'B': {
            'i': {
                'datum1': [ 5, 6 ]
            },
            'ii': {
                'datum1': [ 7, 8 ],
                'datum2': [ 3, 4 ],
            },
            'iii': {
            }
        }
    },
    'II': {
        'A': {
            'i': {
                'datum1': [ 1, 2 ],
                'datum2': [ 3, 4 ]
            }
        }
    }
}, 3)

becomes:

[
    [ 'I',  'A', 'i',   { 'datum1': [ 1, 2 ], 'datum2': [ 3, 4 ] } ],
    [ 'I',  'A', 'ii',  { 'datum1': [ 3, 4 ] } ],
    [ 'I',  'B', 'i',   { 'datum1': [ 5, 6 ] } ],
    [ 'I',  'B', 'ii',  { 'datum1': [ 7, 8 ], 'datum2': [ 3, 4 ] } ],
    [ 'I',  'B', 'iii', {} ],
    [ 'II', 'A', 'i',   { 'datum1': [ 1, 2 ], 'datum2': [ 3, 4 ] } ]
]

This function is strict: "depth" must be a non-negative integer and "obj" must be a non-null object with at least "depth" levels of nesting under all keys.

flattenIter(obj, depth, func)

This is similar to flattenObject except that instead of returning an array, this function invokes func(entry) for each entry in the array that flattenObject would return. flattenIter(obj, depth, func) is logically equivalent to flattenObject(obj, depth).forEach(func). Importantly, this version never constructs the full array. Its memory usage is O(depth) rather than O(n) (where n is the number of flattened elements).

There's another difference between flattenObject and flattenIter that's related to the special case where depth === 0. In this case, flattenObject omits the array wrapping obj (which is regrettable).

pluck(obj, key)

Fetch nested property "key" from object "obj", traversing objects as needed. For example, pluck(obj, "foo.bar.baz") is roughly equivalent to obj.foo.bar.baz, except that:

  1. If traversal fails, the resulting value is undefined, and no error is thrown. For example, pluck({}, "foo.bar") is just undefined.
  2. If "obj" has property "key" directly (without traversing), the corresponding property is returned. For example, pluck({ 'foo.bar': 1 }, 'foo.bar') is 1, not undefined. This is also true recursively, so pluck({ 'a': { 'foo.bar': 1 } }, 'a.foo.bar') is also 1, not undefined.

randElt(array)

Returns an element from "array" selected uniformly at random. If "array" is empty, throws an Error.

startsWith(str, prefix)

Returns true if the given string starts with the given prefix and false otherwise.

endsWith(str, suffix)

Returns true if the given string ends with the given suffix and false otherwise.

parseInteger(str, options)

Parses the contents of str (a string) as an integer. On success, the integer value is returned (as a number). On failure, an error is returned describing why parsing failed.

By default, leading and trailing whitespace characters are not allowed, nor are trailing characters that are not part of the numeric representation. This behaviour can be toggled by using the options below. The empty string ('') is not considered valid input. If the return value cannot be precisely represented as a number (i.e., is smaller than Number.MIN_SAFE_INTEGER or larger than Number.MAX_SAFE_INTEGER), an error is returned. Additionally, the string '-0' will be parsed as the integer 0, instead of as the IEEE floating point value -0.

This function accepts both upper and lowercase characters for digits, similar to parseInt(), Number(), and strtol(3C).

The following may be specified in options:

Option Type Default Meaning
base number 10 numeric base (radix) to use, in the range 2 to 36
allowSign boolean true whether to interpret any leading + (positive) and - (negative) characters
allowImprecise boolean false whether to accept values that may have lost precision (past MAX_SAFE_INTEGER or below MIN_SAFE_INTEGER)
allowPrefix boolean false whether to interpret the prefixes 0b (base 2), 0o (base 8), 0t (base 10), or 0x (base 16)
allowTrailing boolean false whether to ignore trailing characters
trimWhitespace boolean false whether to trim any leading or trailing whitespace/line terminators
leadingZeroIsOctal boolean false whether a leading zero indicates octal

Note that if base is unspecified, and allowPrefix or leadingZeroIsOctal are, then the leading characters can change the default base from 10. If base is explicitly specified and allowPrefix is true, then the prefix will only be accepted if it matches the specified base. base and leadingZeroIsOctal cannot be used together.

Context: It's tricky to parse integers with JavaScript's built-in facilities for several reasons:

  • parseInt() and Number() by default allow the base to be specified in the input string by a prefix (e.g., 0x for hex).
  • parseInt() allows trailing nonnumeric characters.
  • Number(str) returns 0 when str is the empty string ('').
  • Both functions return incorrect values when the input string represents a valid integer outside the range of integers that can be represented precisely. Specifically, parseInt('9007199254740993') returns 9007199254740992.
  • Both functions always accept - and + signs before the digit.
  • Some older JavaScript engines always interpret a leading 0 as indicating octal, which can be surprising when parsing input from users who expect a leading zero to be insignificant.

While each of these may be desirable in some contexts, there are also times when none of them are wanted. parseInteger() grants greater control over what input's permissible.

iso8601(date)

Converts a Date object to an ISO8601 date string of the form "YYYY-MM-DDTHH:MM:SS.sssZ". This format is not customizable.

parseDateTime(str)

Parses a date expressed as a string, as either a number of milliseconds since the epoch or any string format that Date accepts, giving preference to the former where these two sets overlap (e.g., strings containing small numbers).

hrtimeDiff(timeA, timeB)

Given two hrtime readings (as from Node's process.hrtime()), where timeA is later than timeB, compute the difference and return that as an hrtime. It is illegal to invoke this for a pair of times where timeB is newer than timeA.

hrtimeAdd(timeA, timeB)

Add two hrtime intervals (as from Node's process.hrtime()), returning a new hrtime interval array. This function does not modify either input argument.

hrtimeAccum(timeA, timeB)

Add two hrtime intervals (as from Node's process.hrtime()), storing the result in timeA. This function overwrites (and returns) the first argument passed in.

hrtimeNanosec(timeA), hrtimeMicrosec(timeA), hrtimeMillisec(timeA)

This suite of functions converts a hrtime interval (as from Node's process.hrtime()) into a scalar number of nanoseconds, microseconds or milliseconds. Results are truncated, as with Math.floor().

validateJsonObject(schema, object)

Uses JSON validation (via JSV) to validate the given object against the given schema. On success, returns null. On failure, returns (does not throw) a useful Error object.

extraProperties(object, allowed)

Check an object for unexpected properties. Accepts the object to check, and an array of allowed property name strings. If extra properties are detected, an array of extra property names is returned. If no properties other than those in the allowed list are present on the object, the returned array will be of zero length.

mergeObjects(provided, overrides, defaults)

Merge properties from objects "provided", "overrides", and "defaults". The intended use case is for functions that accept named arguments in an "args" object, but want to provide some default values and override other values. In that case, "provided" is what the caller specified, "overrides" are what the function wants to override, and "defaults" contains default values.

The function starts with the values in "defaults", overrides them with the values in "provided", and then overrides those with the values in "overrides". For convenience, any of these objects may be falsey, in which case they will be ignored. The input objects are never modified, but properties in the returned object are not deep-copied.

For example:

mergeObjects(undefined, { 'objectMode': true }, { 'highWaterMark': 0 })

returns:

{ 'objectMode': true, 'highWaterMark': 0 }

For another example:

mergeObjects(
    { 'highWaterMark': 16, 'objectMode': 7 }, /* from caller */
    { 'objectMode': true },                   /* overrides */
    { 'highWaterMark': 0 });                  /* default */

returns:

{ 'objectMode': true, 'highWaterMark': 16 }

Contributing

See separate contribution guidelines.