jquense / expr Goto Github PK
View Code? Open in Web Editor NEWtiny util for getting and setting deep object props safely
License: MIT License
tiny util for getting and setting deep object props safely
License: MIT License
Here's an example of an issue similar to #2 where the property name begins with a number and results in SyntaxError: Invalid or unexpected token
.
My specific use case is working with the yup library to validate a schema. I have a series of properties that begin with numbers (thanks, Salesforce). So given path = '00N40000002S5U0'
, the result of calling expr()
is (data.00N40000002S5U0)
, which clearly won't work. Before taking a crack at a PR, I'd just like to understand if it's reasonable to think this library should be able to build a valid expression for cases like this?
You know we can have objects with keys with more than alphanumeric characters, like:
const externalIdentifier: 'FE43-D880-21AE';
const data = {
[externalIdentifier]: true
};
When we use the getter
to access that id, it throws an error exception:
const getFn = getter(externalIdentifier);
console.log(getFn(data);
Error:
Uncaught ReferenceError: D880 is not defined
at eval (eval at getter (:26:43), :3:16)
at :1:1
Getting Failed to compile during npm run build in my react app because of line 55 in index.js. I cannot use react-scripts as I am using a custom script. Suggested change - use of 'var' instead of 'let'.
I started to use bun by many reasons. and first notices that it throw error
viktord@blade:~/Projects/renthome/dashboard$ bun run build
$ vite build
vite v4.4.11 building for production...
✓ 1858 modules transformed.
✓ built in 8.21s
"getter" is not exported by "node_modules/property-expr/index.js", imported by "node_modules/yup/index.esm.js".
file: /home/viktord/Projects/renthome/dashboard/node_modules/yup/index.esm.js:1:9
1: import { getter, forEach, split, normalizePath, join } from 'property-expr';
^
2: import { camelCase, snakeCase } from 'tiny-case';
3: import toposort from 'toposort';
error during build:
RollupError: "getter" is not exported by "node_modules/property-expr/index.js", imported by "node_modules/yup/index.esm.js".
at error (file:///home/viktord/Projects/renthome/dashboard/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
at Module.error (file:///home/viktord/Projects/renthome/dashboard/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:13745:16)
at Module.traceVariable (file:///home/viktord/Projects/renthome/dashboard/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:14175:29)
at ModuleScope.findVariable (file:///home/viktord/Projects/renthome/dashboard/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:12615:39)
at ChildScope.findVariable (file:///home/viktord/Projects/renthome/dashboard/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
at ClassBodyScope.findVariable (file:///home/viktord/Projects/renthome/dashboard/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
at ChildScope.findVariable (file:///home/viktord/Projects/renthome/dashboard/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
at FunctionScope.findVariable (file:///home/viktord/Projects/renthome/dashboard/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
at ChildScope.findVariable (file:///home/viktord/Projects/renthome/dashboard/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7124:38)
at Identifier.bind (file:///home/viktord/Projects/renthome/dashboard/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:8319:40)
error: script "build" exited with code 1 (SIGHUP)
I am also using nodejs v20
I think we already have PR to fix it
https://github.com/jquense/expr/pull/16/files
How can I assist to merge this PR?
The actual path expressions syntax does not seem to be explicitly documented anywhere that I can see.
Hi,
I'm using react-formal with yup, and while hardening my app's CSP rules to drop unsafe-eval
(reference), I'm seeing explosions because this library uses new Function(...)
which isn't allowed with that kind of CSP setup.
Any chance doing something else here instead, to make this compatible with stricter CSP rules (which are assumably becoming more common)?
Currently I'm not seeing good ways around this in my end, seems that I need to choose between dropping react-formal and yup or to live with unsafe-eval
in CSP (and justify that to the party evaluating the security of my app).
It would be useful to be able to select into arrays, eg. people[].name
or people[*].name
to get an array of the contents all the name
properties of objects in the people
array.
I am currently working on a custom validator for yup
that will need to read the the a name property from an object array to validate some other fields in the form. I have ideas on how to work around this, but it would be useful to be be able to simple to do this using a Ref
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.