-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation, tests, readme, types
- Loading branch information
Showing
20 changed files
with
280 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"root": true, | ||
|
||
"extends": "@ljharb", | ||
|
||
"rules": { | ||
"eqeqeq": ["error", "allow-null"], | ||
"id-length": "off", | ||
"new-cap": ["error", { | ||
"capIsNewExceptions": [ | ||
"RequireObjectCoercible", | ||
"ToObject", | ||
], | ||
}], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# These are supported funding model platforms | ||
|
||
github: [ljharb] | ||
patreon: # Replace with a single Patreon username | ||
open_collective: # Replace with a single Open Collective username | ||
ko_fi: # Replace with a single Ko-fi username | ||
tidelift: npm/es-object | ||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | ||
liberapay: # Replace with a single Liberapay username | ||
issuehunt: # Replace with a single IssueHunt username | ||
otechie: # Replace with a single Otechie username | ||
custom: # Replace with a single custom sponsorship URL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: 'Tests: node.js < 10' | ||
|
||
on: [pull_request, push] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/node.yml@main | ||
with: | ||
range: '< 10' | ||
type: minors | ||
command: npm run tests-only | ||
skip-ls-check: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: 'Tests: pretest/posttest' | ||
|
||
on: [pull_request, push] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/pretest.yml@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: 'Tests: node.js >= 10' | ||
|
||
on: [pull_request, push] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/node.yml@main | ||
with: | ||
range: '>= 10' | ||
type: minors | ||
command: npm run tests-only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Automatic Rebase | ||
|
||
on: [pull_request_target] | ||
|
||
jobs: | ||
_: | ||
uses: ljharb/actions/.github/workflows/rebase.yml@main | ||
secrets: | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Require “Allow Edits” | ||
|
||
on: [pull_request_target] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
_: | ||
permissions: | ||
pull-requests: read # for ljharb/require-allow-edits to check 'allow edits' on PR | ||
|
||
name: "Require “Allow Edits”" | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: ljharb/require-allow-edits@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,3 +133,5 @@ dist | |
npm-shrinkwrap.json | ||
package-lock.json | ||
yarn.lock | ||
|
||
.npmignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
package-lock=false | ||
allow-same-version=true | ||
message=v%s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,56 @@ | ||
# es-object | ||
ES Object-related atoms: ToObject, RequireObjectCoercible | ||
# es-object <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
|
||
[![github actions][actions-image]][actions-url] | ||
[![coverage][codecov-image]][codecov-url] | ||
[![License][license-image]][license-url] | ||
[![Downloads][downloads-image]][downloads-url] | ||
|
||
[![npm badge][npm-badge-png]][package-url] | ||
|
||
ES Object-related atoms: Object, ToObject, RequireObjectCoercible. | ||
|
||
## Example | ||
|
||
```js | ||
const assert = require('assert'); | ||
|
||
const $Object = require('es-object'); | ||
const ToObject = require('es-object/ToObject'); | ||
const RequireObjectCoercible = require('es-object/RequireObjectCoercible'); | ||
|
||
assert.equal($Object, Object); | ||
assert.throws(() => ToObject(null), TypeError); | ||
assert.throws(() => ToObject(undefined), TypeError); | ||
assert.throws(() => RequireObjectCoercible(null), TypeError); | ||
assert.throws(() => RequireObjectCoercible(undefined), TypeError); | ||
|
||
assert.deepEqual(RequireObjectCoercible(true), true); | ||
assert.deepEqual(ToObject(true), Object(true)); | ||
|
||
const obj = {}; | ||
assert.equal(RequireObjectCoercible(obj), obj); | ||
assert.equal(ToObject(obj), obj); | ||
``` | ||
|
||
## Tests | ||
Simply clone the repo, `npm install`, and run `npm test` | ||
|
||
## Security | ||
|
||
Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report. | ||
|
||
[package-url]: https://npmjs.org/package/es-object | ||
[npm-version-svg]: https://versionbadg.es/ljharb/es-object.svg | ||
[deps-svg]: https://david-dm.org/ljharb/es-object.svg | ||
[deps-url]: https://david-dm.org/ljharb/es-object | ||
[dev-deps-svg]: https://david-dm.org/ljharb/es-object/dev-status.svg | ||
[dev-deps-url]: https://david-dm.org/ljharb/es-object#info=devDependencies | ||
[npm-badge-png]: https://nodei.co/npm/es-object.png?downloads=true&stars=true | ||
[license-image]: https://img.shields.io/npm/l/es-object.svg | ||
[license-url]: LICENSE | ||
[downloads-image]: https://img.shields.io/npm/dm/es-object.svg | ||
[downloads-url]: https://npm-stat.com/charts.html?package=es-object | ||
[codecov-image]: https://codecov.io/gh/ljharb/es-object/branch/main/graphs/badge.svg | ||
[codecov-url]: https://app.codecov.io/gh/ljharb/es-object/ | ||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/es-object | ||
[actions-url]: https://github.com/ljharb/es-object/actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare function RequireObjectCoercible<T extends {} = {}>(value: T, optMessage?: string): T; | ||
|
||
export = RequireObjectCoercible; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
var $TypeError = require('es-errors/type'); | ||
|
||
/** @type {import('./RequireObjectCoercible')} */ | ||
module.exports = function RequireObjectCoercible(value) { | ||
if (value == null) { | ||
throw new $TypeError((arguments.length > 0 && arguments[1]) || ('Cannot call method on ' + value)); | ||
} | ||
return value; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare function ToObject<T = {}>(value: T extends object ? T : {}): T extends object ? T : object; | ||
|
||
export = ToObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
var $Object = require('./'); | ||
var RequireObjectCoercible = require('./RequireObjectCoercible'); | ||
|
||
/** @type {import('./ToObject')} */ | ||
module.exports = function ToObject(value) { | ||
RequireObjectCoercible(value); | ||
return $Object(value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare const Object: ObjectConstructor; | ||
|
||
export = Object; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
|
||
/** @type {import('.')} */ | ||
module.exports = Object; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
var test = require('tape'); | ||
|
||
var $Object = require('../'); | ||
var ToObject = require('..//ToObject'); | ||
var RequireObjectCoercible = require('..//RequireObjectCoercible'); | ||
|
||
test('errors', function (t) { | ||
t.equal($Object, Object); | ||
// @ts-expect-error | ||
t['throws'](function () { ToObject(null); }, TypeError); | ||
// @ts-expect-error | ||
t['throws'](function () { ToObject(undefined); }, TypeError); | ||
// @ts-expect-error | ||
t['throws'](function () { RequireObjectCoercible(null); }, TypeError); | ||
// @ts-expect-error | ||
t['throws'](function () { RequireObjectCoercible(undefined); }, TypeError); | ||
|
||
t.deepEqual(RequireObjectCoercible(true), true); | ||
t.deepEqual(ToObject(true), Object(true)); | ||
|
||
var obj = {}; | ||
t.equal(RequireObjectCoercible(obj), obj); | ||
t.equal(ToObject(obj), obj); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "@ljharb/tsconfig", | ||
"compilerOptions": { | ||
"target": "es5", | ||
}, | ||
} |