or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

array.mdcrypto.mddate.mdfs.mdfunction.mdindex.mdjson.mdnumber.mdobject.mdoptimize.mdstring.mdtimeout.mdweb.md

object.mddocs/

0

# Object Utilities

1

2

High-performance object operations including assignment, property enumeration, ownership checking, and clean object creation optimized for performance-critical applications.

3

4

## Capabilities

5

6

### High-Performance Object Assignment

7

8

Fast object assignment implementation optimized for performance before Node.js 6.

9

10

```typescript { .api }

11

/**

12

* High performance object assignment

13

* @param target - Target object to assign properties to

14

* @param objects - Source object(s) to assign from

15

* @returns Modified target object

16

*/

17

function assign(target: any, objects: any | any[]): any;

18

```

19

20

**Usage Examples:**

21

22

```typescript

23

import { assign } from "utility";

24

25

// Single source object

26

const target1 = { a: 1 };

27

const result1 = assign(target1, { b: 2, c: 3 });

28

// Result: { a: 1, b: 2, c: 3 }

29

30

// Multiple source objects

31

const target2 = { x: 'original' };

32

const result2 = assign(target2, [

33

{ y: 'first' },

34

{ z: 'second' },

35

{ x: 'overwritten' }

36

]);

37

// Result: { x: 'overwritten', y: 'first', z: 'second' }

38

39

// With null/undefined sources (safely ignored)

40

const target3 = { safe: true };

41

const result3 = assign(target3, [null, { added: 'value' }, undefined]);

42

// Result: { safe: true, added: 'value' }

43

44

// Modifies target object

45

const original = { keep: 'me' };

46

assign(original, { new: 'property' });

47

console.log(original); // { keep: 'me', new: 'property' }

48

```

49

50

### Property Ownership Check

51

52

Check if object has own property (not inherited) using proper prototype method.

53

54

```typescript { .api }

55

/**

56

* Check if object has own property

57

* @param obj - Object to check

58

* @param prop - Property name to check

59

* @returns True if object has own property

60

*/

61

function has(obj: object, prop: string): boolean;

62

```

63

64

**Usage Examples:**

65

66

```typescript

67

import { has } from "utility";

68

69

// Basic property check

70

const obj = { name: 'test', value: 42 };

71

const hasName = has(obj, 'name');

72

// Result: true

73

74

const hasAge = has(obj, 'age');

75

// Result: false

76

77

// Inherited properties

78

class Parent {

79

parentProp = 'inherited';

80

}

81

class Child extends Parent {

82

childProp = 'own';

83

}

84

85

const child = new Child();

86

const hasOwn = has(child, 'childProp');

87

// Result: true

88

89

const hasInherited = has(child, 'parentProp');

90

// Result: false (inherited, not own)

91

92

// Safe checking

93

const hasToString = has(obj, 'toString');

94

// Result: false (inherited from Object.prototype)

95

```

96

97

### Enumerable Property Names

98

99

Get all enumerable own property names with optional null/undefined filtering.

100

101

```typescript { .api }

102

/**

103

* Get all enumerable own property names

104

* @param obj - Object to inspect

105

* @param ignoreNull - Ignore null, undefined, or NaN properties

106

* @returns Array of enumerable property names

107

*/

108

function getOwnEnumerables(obj: any, ignoreNull?: boolean): Array<string>;

109

```

110

111

**Usage Examples:**

112

113

```typescript

114

import { getOwnEnumerables } from "utility";

115

116

// Basic enumerable properties

117

const obj1 = { a: 1, b: 2, c: 3 };

118

const props1 = getOwnEnumerables(obj1);

119

// Result: ['a', 'b', 'c']

120

121

// With null/undefined values

122

const obj2 = {

123

valid: 'value',

124

nullProp: null,

125

undefinedProp: undefined,

126

nanProp: NaN,

127

zeroProp: 0

128

};

129

130

const allProps = getOwnEnumerables(obj2);

131

// Result: ['valid', 'nullProp', 'undefinedProp', 'nanProp', 'zeroProp']

132

133

const filteredProps = getOwnEnumerables(obj2, true);

134

// Result: ['valid', 'zeroProp']

135

136

// Non-enumerable properties ignored

137

const obj3 = { visible: 'yes' };

138

Object.defineProperty(obj3, 'hidden', {

139

value: 'no',

140

enumerable: false

141

});

142

143

const enumerables = getOwnEnumerables(obj3);

144

// Result: ['visible'] (hidden not included)

145

146

// Array and non-object handling

147

const arrProps = getOwnEnumerables([1, 2, 3]);

148

// Result: [] (arrays return empty)

149

150

const nullProps = getOwnEnumerables(null);

151

// Result: [] (null returns empty)

152

```

153

154

### Clean Object Creation

155

156

Create clean objects without constructor or prototype pollution.

157

158

```typescript { .api }

159

/**

160

* Generate a clean object with no constructor or __proto__

161

* @param obj - Optional initial object to copy properties from

162

* @returns Clean object without prototype

163

*/

164

function map(obj?: any): Record<string, any>;

165

```

166

167

**Usage Examples:**

168

169

```typescript

170

import { map } from "utility";

171

172

// Empty clean object

173

const clean = map();

174

console.log(clean.constructor); // undefined

175

console.log(clean.__proto__); // null

176

console.log(clean.toString); // undefined

177

178

// Clean object with initial data

179

const cleanWithData = map({ name: 'test', id: 123 });

180

// Result: clean object with name and id properties, no prototype

181

182

// Safe property storage

183

const safeMap = map();

184

safeMap['__proto__'] = 'safe';

185

safeMap['constructor'] = 'safe';

186

safeMap['toString'] = 'safe';

187

// These are just regular properties, not special prototype properties

188

189

// Use case: configuration objects

190

function createConfig(userConfig: any) {

191

const config = map({

192

// Default configuration

193

timeout: 5000,

194

retries: 3,

195

debug: false

196

});

197

198

// Safely add user config

199

if (userConfig) {

200

for (const key in userConfig) {

201

config[key] = userConfig[key];

202

}

203

}

204

205

return config;

206

}

207

208

const userConfig = createConfig({ timeout: 10000, debug: true });

209

// Result: clean object with merged configuration

210

```