
Security News
Python Tools Are Quickly Adopting the New pylock.toml Standard
pip, PDM, pip-audit, and the packaging library are already adding support for Python’s new lock file format.
@smartlyio/safe-navigation
Advanced tools
type(script) and null safe navigation in json objects
.$
Returns the value or undefined if any value on the path to it is undefined
// yarn ts-node examples/getter.ts
import safe from '../index';
import * as assert from 'assert';
interface A {
a?: { b?: string };
}
const o: A = { a: { b: 'x' } };
assert(safe(o).a.b.$ === 'x');
The optional chaining also takes into account union types.
// yarn ts-node examples/unions.ts
import safe from '../index';
import * as assert from 'assert';
type A = { a: number } | { b: string };
const o: A = { a: 1 };
assert(safe(o).a.$ === 1);
.$set
Returns a new object with the target set to value if the path to value exists
// yarn ts-node examples/set.ts
import safe from '../index';
import * as assert from 'assert';
interface A {
a?: { b?: string };
}
const o: A = { a: { b: 'old' } };
const newValue: A = safe(o).a.b.$set('new');
assert(safe(newValue).a.b.$ === 'new');
.$map
Maps the value at end of the path
// yarn ts-node examples/map.ts
import safe from '../index';
import * as assert from 'assert';
interface A {
a?: { b?: string };
}
const o: A = { a: { b: 'old' } };
const newValue: A = safe(o).a.b.$map((n: any) => n + ' to new');
assert(safe(newValue).a.b.$ === 'old to new');
.$pmap
Returns a new object with the target mapped using a promise returning map function
// yarn ts-node examples/pmap.ts
import safe from '../index';
import * as assert from 'assert';
interface A {
a?: { b?: string };
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async function () {
const o: A = { a: { b: 'x' } };
const result = await safe(o).a.b.$pmap(async value => 'got ' + value);
assert(safe(o).a.b.$ === 'x');
assert(safe(result).a.b.$ === 'got x');
})();
FAQs
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.
Security News
pip, PDM, pip-audit, and the packaging library are already adding support for Python’s new lock file format.
Product
Socket's Go support is now generally available, bringing automatic scanning and deep code analysis to all users with Go projects.
Security News
vlt adds real-time security selectors powered by Socket, enabling developers to query and analyze package risks directly in their dependency graph.