Skip to content

Commit

Permalink
Require Node.js 18 and add TypeScript types
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 16, 2023
1 parent 0fd027f commit ae336b0
Show file tree
Hide file tree
Showing 20 changed files with 317 additions and 420 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

2 changes: 0 additions & 2 deletions .eslintrc.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 20
- 18
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
.nyc_output/
coverage/
node_modules/
npm-debug.log
package-lock.json
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
86 changes: 0 additions & 86 deletions .travis.yml

This file was deleted.

21 changes: 0 additions & 21 deletions HISTORY.md

This file was deleted.

23 changes: 0 additions & 23 deletions LICENSE

This file was deleted.

49 changes: 0 additions & 49 deletions README.md

This file was deleted.

10 changes: 0 additions & 10 deletions component.json

This file was deleted.

11 changes: 11 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
Merges "own" properties from a source to a destination object, including non-enumerable and accessor-defined properties. It retains original values and descriptors, ensuring the destination receives a complete and accurate copy of the source's properties.
@param destination - The object to receive properties.
@param source - The object providing properties.
@param overwrite - Optional boolean to control overwriting of existing properties. Defaults to true.
@returns The modified destination object.
*/
declare function mergeDescriptors<T, U>(destination: T, source: U, overwrite?: boolean): T & U;

export = mergeDescriptors;
74 changes: 20 additions & 54 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,26 @@
/*!
* merge-descriptors
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict';

'use strict'
function mergeDescriptors(destination, source, overwrite = true) {
if (!destination) {
throw new TypeError('The `destination` argument is required.');
}

/**
* Module exports.
* @public
*/
if (!source) {
throw new TypeError('The `source` argument is required.');
}

module.exports = merge
for (const name of Object.getOwnPropertyNames(source)) {
if (!overwrite && Object.hasOwn(destination, name)) {
// Skip descriptor
continue;
}

/**
* Module variables.
* @private
*/
// Copy descriptor
const descriptor = Object.getOwnPropertyDescriptor(source, name);
Object.defineProperty(destination, name, descriptor);
}

var hasOwnProperty = Object.prototype.hasOwnProperty

/**
* Merge the property descriptors of `src` into `dest`
*
* @param {object} dest Object to add descriptors to
* @param {object} src Object to clone descriptors from
* @param {boolean} [redefine=true] Redefine `dest` properties with `src` properties
* @returns {object} Reference to dest
* @public
*/

function merge (dest, src, redefine) {
if (!dest) {
throw new TypeError('argument dest is required')
}

if (!src) {
throw new TypeError('argument src is required')
}

if (redefine === undefined) {
// Default to true
redefine = true
}

Object.getOwnPropertyNames(src).forEach(function forEachOwnPropertyName (name) {
if (!redefine && hasOwnProperty.call(dest, name)) {
// Skip descriptor
return
}

// Copy descriptor
var descriptor = Object.getOwnPropertyDescriptor(src, name)
Object.defineProperty(dest, name, descriptor)
})

return dest
return destination;
}

module.exports = mergeDescriptors;
11 changes: 11 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MIT License

Copyright (c) Jonathan Ong <me@jongleberry.com>
Copyright (c) Douglas Christopher Wilson <doug@somethingdoug.com>
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading

0 comments on commit ae336b0

Please sign in to comment.