Skip to content

Commit

Permalink
Require Node.js 12.20 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 18, 2021
1 parent 5966010 commit c3d4e47
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 32 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 10
- 8
- 16
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
6 changes: 2 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ Lowercase the keys of an object.
@example
```
import lowercaseKeys = require('lowercase-keys');
import lowercaseKeys from 'lowercase-keys';
lowercaseKeys({FOO: true, bAr: false});
//=> {foo: true, bar: false}
```
*/
declare function lowercaseKeys<T>(object: {[key: string]: T}): {[key: string]: T};

export = lowercaseKeys;
export default function lowercaseKeys<T>(object: Record<string, T>): Record<string, T>;
13 changes: 3 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
'use strict';
module.exports = object => {
const result = {};

for (const [key, value] of Object.entries(object)) {
result[key.toLowerCase()] = value;
}

return result;
};
export default function lowercaseKeys(object) {
return Object.fromEntries(Object.entries(object).map(([key, value]) => [key.toLowerCase(), value]));
}
6 changes: 3 additions & 3 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import lowercaseKeys = require('.');
import lowercaseKeys from './index.js';

expectType<{[key: string]: boolean}>(lowercaseKeys({FOO: true, bAr: false}));
expectType<{[key: string]: string | number}>(lowercaseKeys({foo: 'bar', baz: 1}));
expectType<Record<string, boolean>>(lowercaseKeys({FOO: true, bAr: false})); // eslint-disable-line @typescript-eslint/naming-convention
expectType<Record<string, string | number>>(lowercaseKeys({foo: 'bar', baz: 1}));
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.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:

Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"description": "Lowercase the keys of an object",
"license": "MIT",
"repository": "sindresorhus/lowercase-keys",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -31,8 +34,8 @@
"key"
],
"devDependencies": {
"ava": "^2.0.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.18.0",
"xo": "^0.45.0"
}
}
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Check out [`map-obj`](https://github.com/sindresorhus/map-obj) if you need suppo

## Install

```
$ npm install lowercase-keys
```sh
npm install lowercase-keys
```

## Usage

```js
const lowercaseKeys = require('lowercase-keys');
import lowercaseKeys from 'lowercase-keys';

lowercaseKeys({FOO: true, bAr: false});
//=> {foo: true, bar: false}
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import lowercaseKeys from '.';
import lowercaseKeys from './index.js';

test('main', t => {
t.true(lowercaseKeys({FOO: true}).foo);
Expand Down

0 comments on commit c3d4e47

Please sign in to comment.