Skip to content

Commit

Permalink
Require Node.js 4
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jun 9, 2017
1 parent 6199bec commit 70a5ee6
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .gitattributes
@@ -1 +1,2 @@
* text=auto
*.js text eol=lf
4 changes: 1 addition & 3 deletions .travis.yml
@@ -1,7 +1,5 @@
sudo: false
language: node_js
node_js:
- '8'
- '6'
- '4'
- '0.12'
- '0.10'
30 changes: 15 additions & 15 deletions index.js
@@ -1,7 +1,7 @@
'use strict';
var isPlainObj = require('is-plain-obj');
const isPlainObj = require('is-plain-obj');

module.exports = function (obj, opts) {
module.exports = (obj, opts) => {
if (!isPlainObj(obj)) {
throw new TypeError('Expected a plain object');
}
Expand All @@ -10,34 +10,34 @@ module.exports = function (obj, opts) {

// DEPRECATED
if (typeof opts === 'function') {
opts = {compare: opts};
throw new TypeError('Specify the compare function as an option instead');
}

var deep = opts.deep;
var seenInput = [];
var seenOutput = [];
const deep = opts.deep;
const seenInput = [];
const seenOutput = [];

var sortKeys = function (x) {
var seenIndex = seenInput.indexOf(x);
const sortKeys = x => {
const seenIndex = seenInput.indexOf(x);

if (seenIndex !== -1) {
return seenOutput[seenIndex];
}

var ret = {};
var keys = Object.keys(x).sort(opts.compare);
const ret = {};
const keys = Object.keys(x).sort(opts.compare);

seenInput.push(x);
seenOutput.push(ret);

for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var val = x[key];
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const val = x[key];

if (deep && Array.isArray(val)) {
var retArr = [];
const retArr = [];

for (var j = 0; j < val.length; j++) {
for (let j = 0; j < val.length; j++) {
retArr[j] = isPlainObj(val[j]) ? sortKeys(val[j]) : val[j];
}

Expand Down
20 changes: 4 additions & 16 deletions license
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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:
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 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.
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.
76 changes: 38 additions & 38 deletions package.json
@@ -1,40 +1,40 @@
{
"name": "sort-keys",
"version": "1.1.2",
"description": "Sort the keys of an object",
"license": "MIT",
"repository": "sindresorhus/sort-keys",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"sort",
"object",
"keys",
"obj",
"key",
"stable",
"deterministic",
"deep",
"recursive",
"recursively"
],
"dependencies": {
"is-plain-obj": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "sort-keys",
"version": "1.1.2",
"description": "Sort the keys of an object",
"license": "MIT",
"repository": "sindresorhus/sort-keys",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"sort",
"object",
"keys",
"obj",
"key",
"stable",
"deterministic",
"deep",
"recursive",
"recursively"
],
"dependencies": {
"is-plain-obj": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
}
7 changes: 1 addition & 6 deletions test.js
@@ -1,15 +1,10 @@
import test from 'ava';
import m from './';
import m from '.';

test('sort the keys of an object', t => {
t.deepEqual(m({c: 0, a: 0, b: 0}), {a: 0, b: 0, c: 0});
});

test('DEPRECATED - sort the keys of an object with a custom sort function', t => {
const sortFn = (a, b) => -a.localeCompare(b);
t.deepEqual(m({c: 0, a: 0, b: 0}, sortFn), {c: 0, b: 0, a: 0});
});

test('custom compare function', t => {
const compare = (a, b) => a.localeCompare(b);
t.deepEqual(m({c: 0, a: 0, b: 0}, {compare}), {c: 0, b: 0, a: 0});
Expand Down

0 comments on commit 70a5ee6

Please sign in to comment.