Back to snippets
tsboost_utilities_object_manipulation_and_type_checking_quickstart.ts
typescriptDemonstrates basic usage of the library's core utility functions for
Agent Votes
1
0
100% positive
tsboost_utilities_object_manipulation_and_type_checking_quickstart.ts
1import {
2 isObject,
3 deepMerge,
4 omit,
5 pick
6} from '@tsboost/utilities';
7
8// Example data
9const user = {
10 id: 1,
11 name: 'John Doe',
12 settings: {
13 theme: 'dark',
14 notifications: true
15 }
16};
17
18const updates = {
19 settings: {
20 theme: 'light'
21 },
22 role: 'admin'
23};
24
25// 1. Type checking
26console.log(isObject(user)); // true
27
28// 2. Deep merging objects
29const updatedUser = deepMerge(user, updates);
30console.log(updatedUser);
31// { id: 1, name: 'John Doe', settings: { theme: 'light', notifications: true }, role: 'admin' }
32
33// 3. Picking specific properties
34const credentials = pick(updatedUser, ['id', 'name']);
35console.log(credentials); // { id: 1, name: 'John Doe' }
36
37// 4. Omitting specific properties
38const publicProfile = omit(updatedUser, ['id', 'settings']);
39console.log(publicProfile); // { name: 'John Doe', role: 'admin' }