arrangekeys
Advanced tools
Comparing version 2.4.0 to 3.0.0-next.1576639049.80ae33029a81f37238634991ba3792adf70c3dab
@@ -1,83 +0,33 @@ | ||
'use strict'; | ||
/** | ||
* Returns a copy of a JavaScript object with the keys arranged in a specified order. | ||
* @param {object} data The unarranged source object. | ||
* @param {string[]|string|false} [keys] The keys that we wish to arrange at the top. Can be a an array of keys. A string of keys seperated by a space character. Or false, to just sort the keys of the object. | ||
* @param {boolean} [sort=false] If true, the remaining keys are sorted. | ||
* @returns {object} The arranged object. | ||
* @param subject The unarranged source object. | ||
* @param keys The keys that we wish to arrange at the top. Can be a an array of keys. A string of keys seperated by a space character. Or false, to just sort the keys of the object. | ||
* @param sort If true, the remaining keys are sorted. | ||
* @returns The arranged object. | ||
*/ | ||
function arrangekeys(data) { | ||
var keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var sort = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
// Prepare | ||
var result = {}; // Expand | ||
if (!keys) { | ||
sort = true; | ||
} else { | ||
if (typeof keys === 'string') { | ||
keys = keys.split(/\s+/); | ||
} // Add the specified keys in the specified order | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var key = _step.value; | ||
if (typeof data[key] !== 'undefined') { | ||
result[key] = data[key]; | ||
export default function arrangekeys(subject, keys, sort) { | ||
// Prepare | ||
const result = {}; | ||
// Expand | ||
if (!keys) { | ||
sort = true; | ||
} | ||
else { | ||
if (typeof keys === 'string') { | ||
keys = keys.split(/\s+/); | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
// Add the specified keys in the specified order | ||
for (const key of keys) { | ||
if (typeof subject[key] !== 'undefined') { | ||
result[key] = subject[key]; | ||
} | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} // Add the leftovers | ||
var dataKeys = sort ? Object.keys(data).sort() : Object.keys(data); | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = dataKeys[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var _key = _step2.value; | ||
result[_key] = data[_key]; // no need for !(key in keys) as we assume the JS engine handles that for us | ||
} // Return the result | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
// Add the leftovers | ||
const dataKeys = sort ? Object.keys(subject).sort() : Object.keys(subject); | ||
for (const key of dataKeys) { | ||
result[key] = subject[key]; // no need for !(key in keys) as we assume the JS engine handles that for us | ||
} | ||
} | ||
return result; | ||
} // Export | ||
module.exports = arrangekeys; | ||
// Return the result | ||
return result; | ||
} |
# History | ||
## v3.0.0 2019 December 18 | ||
- Converted from JavaScript to TypeScript | ||
- If you are using CommonJS, you must now do `require('arrangekeys').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 9 | ||
@@ -4,0 +10,0 @@ |
104
package.json
{ | ||
"title": "Arrange Keys", | ||
"name": "arrangekeys", | ||
"version": "2.4.0", | ||
"version": "3.0.0-next.1576639049.80ae33029a81f37238634991ba3792adf70c3dab", | ||
"description": "Returns a copy of a JavaScript object with the keys arranged in a specified order. Useful for formatting JSON files.", | ||
@@ -9,5 +9,11 @@ "homepage": "https://github.com/bevry/arrangekeys", | ||
"keywords": [ | ||
"browser", | ||
"export-default", | ||
"json", | ||
"keys", | ||
"module", | ||
"objects", | ||
"keys" | ||
"typed", | ||
"types", | ||
"typescript" | ||
], | ||
@@ -51,4 +57,3 @@ "badges": { | ||
"contributors": [ | ||
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)", | ||
"dependabot-preview[bot] (http://github.com/apps/dependabot-preview)" | ||
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)" | ||
], | ||
@@ -67,59 +72,71 @@ "bugs": { | ||
{ | ||
"description": "esnext source code 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": "8 || 10 || 12", | ||
"browsers": false | ||
"node": false, | ||
"browsers": "defaults" | ||
} | ||
}, | ||
{ | ||
"description": "esnext compiled for 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": "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", | ||
"assert-helpers": "^5.7.0", | ||
"@typescript-eslint/eslint-plugin": "^2.12.0", | ||
"@typescript-eslint/parser": "^2.12.0", | ||
"assert-helpers": "^5.8.0", | ||
"eslint": "^6.7.2", | ||
"eslint-config-bevry": "^2.2.0", | ||
"eslint-config-bevry": "^2.3.0", | ||
"eslint-config-prettier": "^6.7.0", | ||
"eslint-plugin-babel": "^5.3.0", | ||
"eslint-plugin-prettier": "^3.1.1", | ||
"jsdoc": "^3.6.3", | ||
"kava": "^4.3.0", | ||
"minami": "^1.2.3", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"kava": "^4.4.0", | ||
"prettier": "^1.19.1", | ||
"projectz": "^1.15.0", | ||
"projectz": "^1.19.0", | ||
"surge": "^0.21.3", | ||
"valid-directory": "^1.5.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", | ||
@@ -135,7 +152,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" | ||
}, | ||
@@ -150,22 +169,3 @@ "eslintConfig": { | ||
"singleQuote": true | ||
}, | ||
"babel": { | ||
"env": { | ||
"edition-browsers": { | ||
"sourceType": "script", | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": "defaults", | ||
"modules": false | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
"@babel/proposal-object-rest-spread" | ||
] | ||
} | ||
} | ||
} | ||
} |
@@ -36,47 +36,6 @@ <!-- TITLE/ --> | ||
<!-- INSTALL/ --> | ||
## Usage | ||
<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 arrangekeys</code></li> | ||
<li>Require: <code>require('arrangekeys')</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/arrangekeys' | ||
</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>arrangekeys</code> aliases <code>arrangekeys/source/index.js</code></li> | ||
<li><code>arrangekeys/source/index.js</code> is esnext source code with require for modules</li> | ||
<li><code>arrangekeys/edition-browsers/index.js</code> is esnext compiled for 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.arrangekeys.bevry.surge.sh/docs/) | ||
```javascript | ||
@@ -136,2 +95,51 @@ // Arrange the keys of the input so that keys "b" and "c" are first | ||
[Complete API Documentation.](http://master.arrangekeys.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 arrangekeys</code></li> | ||
<li>Import: <code>import pkg from ('arrangekeys')</code></li> | ||
<li>Require: <code>const pkg = require('arrangekeys').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/arrangekeys/^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/arrangekeys@^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/arrangekeys@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>arrangekeys/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>arrangekeys/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>arrangekeys</code> aliases <code>arrangekeys/edition-esnext/index.js</code></li> | ||
<li><code>arrangekeys/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 +146,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
25214
16
9
121
210
1
1