Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
@paxperscientiam/dlv.ts
Advanced tools
Readme
This fork is a TypeScript implementation of dlv.
dlv(obj, keypath)
Safely get a dot-notated path within a nested object, with ability to return a default if the full key path does not exist or the value is "undefined".
Supports ES Modules, CommonJS and globals.
pnpm i @paxperscientiam/dlv.ts
or ...
npm i @paxperscientiam/dlv.ts
or ...
yarn add @paxperscientiam/dlv.ts
Available as dlvTs
from dist/dlv.umd.js
.
@paxperscientiam/dlv.ts
uses a default export.
Code:
export default function dlv<T, K extends Extract<keyof T, string>>(obj: T,
key: K|K[],
def?: any,
p: number = 0): any {
const accessor = (key as string).split ? (key as string).split(".") : (key as string[])
while (obj && p < accessor.length) {
obj = obj[accessor[p++]]
}
return (obj === undefined || p < accessor.length) ? def : obj
}
delve(object, keypath, [default])
import delve from '@paxperscientiam/dlv.ts';
let obj = {
a: {
b: {
c: 1,
d: undefined,
e: null
}
}
};
//use string dot notation for keys
delve(obj, 'a.b.c') === 1;
//or use an array key
delve(obj, ['a', 'b', 'c']) === 1;
delve(obj, 'a.b') === obj.a.b;
//returns undefined if the full key path does not exist and no default is specified
delve(obj, 'a.b.c.f') === undefined;
//optional third parameter for default if the full key in path is missing
delve(obj, 'a.b.c.f', 'foo') === 'foo';
//or if the key exists but the value is undefined
delve(obj, 'a.b.c.d', 'foo') === 'foo';
//Non-truthy defined values are still returned if they exist at the full keypath
delve(obj, 'a.b.c.e', 'foo') === null;
//undefined obj or key returns undefined, unless a default is supplied
delve(undefined, 'a.b.c') === undefined;
delve(undefined, 'a.b.c', 'foo') === 'foo';
delve(obj, undefined, 'foo') === 'foo';
dlv
and very fast.dlv
and is implemented in a very similar manner.FAQs
Safely get a dot-notated property within an object.
We found that @paxperscientiam/dlv.ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.