@ohos-ports/stdlib-buffer 0.0.0-stage → 0.4.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +177 -0
  2. package/NOTICE +1 -0
  3. package/README.md +205 -2
  4. package/SECURITY.md +5 -0
  5. package/alloc-unsafe/README.md +140 -0
  6. package/alloc-unsafe/docs/repl.txt +28 -0
  7. package/alloc-unsafe/docs/types/index.d.ts +47 -0
  8. package/alloc-unsafe/docs/types/test.ts +44 -0
  9. package/alloc-unsafe/lib/has_alloc_unsafe.js +34 -0
  10. package/alloc-unsafe/lib/index.js +52 -0
  11. package/alloc-unsafe/lib/main.js +56 -0
  12. package/alloc-unsafe/lib/polyfill.js +56 -0
  13. package/alloc-unsafe/package.json +67 -0
  14. package/ctor/README.md +182 -0
  15. package/ctor/docs/repl.txt +91 -0
  16. package/ctor/docs/types/index.d.ts +37 -0
  17. package/ctor/docs/types/test.ts +35 -0
  18. package/ctor/lib/index.js +52 -0
  19. package/ctor/lib/main.js +28 -0
  20. package/ctor/lib/polyfill.js +37 -0
  21. package/ctor/package.json +62 -0
  22. package/docs/types/index.d.ts +189 -0
  23. package/from-array/README.md +141 -0
  24. package/from-array/docs/repl.txt +22 -0
  25. package/from-array/docs/types/index.d.ts +42 -0
  26. package/from-array/docs/types/test.ts +42 -0
  27. package/from-array/lib/has_from.js +34 -0
  28. package/from-array/lib/index.js +52 -0
  29. package/from-array/lib/main.js +53 -0
  30. package/from-array/lib/polyfill.js +53 -0
  31. package/from-array/package.json +69 -0
  32. package/from-arraybuffer/README.md +198 -0
  33. package/from-arraybuffer/docs/repl.txt +48 -0
  34. package/from-arraybuffer/docs/types/index.d.ts +64 -0
  35. package/from-arraybuffer/docs/types/test.ts +72 -0
  36. package/from-arraybuffer/lib/has_from.js +35 -0
  37. package/from-arraybuffer/lib/index.js +54 -0
  38. package/from-arraybuffer/lib/main.js +105 -0
  39. package/from-arraybuffer/lib/node_version.js +33 -0
  40. package/from-arraybuffer/lib/polyfill.js +107 -0
  41. package/from-arraybuffer/package.json +69 -0
  42. package/from-buffer/README.md +145 -0
  43. package/from-buffer/docs/repl.txt +23 -0
  44. package/from-buffer/docs/types/index.d.ts +45 -0
  45. package/from-buffer/docs/types/test.ts +47 -0
  46. package/from-buffer/lib/has_from.js +34 -0
  47. package/from-buffer/lib/index.js +56 -0
  48. package/from-buffer/lib/main.js +56 -0
  49. package/from-buffer/lib/polyfill.js +56 -0
  50. package/from-buffer/package.json +67 -0
  51. package/from-string/README.md +158 -0
  52. package/from-string/docs/repl.txt +28 -0
  53. package/from-string/docs/types/index.d.ts +42 -0
  54. package/from-string/docs/types/test.ts +55 -0
  55. package/from-string/lib/has_from.js +34 -0
  56. package/from-string/lib/index.js +52 -0
  57. package/from-string/lib/main.js +60 -0
  58. package/from-string/lib/polyfill.js +60 -0
  59. package/from-string/package.json +66 -0
  60. package/lib/index.js +114 -0
  61. package/package.json +63 -4
  62. package/reviver/README.md +137 -0
  63. package/reviver/docs/repl.txt +32 -0
  64. package/reviver/docs/types/index.d.ts +41 -0
  65. package/reviver/docs/types/test.ts +49 -0
  66. package/reviver/lib/index.js +43 -0
  67. package/reviver/lib/main.js +58 -0
  68. package/reviver/package.json +73 -0
  69. package/to-json/README.md +142 -0
  70. package/to-json/docs/repl.txt +31 -0
  71. package/to-json/docs/types/index.d.ts +46 -0
  72. package/to-json/docs/types/test.ts +47 -0
  73. package/to-json/lib/index.js +44 -0
  74. package/to-json/lib/main.js +63 -0
  75. package/to-json/package.json +69 -0
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isFunction = require( '@stdlib/assert/is-function' );
24
+ var Buffer = require( './../../ctor' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ var bool = isFunction( Buffer.allocUnsafe );
30
+
31
+
32
+ // EXPORTS //
33
+
34
+ module.exports = bool;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ /**
22
+ * Allocate a buffer having a specified number of bytes.
23
+ *
24
+ * @module @stdlib/buffer/alloc-unsafe
25
+ *
26
+ * @example
27
+ * var allocUnsafe = require( '@stdlib/buffer/alloc-unsafe' );
28
+ *
29
+ * var buf = allocUnsafe( 10 );
30
+ * // returns <Buffer>
31
+ */
32
+
33
+ // MODULES //
34
+
35
+ var hasAllocUnsafe = require( './has_alloc_unsafe.js' );
36
+ var main = require( './main.js' );
37
+ var polyfill = require( './polyfill.js' );
38
+
39
+
40
+ // MAIN //
41
+
42
+ var allocUnsafe;
43
+ if ( hasAllocUnsafe ) {
44
+ allocUnsafe = main;
45
+ } else {
46
+ allocUnsafe = polyfill;
47
+ }
48
+
49
+
50
+ // EXPORTS //
51
+
52
+ module.exports = allocUnsafe;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' );
24
+ var format = require( '@stdlib/string/format' );
25
+ var Buffer = require( './../../ctor' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ /**
31
+ * Allocates a buffer having a specified number of bytes.
32
+ *
33
+ * ## Notes
34
+ *
35
+ * - The underlying memory of returned `Buffer` instances is not initialized. Memory contents are unknown and may contain sensitive data.
36
+ * - When the size is less than half the pool size (specified on the `Buffer` constructor), memory is allocated from the `Buffer` pool for faster allocation of new `Buffer` instances.
37
+ *
38
+ * @param {NonNegativeInteger} size - number of bytes to allocate
39
+ * @throws {TypeError} must provide a nonnegative integer
40
+ * @returns {Buffer} new `Buffer` instance
41
+ *
42
+ * @example
43
+ * var buf = allocUnsafe( 10 );
44
+ * // returns <Buffer>
45
+ */
46
+ function allocUnsafe( size ) {
47
+ if ( !isNonNegativeInteger( size ) ) {
48
+ throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', size ) );
49
+ }
50
+ return Buffer.allocUnsafe( size );
51
+ }
52
+
53
+
54
+ // EXPORTS //
55
+
56
+ module.exports = allocUnsafe;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' );
24
+ var format = require( '@stdlib/string/format' );
25
+ var Buffer = require( './../../ctor' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ /**
31
+ * Allocates a buffer having a specified number of bytes.
32
+ *
33
+ * ## Notes
34
+ *
35
+ * - The underlying memory of returned `Buffer` instances is not initialized. Memory contents are unknown and may contain sensitive data.
36
+ * - When the size is less than half the pool size (specified on the `Buffer` constructor), memory is allocated from the `Buffer` pool for faster allocation of new `Buffer` instances.
37
+ *
38
+ * @param {NonNegativeInteger} size - number of bytes to allocate
39
+ * @throws {TypeError} must provide a nonnegative integer
40
+ * @returns {Buffer} new `Buffer` instance
41
+ *
42
+ * @example
43
+ * var buf = allocUnsafe( 10 );
44
+ * // returns <Buffer>
45
+ */
46
+ function allocUnsafe( size ) {
47
+ if ( !isNonNegativeInteger( size ) ) {
48
+ throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', size ) );
49
+ }
50
+ return new Buffer( size );
51
+ }
52
+
53
+
54
+ // EXPORTS //
55
+
56
+ module.exports = allocUnsafe;
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@stdlib/buffer/alloc-unsafe",
3
+ "version": "0.0.0",
4
+ "description": "Allocate a buffer having a specified number of bytes.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "directories": {
18
+ "benchmark": "./benchmark",
19
+ "doc": "./docs",
20
+ "example": "./examples",
21
+ "lib": "./lib",
22
+ "test": "./test"
23
+ },
24
+ "types": "./docs/types",
25
+ "scripts": {},
26
+ "homepage": "https://github.com/stdlib-js/stdlib",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git://github.com/stdlib-js/stdlib.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/stdlib-js/stdlib/issues"
33
+ },
34
+ "dependencies": {},
35
+ "devDependencies": {},
36
+ "engines": {
37
+ "node": ">=0.10.0",
38
+ "npm": ">2.7.0"
39
+ },
40
+ "os": [
41
+ "aix",
42
+ "darwin",
43
+ "freebsd",
44
+ "linux",
45
+ "macos",
46
+ "openbsd",
47
+ "openharmony",
48
+ "sunos",
49
+ "win32",
50
+ "windows"
51
+ ],
52
+ "keywords": [
53
+ "stdlib",
54
+ "stdtypes",
55
+ "types",
56
+ "data",
57
+ "structure",
58
+ "buffer",
59
+ "buf",
60
+ "binary",
61
+ "octets",
62
+ "reallocate",
63
+ "allocate",
64
+ "alloc",
65
+ "unsafe"
66
+ ]
67
+ }
package/ctor/README.md ADDED
@@ -0,0 +1,182 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2018 The Stdlib Authors.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ -->
20
+
21
+ # Buffer
22
+
23
+ > [Buffer][node-buffer] constructor.
24
+
25
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26
+
27
+ <section class="intro">
28
+
29
+ </section>
30
+
31
+ <!-- /.intro -->
32
+
33
+ <!-- Package usage documentation. -->
34
+
35
+ <section class="usage">
36
+
37
+ ## Usage
38
+
39
+ ```javascript
40
+ var Buffer = require( '@stdlib/buffer/ctor' );
41
+ ```
42
+
43
+ #### Buffer( size )
44
+
45
+ Allocates a [`Buffer`][node-buffer] having a specified number of bytes.
46
+
47
+ <!-- eslint-disable stdlib/require-globals, no-buffer-constructor -->
48
+
49
+ ```javascript
50
+ var b = new Buffer( 10 );
51
+ // returns <Buffer>
52
+ ```
53
+
54
+ #### Buffer( array )
55
+
56
+ Allocates a [`Buffer`][node-buffer] from an array of octets.
57
+
58
+ <!-- eslint-disable stdlib/require-globals, no-buffer-constructor -->
59
+
60
+ ```javascript
61
+ var b = new Buffer( [ 1, 2, 3, 4 ] );
62
+ // returns <Buffer>[ 1, 2, 3, 4 ]
63
+ ```
64
+
65
+ #### Buffer( buffer )
66
+
67
+ Copies [buffer][node-buffer] data to a new [`Buffer`][node-buffer] instance.
68
+
69
+ <!-- eslint-disable stdlib/require-globals, no-buffer-constructor -->
70
+
71
+ ```javascript
72
+ var b1 = new Buffer( [ 1, 2, 3, 4 ] );
73
+ var b2 = new Buffer( b1 );
74
+ // returns <Buffer>[ 1, 2, 3, 4 ]
75
+ ```
76
+
77
+ #### Buffer( str\[, encoding] )
78
+
79
+ Returns a [`Buffer`][node-buffer] containing a provided `string`.
80
+
81
+ <!-- eslint-disable stdlib/require-globals, no-buffer-constructor -->
82
+
83
+ ```javascript
84
+ var b = new Buffer( 'beep boop' );
85
+ // returns <Buffer>
86
+ ```
87
+
88
+ * * *
89
+
90
+ ### Properties
91
+
92
+ TODO: add properties
93
+
94
+ * * *
95
+
96
+ ### Methods
97
+
98
+ TODO: add methods
99
+
100
+ </section>
101
+
102
+ <!-- /.usage -->
103
+
104
+ * * *
105
+
106
+ <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
107
+
108
+ <section class="notes">
109
+
110
+ </section>
111
+
112
+ <!-- /.notes -->
113
+
114
+ <!-- Package usage examples. -->
115
+
116
+ <section class="examples">
117
+
118
+ ## Examples
119
+
120
+ <!-- eslint no-undef: "error" -->
121
+
122
+ ```javascript
123
+ var ctor = require( '@stdlib/buffer/ctor' );
124
+
125
+ var b;
126
+ var i;
127
+
128
+ // Allocate uninitialized memory:
129
+ if ( typeof ctor.alloc === 'function' ) {
130
+ b = ctor.alloc( 10 );
131
+ } else {
132
+ b = new ctor( 10 );
133
+ }
134
+
135
+ // Zero fill the buffer...
136
+ for ( i = 0; i < b.length; i++ ) {
137
+ b[ i ] = 0;
138
+ }
139
+ console.log( b );
140
+ ```
141
+
142
+ </section>
143
+
144
+ <!-- /.examples -->
145
+
146
+ <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
147
+
148
+ <section class="references">
149
+
150
+ </section>
151
+
152
+ <!-- /.references -->
153
+
154
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
155
+
156
+ <section class="related">
157
+
158
+ * * *
159
+
160
+ ## See Also
161
+
162
+ - <span class="package-name">[`@stdlib/array/buffer`][@stdlib/array/buffer]</span><span class="delimiter">: </span><span class="description">ArrayBuffer.</span>
163
+
164
+ </section>
165
+
166
+ <!-- /.related -->
167
+
168
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
169
+
170
+ <section class="links">
171
+
172
+ [node-buffer]: https://nodejs.org/api/buffer.html
173
+
174
+ <!-- <related-links> -->
175
+
176
+ [@stdlib/array/buffer]: https://www.npmjs.com/package/@stdlib/array-buffer
177
+
178
+ <!-- </related-links> -->
179
+
180
+ </section>
181
+
182
+ <!-- /.links -->
@@ -0,0 +1,91 @@
1
+
2
+ {{alias}}
3
+ Buffer constructor.
4
+
5
+
6
+ {{alias}}( size )
7
+ Allocates a buffer having a specified number of bytes.
8
+
9
+ Parameters
10
+ ----------
11
+ size: integer
12
+ Number of bytes to allocate.
13
+
14
+ Returns
15
+ -------
16
+ out: Buffer
17
+ Buffer instance.
18
+
19
+ Examples
20
+ --------
21
+ > var b = new {{alias}}( 4 )
22
+ <Buffer>
23
+
24
+
25
+ {{alias}}( buffer )
26
+ Copies buffer data to a new Buffer instance.
27
+
28
+ Parameters
29
+ ----------
30
+ buffer: Buffer
31
+ Buffer to copy from.
32
+
33
+ Returns
34
+ -------
35
+ out: Buffer
36
+ Buffer instance.
37
+
38
+ Examples
39
+ --------
40
+ > var b1 = new {{alias}}( [ 1, 2, 3, 4 ] );
41
+ > var b2 = new {{alias}}( b1 )
42
+ <Buffer>[ 1, 2, 3, 4 ]
43
+
44
+
45
+ {{alias}}( array )
46
+ Allocates a buffer using an array of octets.
47
+
48
+ Parameters
49
+ ----------
50
+ array: Array
51
+ Array of octets.
52
+
53
+ Returns
54
+ -------
55
+ out: Buffer
56
+ Buffer instance.
57
+
58
+ Examples
59
+ --------
60
+ > var b = new {{alias}}( [ 1, 2, 3, 4 ] )
61
+ <Buffer>[ 1, 2, 3, 4 ]
62
+
63
+
64
+ {{alias}}( str[, encoding] )
65
+ Allocates a buffer containing a provided string.
66
+
67
+ Parameters
68
+ ----------
69
+ str: string
70
+ Input string.
71
+
72
+ encoding: string (optional)
73
+ Character encoding. Default: 'utf8'.
74
+
75
+ Returns
76
+ -------
77
+ out: Buffer
78
+ Buffer instance.
79
+
80
+ Examples
81
+ --------
82
+ > var b = new {{alias}}( 'beep boop' )
83
+ <Buffer>
84
+
85
+
86
+ TODO: add methods and properties
87
+
88
+
89
+ See Also
90
+ --------
91
+
@@ -0,0 +1,37 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2021 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ // TypeScript Version: 4.1
20
+
21
+ /// <reference types="node"/>
22
+
23
+ import { Buffer } from 'buffer';
24
+
25
+
26
+ // EXPORTS //
27
+
28
+ /**
29
+ * Buffer constructor.
30
+ *
31
+ * @example
32
+ * var ctor = require( '@stdlib/buffer/ctor' );
33
+ *
34
+ * var b = new ctor( [ 1, 2, 3, 4 ] );
35
+ * // returns <Buffer>
36
+ */
37
+ export = Buffer;
@@ -0,0 +1,35 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2021 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ /* eslint-disable @typescript-eslint/no-unused-expressions */
20
+
21
+ import Buffer = require( './index' );
22
+
23
+
24
+ // TESTS //
25
+
26
+ // The function returns a buffer instance...
27
+ {
28
+ new Buffer( 10 ); // $ExpectType Buffer
29
+ new Buffer( [ 1, 2, 3, 4 ] ); // $ExpectType Buffer
30
+ }
31
+
32
+ // The compiler throws an error if the function is provided an unsupported number of arguments...
33
+ {
34
+ new Buffer(); // $ExpectError
35
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ /**
22
+ * Buffer constructor.
23
+ *
24
+ * @module @stdlib/buffer/ctor
25
+ *
26
+ * @example
27
+ * var ctor = require( '@stdlib/buffer/ctor' );
28
+ *
29
+ * var b = new ctor( [ 1, 2, 3, 4 ] );
30
+ * // returns <Buffer>
31
+ */
32
+
33
+ // MODULES //
34
+
35
+ var hasNodeBufferSupport = require( '@stdlib/assert/has-node-buffer-support' );
36
+ var main = require( './main.js' );
37
+ var polyfill = require( './polyfill.js' );
38
+
39
+
40
+ // MAIN //
41
+
42
+ var ctor;
43
+ if ( hasNodeBufferSupport() ) {
44
+ ctor = main;
45
+ } else {
46
+ ctor = polyfill;
47
+ }
48
+
49
+
50
+ // EXPORTS //
51
+
52
+ module.exports = ctor;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MAIN //
22
+
23
+ var ctor = require( 'buffer' ).Buffer;
24
+
25
+
26
+ // EXPORTS //
27
+
28
+ module.exports = ctor;