Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sortobject

Package Overview
Dependencies
Maintainers
2
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sortobject - npm Package Compare versions

Comparing version 2.4.0 to 3.0.0-next.1576638523.28418d981f2d1cfd72d2060a23ab6584a80c8dcd

edition-esnext/index.js

96

edition-browsers/index.js

@@ -1,59 +0,51 @@

'use strict';
/**
* A typical comparator for sorting.
* @callback Comparator
* @param {any} a
* @param {any} b
* @returns {number}
* Returns a copy of the passed array, with all nested objects within it sorted deeply by their keys, without mangling any nested arrays.
* @param subject The unsorted array.
* @param comparator An optional comparator for sorting keys of objects.
* @returns The new sorted array.
*/
export function sortArray(subject, comparator) {
const result = [];
for (let value of subject) {
// Recurse if object or array
if (value != null) {
if (Array.isArray(value)) {
value = sortArray(value, comparator);
}
else if (typeof value === 'object') {
/* eslint no-use-before-define:0 */
value = sortObject(value, comparator);
}
}
// Push
result.push(value);
}
return result;
}
/**
* Returns a copy of an object, sorted deeply by its keys, without mangling any arrays inside of it.
* @param {object} obj The unsorted object.
* @param {Comparator} [comparator] An optional comparator to use to sort the keys.
* @returns {object} The new sorted object.
* Returns a copy of the passed object, with all nested objects within it sorted deeply by their keys, without mangling any nested arrays inside of it.
* @param subject The unsorted object.
* @param comparator An optional comparator for sorting keys of objects.
* @returns The new sorted object.
*/
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function sortObject(obj, comparator) {
// Arrays
if (Array.isArray(obj)) {
var result = [];
for (var i = 0; i < obj.length; ++i) {
// Fetch
var value = obj[i]; // Recurse if object or array
if (value != null && _typeof(value) === 'object') {
value = sortObject(value, comparator);
} // Push
result.push(value);
export default function sortObject(subject, comparator) {
const result = {};
const sortedKeys = Object.keys(subject).sort(comparator);
for (let i = 0; i < sortedKeys.length; ++i) {
// Fetch
const key = sortedKeys[i];
let value = subject[key];
// Recurse if object or array
if (value != null) {
if (Array.isArray(value)) {
value = sortArray(value, comparator);
}
else if (typeof value === 'object') {
value = sortObject(value, comparator);
}
}
// Push
result[key] = value;
}
return result;
} // Objects
else {
var _result = {};
var sortedKeys = Object.keys(obj).sort(comparator);
for (var _i = 0; _i < sortedKeys.length; ++_i) {
// Fetch
var key = sortedKeys[_i];
var _value = obj[key]; // Recurse if object or array
if (_value != null && _typeof(_value) === 'object') {
_value = sortObject(_value, comparator);
} // Push
_result[key] = _value;
}
return _result;
}
}
module.exports = sortObject;
# History
## v3.0.0 2019 December 18
- Converted from JavaScript to TypeScript
- If you are using CommonJS, you must now do `require('sortobject').default`
- Updated dependencies, [base files](https://github.com/bevry/base), and [editions](https://editions.bevry.me) using [boundation](https://github.com/bevry/boundation)
## v2.4.0 2019 December 11

@@ -4,0 +10,0 @@

{
"title": "Sort Object",
"name": "sortobject",
"version": "2.4.0",
"version": "3.0.0-next.1576638523.28418d981f2d1cfd72d2060a23ab6584a80c8dcd",
"description": "Returns a copy of an object, sorted deeply by its keys, without mangling any arrays inside of it",

@@ -9,9 +9,15 @@ "homepage": "https://github.com/bevry/sortobject",

"keywords": [
"sort",
"object",
"keys",
"array",
"browser",
"comparator",
"array",
"deep",
"deeply"
"deeply",
"export-default",
"keys",
"module",
"object",
"sort",
"typed",
"types",
"typescript"
],

@@ -61,4 +67,3 @@ "badges": {

"James Newell (http://jameslnewell.me/)",
"James Newell (http://jameslnewell.dev/)",
"dependabot-preview[bot] (http://github.com/apps/dependabot-preview)"
"James Newell (http://jameslnewell.dev/)"
],

@@ -77,37 +82,47 @@ "bugs": {

{
"description": "esnext source code for Node.js with require for modules",
"description": "TypeScript source code with Import for modules",
"directory": "source",
"entry": "index.ts",
"tags": [
"typescript",
"import"
],
"engines": false
},
{
"description": "TypeScript compiled against ESNext for web browsers with Import for modules",
"directory": "edition-browsers",
"entry": "index.js",
"tags": [
"javascript",
"esnext",
"require"
"import"
],
"engines": {
"node": "6 || 8 || 10 || 12 || 13",
"browsers": false
"node": false,
"browsers": "defaults"
}
},
{
"description": "esnext compiled for web browsers with require for modules",
"directory": "edition-browsers",
"description": "TypeScript compiled against ESNext for Node.js with Require for modules",
"directory": "edition-esnext",
"entry": "index.js",
"tags": [
"javascript",
"esnext",
"require"
],
"engines": {
"node": false,
"browsers": "defaults"
"node": "6 || 8 || 10 || 12 || 13",
"browsers": false
}
}
],
"types": "source/index.ts",
"type": "commonjs",
"main": "source/index.js",
"main": "edition-esnext/index.js",
"browser": "edition-browsers/index.js",
"module": "edition-browsers/index.js",
"devDependencies": {
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
"@babel/plugin-proposal-object-rest-spread": "^7.7.4",
"@babel/preset-env": "^7.7.6",
"@typescript-eslint/eslint-plugin": "^2.12.0",
"@typescript-eslint/parser": "^2.12.0",
"assert-helpers": "4.10.0",

@@ -118,19 +133,21 @@ "eslint": "^6.7.2",

"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-prettier": "^3.1.1",
"jsdoc": "^3.6.3",
"eslint-plugin-prettier": "^3.1.2",
"kava": "3.2.0",
"minami": "^1.2.3",
"prettier": "^1.19.1",
"projectz": "^1.16.0",
"projectz": "^1.19.0",
"surge": "^0.21.3",
"valid-directory": "^1.6.0"
"typedoc": "^0.15.5",
"typescript": "^3.7.3",
"valid-directory": "^1.6.0",
"valid-module": "^1.0.0"
},
"scripts": {
"our:clean": "rm -Rf ./docs ./edition* ./es2015 ./es5 ./out ./.next",
"our:compile": "npm run our:compile:edition-browsers",
"our:compile:edition-browsers": "env BABEL_ENV=edition-browsers babel --out-dir ./edition-browsers ./source",
"our:compile": "npm run our:compile:edition-browsers && npm run our:compile:edition-esnext",
"our:compile:edition-browsers": "tsc --module ESNext --target ESNext --outDir ./edition-browsers --project tsconfig.json && test -d edition-browsers/source && ( mv edition-browsers/source edition-temp && rm -Rf edition-browsers && mv edition-temp edition-browsers ) || true",
"our:compile:edition-esnext": "tsc --module commonjs --target ESNext --outDir ./edition-esnext --project tsconfig.json && test -d edition-esnext/source && ( mv edition-esnext/source edition-temp && rm -Rf edition-esnext && mv edition-temp edition-esnext ) || true",
"our:deploy": "echo no need for this project",
"our:meta": "npm run our:meta:docs && npm run our:meta:projectz",
"our:meta:docs": "npm run our:meta:docs:jsdoc",
"our:meta:docs:jsdoc": "rm -Rf ./docs && jsdoc --recurse --pedantic --access all --destination ./docs --package ./package.json --readme ./README.md --template ./node_modules/minami ./source && mv ./docs/$npm_package_name/$npm_package_version/* ./docs/ && rm -Rf ./docs/$npm_package_name/$npm_package_version",
"our:meta:docs": "npm run our:meta:docs:typedoc",
"our:meta:docs:typedoc": "rm -Rf ./docs && typedoc --mode file --exclude '**/+(*test*|node_modules)' --excludeExternals --name \"$npm_package_name\" --readme ./README.md --out ./docs ./source",
"our:meta:projectz": "projectz compile",

@@ -146,7 +163,9 @@ "our:release": "npm run our:release:prepare && npm run our:release:check-changelog && npm run our:release:check-dirty && npm run our:release:tag && npm run our:release:push",

"our:test": "npm run our:verify && npm test",
"our:verify": "npm run our:verify:directory && npm run our:verify:eslint && npm run our:verify:prettier",
"our:verify:directory": "npx valid-directory",
"our:verify": "npm run our:verify:directory && npm run our:verify:eslint && npm run our:verify:module && npm run our:verify:prettier && npm run our:verify:typescript",
"our:verify:directory": "valid-directory",
"our:verify:eslint": "eslint --fix --ignore-pattern '**/*.d.ts' --ignore-pattern '**/vendor/' --ignore-pattern '**/node_modules/' --ext .mjs,.js,.jsx,.ts,.tsx ./source",
"our:verify:module": "valid-module",
"our:verify:prettier": "prettier --write ./source/**",
"test": "node ./source/test.js"
"our:verify:typescript": "tsc --noEmit --project tsconfig.json",
"test": "node ./edition-esnext/test.js"
},

@@ -162,23 +181,2 @@ "eslintConfig": {

},
"babel": {
"env": {
"edition-browsers": {
"sourceType": "script",
"presets": [
[
"@babel/preset-env",
{
"targets": {
"browsers": "defaults"
},
"modules": false
}
]
],
"plugins": [
"@babel/proposal-object-rest-spread"
]
}
}
},
"boundation": {

@@ -185,0 +183,0 @@ "minimumSupportNodeVersion": "5",

@@ -36,50 +36,7 @@ <!-- TITLE/ -->

<!-- INSTALL/ -->
<h2>Install</h2>
<a href="https://npmjs.com" title="npm is a package manager for javascript"><h3>npm</h3></a>
<ul>
<li>Install: <code>npm install --save sortobject</code></li>
<li>Require: <code>require('sortobject')</code></li>
</ul>
<a href="https://jspm.io" title="Native ES Modules CDN"><h3>jspm</h3></a>
``` html
<script type="module">
import * as pkg from '//dev.jspm.io/sortobject'
</script>
```
<h3><a href="https://editions.bevry.me" title="Editions are the best way to produce and consume packages you care about.">Editions</a></h3>
<p>This package is published with the following editions:</p>
<ul><li><code>sortobject</code> aliases <code>sortobject/source/index.js</code></li>
<li><code>sortobject/source/index.js</code> is esnext source code for Node.js with require for modules</li>
<li><code>sortobject/edition-browsers/index.js</code> is esnext compiled for web browsers with require for modules</li></ul>
<h3><a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a></h3>
This project provides its type information via inline <a href="http://usejsdoc.org" title="JSDoc is an API documentation generator for JavaScript, similar to Javadoc or phpDocumentor">JSDoc Comments</a>. To make use of this in <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a>, set your <code>maxNodeModuleJsDepth</code> compiler option to `5` or thereabouts. You can accomlish this via your `tsconfig.json` file like so:
``` json
{
"compilerOptions": {
"maxNodeModuleJsDepth": 5
}
}
```
<!-- /INSTALL -->
## Usage
[API Documentation.](http://master.sortobject.bevry.surge.sh/docs/)
```javascript
var sortObject = require('sortobject')
var fixture = {
import sortObject from 'sortobject'
const fixture = {
c: true,

@@ -108,3 +65,3 @@ a: true,

}
var actual = sortObject(fixture)
const actual = sortObject(fixture)
console.log(JSON.stringify(actual, null, 4)) /* {

@@ -136,2 +93,67 @@ "a": true,

[Complete API Documentation.](http://master.sortobject.bevry.surge.sh/docs/)
<!-- INSTALL/ -->
<h2>Install</h2>
<a href="https://npmjs.com" title="npm is a package manager for javascript"><h3>npm</h3></a>
<ul>
<li>Install: <code>npm install --save sortobject</code></li>
<li>Import: <code>import pkg from ('sortobject')</code></li>
<li>Require: <code>const pkg = require('sortobject').default</code></li>
</ul>
<a href="https://www.pika.dev/cdn" title="100% Native ES Modules CDN"><h3>pika</h3></a>
``` html
<script type="module">
import pkg from '//cdn.pika.dev/sortobject/^3.0.0'
</script>
```
<a href="https://unpkg.com" title="unpkg is a fast, global content delivery network for everything on npm"><h3>unpkg</h3></a>
``` html
<script type="module">
import pkg from '//unpkg.com/sortobject@^3.0.0'
</script>
```
<a href="https://jspm.io" title="Native ES Modules CDN"><h3>jspm</h3></a>
``` html
<script type="module">
import pkg from '//dev.jspm.io/sortobject@3.0.0'
</script>
```
<h3><a href="https://editions.bevry.me" title="Editions are the best way to produce and consume packages you care about.">Editions</a></h3>
<p>This package is published with the following editions:</p>
<ul><li><code>sortobject/source/index.ts</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> source code with <a href="https://babeljs.io/docs/learn-es2015/#modules" title="ECMAScript Modules">Import</a> for modules</li>
<li><code>sortobject/edition-browsers/index.js</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> compiled against <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> for web browsers with <a href="https://babeljs.io/docs/learn-es2015/#modules" title="ECMAScript Modules">Import</a> for modules</li>
<li><code>sortobject</code> aliases <code>sortobject/edition-esnext/index.js</code></li>
<li><code>sortobject/edition-esnext/index.js</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> compiled against <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> for <a href="https://nodejs.org" title="Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine">Node.js</a> with <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a> for modules</li></ul>
<!-- /INSTALL -->
<!-- HISTORY/ -->

@@ -138,0 +160,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc