New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

array-to-object-keys

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-to-object-keys - npm Package Compare versions

Comparing version 1.0.21 to 1.1.0

52

index.d.ts

@@ -11,17 +11,26 @@ /** @module array-to-object-keys

*/
export type valueGenerator = (value: string, index: number) => any;
type valueGenerator = (value: string, index: number) => any;
/**
* @typedef asyncValueGenerator
* @type {function}
* @async
* @param {string} value Original array entry
* @param {number} index Index of the array entry (starts at 0)
* @returns {*} Anything that will be the object entry value
*/
type asyncValueGenerator = (value: string, index: number) => any;
/**
* Converts an array to an object with static keys and customizable values
* @example
* import arrayToObjectKeys from "array-to-object-keys"
* arrayToObjectKeys(["a", "b"])
* // {a: null, b: null}
* let result = arrayToObjectKeys(["a", "b"])
* result = {a: null, b: null}
* @example
* import arrayToObjectKeys from "array-to-object-keys"
* arrayToObjectKeys(["a", "b"], "value")
* // {a: "value", b: "value"}
* let result = arrayToObjectKeys(["a", "b"], "value")
* result = {a: "value", b: "value"}
* @example
* import arrayToObjectKeys from "array-to-object-keys"
* arrayToObjectKeys(["a", "b"], (key, index) => `value for ${key} #${index + 1}`)
* // {a: "value for a #1", b: "value for b #2"}
* let result = arrayToObjectKeys(["a", "b"], (key, index) => `value for ${key} #${index + 1}`)
* result = {a: "value for a #1", b: "value for b #2"}
* @function

@@ -32,5 +41,32 @@ * @param {string[]} array Keys for the generated object

*/
export default function(array: string[], valueGenerator?: valueGenerator | any): {
function default(array: string[], valueGenerator?: valueGenerator | any): {
[key: string]: any;
};
/**
* Converts an array to an object with static keys and customizable values
* @example
* import fs from "fs"
* import path from "path"
* import {parallel} from "array-to-object-keys"
* const keys = ["license", "readme", "package", ".travis", "not-here"]
* const valueGenerator = async name => {
* const files = await fs.promises.readdir(path.resolve(__dirname, ".."))
* for (const file of files) {
* if (file.startsWith(`${name}.`)) {
* const stat = await fs.promises.stat(path.resolve(__dirname, "..", file), "utf8")
* return stat.size
* }
* }
* return null
* }
* let result = await parallel(keys, valueGenerator)
* result = { ".travis": 1672, license: 1099, package: 1948, readme: 132, "not-here": null }
* @function
* @param {string[]} array Keys for the generated object
* @param {asyncValueGenerator|*} [valueGenerator=null] Async function that sets the object values based on key and index
* @returns {object<string, *>} A generated object based on the array input
*/
function parallel(array: string[], valueGenerator?: asyncValueGenerator | any): {
[key: string]: any;
};
}

4

index.js
/*!
*** array-to-object-keys 1.0.21
*** array-to-object-keys 1.1.0
*** Copyright © 2019, Jaid <jaid.jsx@gmail.com> (https://github.com/Jaid)

@@ -7,3 +7,3 @@ *** @license MIT

!*/
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(global,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t),t.default=((e,t=null)=>{if(!Array.isArray(e))return{};const r={};if("function"==typeof t){let n=0;for(const o of e)r[o]=t(o,n),n++}else for(const n of e)r[n]=t;return r})}])});
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(global,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t),n.d(t,"parallel",function(){return o});const r={};t.default=((e,t=null)=>{if(!Array.isArray(e)||!e.length)return r;const n={};if("function"==typeof t){const r=(e,r)=>{n[e]=t(e,r)};for(let t=0;t<=e.length-1;t++)r(e[t],t,e)}else for(const r of e)n[r]=t;return n});const o=async(e,t=null)=>{if(!Array.isArray(e)||!e.length)return r;const n={};if("function"==typeof t){for(const t of e)n[t]=null;const r=async(e,r)=>{const o=await t(e,r);n[e]=o},o=Array(e.length);for(let t=0;t<=e.length-1;t++)o[t]=r(e[t],t,e);await Promise.all(o)}else for(const r of e)n[r]=t;return n}}])});
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"author":{"name":"Jaid","email":"jaid.jsx@gmail.com","url":"https://github.com/Jaid"},"bugs":"https://github.com/Jaid/array-to-object-keys/issues","description":"Converts an array to an object where the keys are the array entries and the values are customizable in a function.","homepage":"https://array-to-object-keys.jaid.codes","keywords":["array","array-manipulations","array-map","convert","javascript-array","javascript-object","keys","lang","object","values"],"license":"MIT","name":"array-to-object-keys","repository":"github:Jaid/array-to-object-keys","types":"index.d.ts","version":"1.0.21"}
{"author":{"name":"Jaid","email":"jaid.jsx@gmail.com","url":"https://github.com/Jaid"},"bugs":"https://github.com/Jaid/array-to-object-keys/issues","dependencies":{},"description":"Converts an array to an object where the keys are the array entries and the values are customizable in a function.","homepage":"https://array-to-object-keys.jaid.codes","keywords":["array","array-manipulations","array-map","convert","javascript-array","javascript-object","keys","lang","object","values"],"license":"MIT","name":"array-to-object-keys","repository":"github:Jaid/array-to-object-keys","types":"index.d.ts","version":"1.1.0"}

Sorry, the diff of this file is not supported yet

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