mirror of
https://github.com/clarencechaan/ufc-cal.git
synced 2026-10-19 08:38:30 -07:00
Add node_modules
This commit is contained in:
1 parent
1df571f777
commit
c01615d999
530 files changed
+38186
No files matched your search
+17
@@ -0,0 +1,17 @@
|
||||
## [2.0.4](https://github.com/jquense/expr/compare/v2.0.3...v2.0.4) (2020-08-26)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [2.0.3](https://github.com/jquense/expr/compare/v2.0.2...v2.0.3) (2020-08-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* prototype polution vector ([df84691](https://github.com/jquense/expr/commit/df846910915d59f711ce63c1f817815bceab5ff7))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Jason Quense
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
# expr
|
||||
|
||||
Tiny property path utilities, including path parsing and metadata and deep property setters and getters
|
||||
|
||||
npm install property-expr
|
||||
|
||||
## Use
|
||||
|
||||
Setters and getters:
|
||||
|
||||
```js
|
||||
let expr = require('property-expr')
|
||||
let obj = {
|
||||
foo: {
|
||||
bar: ['hi', { buz: { baz: 'found me!' } }]
|
||||
}
|
||||
}
|
||||
|
||||
let getBaz = expr.getter('foo.bar[1]["buz"].baz')
|
||||
let setBaz = expr.setter('foo.bar[1]["buz"].baz')
|
||||
|
||||
console.log(getBaz(obj)) // => 'found me!'
|
||||
setBaz(obj, 'set me!')
|
||||
console.log(obj.foo.bar[1].buz.baz) // => 'set me!'
|
||||
```
|
||||
|
||||
### `getter(expression, [ safeAccess ])`
|
||||
|
||||
Returns a function that accepts an obj and returns the value at the supplied expression. You can create a "safe" getter, which won't error out when accessing properties that don't exist, reducing existance checks befroe property access:
|
||||
|
||||
```js
|
||||
expr.getter('foo.bar.baz', true)({ foo: {} }) // => undefined
|
||||
//instead of val = foo.bar && foo.bar.baz
|
||||
```
|
||||
|
||||
### `setter(expression)`
|
||||
|
||||
Returns a function that accepts an obj and a value and sets the property pointed to by the expression to the supplied value.
|
||||
|
||||
### `expr(expression, [ safeAccess], [ paramName = 'data'])`
|
||||
|
||||
Returns a normalized expression string pointing to a property on root object
|
||||
`paramName`.
|
||||
|
||||
expr.expr("foo['bar'][0].baz", true, 'obj') // => "(((obj.foo || {})['bar'] || {})[0])"
|
||||
|
||||
### `split(path) -> Array`
|
||||
|
||||
Returns an array of each path segment.
|
||||
|
||||
```js
|
||||
expr.split("foo['bar'][0].baz") // [ "foo", "'bar'", "0", "baz"]
|
||||
```
|
||||
|
||||
### `forEach(path, iterator[, thisArg])`
|
||||
|
||||
Iterate through a path but segment, with some additional helpful metadata about the segment. The iterator function is called with: `pathSegment`, `isBracket`, `isArray`, `idx`, `segments`
|
||||
|
||||
```js
|
||||
expr.forEach('foo["bar"][1]', function(
|
||||
pathSegment,
|
||||
isBracket,
|
||||
isArray,
|
||||
idx,
|
||||
segments
|
||||
) {
|
||||
// 'foo' -> isBracket = false, isArray = false, idx = 0
|
||||
// '"bar"' -> isBracket = true, isArray = false, idx = 1
|
||||
// '0' -> isBracket = false, isArray = true, idx = 2
|
||||
})
|
||||
```
|
||||
|
||||
### `normalizePath(path)`
|
||||
|
||||
Returns an array of path segments without quotes and spaces.
|
||||
|
||||
```js
|
||||
expr.normalizePath('foo["bar"][ "1" ][2][ " sss " ]')
|
||||
// ['foo', 'bar', '1', '2', ' sss ']
|
||||
```
|
||||
|
||||
### `new Cache(maxSize)`
|
||||
|
||||
Just an utility class, returns an instance of cache. When the max size is exceeded, cache clears its storage.
|
||||
|
||||
```js
|
||||
var cache = new Cache(2)
|
||||
cache.set('a', 123) // returns 123
|
||||
cache.get('a') // returns 123
|
||||
cache.clear()
|
||||
|
||||
cache.set('a', 1)
|
||||
cache.set('b', 2) // cache contains 2 values
|
||||
cache.set('c', 3) // cache was cleaned automatically and contains 1 value
|
||||
```
|
||||
|
||||
### CSP
|
||||
|
||||
This pacakge used to rely on `new Function` to compile setters and getters into fast
|
||||
reusable functions. Since `new Function` is forbidden by folks using Content Security Policy `unsafe-eval`
|
||||
we've moved away from that approach. I believe that for most cases the perf hit is not noticable
|
||||
but if it is in your case please reach out.
|
||||
|
||||
If you really want to use the old version require `property-expr/compiler` instead
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
var { Cache, normalizePath, split, forEach } = require('./')
|
||||
|
||||
var setCache = new Cache(512),
|
||||
getCache = new Cache(512)
|
||||
|
||||
function makeSafe(path, param) {
|
||||
var result = param,
|
||||
parts = split(path),
|
||||
isLast
|
||||
|
||||
forEach(parts, function (part, isBracket, isArray, idx, parts) {
|
||||
isLast = idx === parts.length - 1
|
||||
|
||||
part = isBracket || isArray ? '[' + part + ']' : '.' + part
|
||||
|
||||
result += part + (!isLast ? ' || {})' : ')')
|
||||
})
|
||||
|
||||
return new Array(parts.length + 1).join('(') + result
|
||||
}
|
||||
|
||||
function expr(expression, safe, param) {
|
||||
expression = expression || ''
|
||||
|
||||
if (typeof safe === 'string') {
|
||||
param = safe
|
||||
safe = false
|
||||
}
|
||||
|
||||
param = param || 'data'
|
||||
|
||||
if (expression && expression.charAt(0) !== '[') expression = '.' + expression
|
||||
|
||||
return safe ? makeSafe(expression, param) : param + expression
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
expr,
|
||||
setter: function (path) {
|
||||
if (
|
||||
path.indexOf('__proto__') !== -1 ||
|
||||
path.indexOf('constructor') !== -1 ||
|
||||
path.indexOf('prototype') !== -1
|
||||
) {
|
||||
return (obj) => obj
|
||||
}
|
||||
|
||||
return (
|
||||
setCache.get(path) ||
|
||||
setCache.set(
|
||||
path,
|
||||
new Function('data, value', expr(path, 'data') + ' = value')
|
||||
)
|
||||
)
|
||||
},
|
||||
|
||||
getter: function (path, safe) {
|
||||
var key = path + '_' + safe
|
||||
return (
|
||||
getCache.get(key) ||
|
||||
getCache.set(
|
||||
key,
|
||||
new Function('data', 'return ' + expr(path, safe, 'data'))
|
||||
)
|
||||
)
|
||||
},
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
export interface Cache {
|
||||
set(key: string, value: any): value
|
||||
get(key: string): any
|
||||
clear(): void
|
||||
}
|
||||
|
||||
export interface Expr {
|
||||
setConfig(config: { contentSecurityPolicy: boolean }): void
|
||||
|
||||
Cache: {
|
||||
new (maxSize: number): Cache
|
||||
}
|
||||
|
||||
split(path: string): string[]
|
||||
setter(path: string): (data: any, value: any) => any
|
||||
getter(path: string, safe?: boolean): (data: any) => any
|
||||
join(segments: string[]): string
|
||||
forEach(
|
||||
path: string | string[],
|
||||
callback: (
|
||||
part: string,
|
||||
isBracket: boolean,
|
||||
isArray: boolean,
|
||||
idx: number,
|
||||
parts: string[]
|
||||
) => any
|
||||
): void
|
||||
}
|
||||
|
||||
declare const expr: Expr
|
||||
export = expr
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
* Based on Kendo UI Core expression code <https://github.com/telerik/kendo-ui-core#license-information>
|
||||
*/
|
||||
'use strict'
|
||||
|
||||
function Cache(maxSize) {
|
||||
this._maxSize = maxSize
|
||||
this.clear()
|
||||
}
|
||||
Cache.prototype.clear = function () {
|
||||
this._size = 0
|
||||
this._values = Object.create(null)
|
||||
}
|
||||
Cache.prototype.get = function (key) {
|
||||
return this._values[key]
|
||||
}
|
||||
Cache.prototype.set = function (key, value) {
|
||||
this._size >= this._maxSize && this.clear()
|
||||
if (!(key in this._values)) this._size++
|
||||
|
||||
return (this._values[key] = value)
|
||||
}
|
||||
|
||||
var SPLIT_REGEX = /[^.^\]^[]+|(?=\[\]|\.\.)/g,
|
||||
DIGIT_REGEX = /^\d+$/,
|
||||
LEAD_DIGIT_REGEX = /^\d/,
|
||||
SPEC_CHAR_REGEX = /[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g,
|
||||
CLEAN_QUOTES_REGEX = /^\s*(['"]?)(.*?)(\1)\s*$/,
|
||||
MAX_CACHE_SIZE = 512
|
||||
|
||||
var pathCache = new Cache(MAX_CACHE_SIZE),
|
||||
setCache = new Cache(MAX_CACHE_SIZE),
|
||||
getCache = new Cache(MAX_CACHE_SIZE)
|
||||
|
||||
var config
|
||||
|
||||
module.exports = {
|
||||
Cache: Cache,
|
||||
|
||||
split: split,
|
||||
|
||||
normalizePath: normalizePath,
|
||||
|
||||
setter: function (path) {
|
||||
var parts = normalizePath(path)
|
||||
|
||||
return (
|
||||
setCache.get(path) ||
|
||||
setCache.set(path, function setter(obj, value) {
|
||||
var index = 0
|
||||
var len = parts.length
|
||||
var data = obj
|
||||
|
||||
while (index < len - 1) {
|
||||
var part = parts[index]
|
||||
if (
|
||||
part === '__proto__' ||
|
||||
part === 'constructor' ||
|
||||
part === 'prototype'
|
||||
) {
|
||||
return obj
|
||||
}
|
||||
|
||||
data = data[parts[index++]]
|
||||
}
|
||||
data[parts[index]] = value
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
getter: function (path, safe) {
|
||||
var parts = normalizePath(path)
|
||||
return (
|
||||
getCache.get(path) ||
|
||||
getCache.set(path, function getter(data) {
|
||||
var index = 0,
|
||||
len = parts.length
|
||||
while (index < len) {
|
||||
if (data != null || !safe) data = data[parts[index++]]
|
||||
else return
|
||||
}
|
||||
return data
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
join: function (segments) {
|
||||
return segments.reduce(function (path, part) {
|
||||
return (
|
||||
path +
|
||||
(isQuoted(part) || DIGIT_REGEX.test(part)
|
||||
? '[' + part + ']'
|
||||
: (path ? '.' : '') + part)
|
||||
)
|
||||
}, '')
|
||||
},
|
||||
|
||||
forEach: function (path, cb, thisArg) {
|
||||
forEach(Array.isArray(path) ? path : split(path), cb, thisArg)
|
||||
},
|
||||
}
|
||||
|
||||
function normalizePath(path) {
|
||||
return (
|
||||
pathCache.get(path) ||
|
||||
pathCache.set(
|
||||
path,
|
||||
split(path).map(function (part) {
|
||||
return part.replace(CLEAN_QUOTES_REGEX, '$2')
|
||||
})
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
function split(path) {
|
||||
return path.match(SPLIT_REGEX) || ['']
|
||||
}
|
||||
|
||||
function forEach(parts, iter, thisArg) {
|
||||
var len = parts.length,
|
||||
part,
|
||||
idx,
|
||||
isArray,
|
||||
isBracket
|
||||
|
||||
for (idx = 0; idx < len; idx++) {
|
||||
part = parts[idx]
|
||||
|
||||
if (part) {
|
||||
if (shouldBeQuoted(part)) {
|
||||
part = '"' + part + '"'
|
||||
}
|
||||
|
||||
isBracket = isQuoted(part)
|
||||
isArray = !isBracket && /^\d+$/.test(part)
|
||||
|
||||
iter.call(thisArg, part, isBracket, isArray, idx, parts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isQuoted(str) {
|
||||
return (
|
||||
typeof str === 'string' && str && ["'", '"'].indexOf(str.charAt(0)) !== -1
|
||||
)
|
||||
}
|
||||
|
||||
function hasLeadingNumber(part) {
|
||||
return part.match(LEAD_DIGIT_REGEX) && !part.match(DIGIT_REGEX)
|
||||
}
|
||||
|
||||
function hasSpecialChars(part) {
|
||||
return SPEC_CHAR_REGEX.test(part)
|
||||
}
|
||||
|
||||
function shouldBeQuoted(part) {
|
||||
return !isQuoted(part) && (hasLeadingNumber(part) || hasSpecialChars(part))
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "property-expr",
|
||||
"version": "2.0.5",
|
||||
"description": "tiny util for getting and setting deep object props safely",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"compiler.js"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "node ./test.js",
|
||||
"debug": "node --inspect-brk ./test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jquense/expr/"
|
||||
},
|
||||
"keywords": [
|
||||
"expr",
|
||||
"expression",
|
||||
"setter",
|
||||
"getter",
|
||||
"deep",
|
||||
"property",
|
||||
"Justin-Beiber",
|
||||
"accessor"
|
||||
],
|
||||
"author": "@monasticpanic Jason Quense",
|
||||
"license": "MIT",
|
||||
"prettier": {
|
||||
"singleQuote": true,
|
||||
"semi": false
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user