@stdlib/utils-group 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2023 The Stdlib Authors.
1
+ Copyright (c) 2016-2024 The Stdlib Authors.
package/README.md CHANGED
@@ -227,7 +227,7 @@ See [LICENSE][stdlib-license].
227
227
 
228
228
  ## Copyright
229
229
 
230
- Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
230
+ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
231
231
 
232
232
  </section>
233
233
 
@@ -240,8 +240,8 @@ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
240
240
  [npm-image]: http://img.shields.io/npm/v/@stdlib/utils-group.svg
241
241
  [npm-url]: https://npmjs.org/package/@stdlib/utils-group
242
242
 
243
- [test-image]: https://github.com/stdlib-js/utils-group/actions/workflows/test.yml/badge.svg?branch=v0.1.0
244
- [test-url]: https://github.com/stdlib-js/utils-group/actions/workflows/test.yml?query=branch:v0.1.0
243
+ [test-image]: https://github.com/stdlib-js/utils-group/actions/workflows/test.yml/badge.svg?branch=v0.2.1
244
+ [test-url]: https://github.com/stdlib-js/utils-group/actions/workflows/test.yml?query=branch:v0.2.1
245
245
 
246
246
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/utils-group/main.svg
247
247
  [coverage-url]: https://codecov.io/github/stdlib-js/utils-group?branch=main
@@ -264,8 +264,11 @@ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
264
264
  [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
265
265
 
266
266
  [deno-url]: https://github.com/stdlib-js/utils-group/tree/deno
267
+ [deno-readme]: https://github.com/stdlib-js/utils-group/blob/deno/README.md
267
268
  [umd-url]: https://github.com/stdlib-js/utils-group/tree/umd
269
+ [umd-readme]: https://github.com/stdlib-js/utils-group/blob/umd/README.md
268
270
  [esm-url]: https://github.com/stdlib-js/utils-group/tree/esm
271
+ [esm-readme]: https://github.com/stdlib-js/utils-group/blob/esm/README.md
269
272
  [branches-url]: https://github.com/stdlib-js/utils-group/blob/main/branches.md
270
273
 
271
274
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-group/main/LICENSE
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).
package/dist/index.js CHANGED
@@ -1,13 +1,7 @@
1
- "use strict";var i=function(e,u){return function(){return u||e((u={exports:{}}).exports,u),u.exports}};var g=i(function(B,o){
2
- var x=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/assert-has-own-property/dist'),P=require('@stdlib/utils-index-of/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist'),v=["values","indices","*"];function y(e,u){return x(u)?E(u,"returns")&&(e.returns=u.returns,P(v,e.returns)===-1)?new TypeError(s('1UJ4S',"returns",v.join('", "'),e.returns)):null:new TypeError(s('1UJ2V',u));}o.exports=y
3
- });var l=i(function(D,f){
4
- var T=require('@stdlib/assert-has-own-property/dist');function V(e,u){var t,a,n,r;for(a=e.length,t={},r=0;r<a;r++)n=u[r].toString(),T(t,n)?t[n].push(e[r]):t[n]=[e[r]];return t}f.exports=V
5
- });var p=i(function(G,h){
6
- var c=require('@stdlib/assert-has-own-property/dist');function j(e,u){var t,a,n,r;for(a=e.length,t={},r=0;r<a;r++)n=u[r].toString(),c(t,n)?t[n].push(r):t[n]=[r];return t}h.exports=j
7
- });var q=i(function(H,m){
8
- var S=require('@stdlib/assert-has-own-property/dist');function F(e,u){var t,a,n,r;for(a=e.length,t={},r=0;r<a;r++)n=u[r].toString(),S(t,n)?t[n].push([r,e[r]]):t[n]=[[r,e[r]]];return t}m.exports=F
9
- });var b=i(function(J,O){
10
- var w=require('@stdlib/assert-is-collection/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist'),C=g(),I=l(),L=p(),R=q();function k(e,u,t){var a,n,r;if(!w(e))throw new TypeError(d('1UJAh',e));if(a={returns:"values"},arguments.length===2)r=u;else{if(n=C(a,u),n)throw n;r=t}if(!w(r))throw new TypeError(d('1UJAm',r));if(e.length!==r.length)throw new RangeError(format('1UJ1a'));return a.returns==="values"?I(e,r):a.returns==="indices"?L(e,r):R(e,r)}O.exports=k
11
- });var z=b();module.exports=z;
1
+ "use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=a(function(V,v){
2
+ var h=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),w=require('@stdlib/utils-index-of/dist'),i=require('@stdlib/error-tools-fmtprodmsg/dist'),s=["values","indices","*"];function p(r,e){return h(e)?q(e,"returns")&&(r.returns=e.returns,w(s,r.returns)===-1)?new TypeError(i('1UJ4S',"returns",s.join('", "'),r.returns)):null:new TypeError(i('1UJ2V',e));}v.exports=p
3
+ });var o=a(function(j,g){
4
+ var m=require('@stdlib/assert-is-collection/dist'),b=require('@stdlib/array-base-group-values/dist'),c=require('@stdlib/array-base-group-indices/dist'),E=require('@stdlib/array-base-group-entries/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist'),O=l();function x(r,e,d){var u,n,t;if(!m(r))throw new TypeError(f('1UJAh',r));if(u={returns:"values"},arguments.length===2)t=e;else{if(n=O(u,e),n)throw n;t=d}if(!m(t))throw new TypeError(f('1UJAm',t));if(r.length!==t.length)throw new RangeError(f('1UJ1a'));return u.returns==="values"?b(r,t):u.returns==="indices"?c(r,t):E(r,t)}g.exports=x
5
+ });var y=o();module.exports=y;
12
6
  /** @license Apache-2.0 */
13
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../lib/validate.js", "../lib/return_values.js", "../lib/return_indices.js", "../lib/return_pairs.js", "../lib/main.js", "../lib/index.js"],
4
- "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar returns = [ 'values', 'indices', '*' ];\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {string} [options.returns] - output format\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'returns': '*'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'returns' ) ) {\n\t\topts.returns = options.returns;\n\t\tif ( indexOf( returns, opts.returns ) === -1 ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'returns', returns.join( '\", \"' ), opts.returns ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\n\n\n// MAIN //\n\n/**\n* Groups values as arrays associated with distinct keys and outputs element values.\n*\n* ## Notes\n*\n* - Checking for an \"own\" property is necessary to guard against the edge case where a group identifier which matches a method or property on the `Object` prototype.\n*\n* @private\n* @param {Collection} collection - collection to group\n* @param {Collection} groups - collection defining which group an element in the input collection belongs to\n* @returns {Object} group results\n*\n* @example\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var out = group( arr, groups );\n* // returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }\n*/\nfunction group( collection, groups ) {\n\tvar out;\n\tvar len;\n\tvar g;\n\tvar i;\n\n\tlen = collection.length;\n\tout = {};\n\tfor ( i = 0; i < len; i++ ) {\n\t\tg = groups[ i ].toString();\n\t\tif ( hasOwnProp( out, g ) ) {\n\t\t\tout[ g ].push( collection[ i ] );\n\t\t} else {\n\t\t\tout[ g ] = [ collection[ i ] ];\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = group;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\n\n\n// MAIN //\n\n/**\n* Groups values as arrays associated with distinct keys and outputs element indices.\n*\n* ## Notes\n*\n* - Checking for an \"own\" property is necessary to guard against the edge case where a group identifier which matches a method or property on the `Object` prototype.\n*\n* @private\n* @param {Collection} collection - collection to group\n* @param {Collection} groups - collection defining which group an element in the input collection belongs to\n* @returns {Object} group results\n*\n* @example\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var out = group( arr, groups );\n* // returns { 'b': [ 0, 1, 3 ], 'f': [ 2 ] }\n*/\nfunction group( collection, groups ) {\n\tvar out;\n\tvar len;\n\tvar g;\n\tvar i;\n\n\tlen = collection.length;\n\tout = {};\n\tfor ( i = 0; i < len; i++ ) {\n\t\tg = groups[ i ].toString();\n\t\tif ( hasOwnProp( out, g ) ) {\n\t\t\tout[ g ].push( i );\n\t\t} else {\n\t\t\tout[ g ] = [ i ];\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = group;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\n\n\n// MAIN //\n\n/**\n* Groups values as arrays associated with distinct keys and outputs index-element pairs.\n*\n* ## Notes\n*\n* - Checking for an \"own\" property is necessary to guard against the edge case where a group identifier which matches a method or property on the `Object` prototype.\n*\n* @private\n* @param {Collection} collection - collection to group\n* @param {Collection} groups - collection defining which group an element in the input collection belongs to\n* @returns {Object} group results\n*\n* @example\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var out = group( arr, groups );\n* // returns { 'b': [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], 'f': [ [ 2, 'foo' ] ] }\n*/\nfunction group( collection, groups ) {\n\tvar out;\n\tvar len;\n\tvar g;\n\tvar i;\n\n\tlen = collection.length;\n\tout = {};\n\tfor ( i = 0; i < len; i++ ) {\n\t\tg = groups[ i ].toString();\n\t\tif ( hasOwnProp( out, g ) ) {\n\t\t\tout[ g ].push( [ i, collection[ i ] ] );\n\t\t} else {\n\t\t\tout[ g ] = [ [ i, collection[ i ] ] ];\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = group;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar returnValues = require( './return_values.js' );\nvar returnIndices = require( './return_indices.js' );\nvar returnPairs = require( './return_pairs.js' );\n\n\n// MAIN //\n\n/**\n* Groups values as arrays associated with distinct keys.\n*\n* @param {Collection} collection - collection to group\n* @param {Options} [options] - function options\n* @param {string} [options.returns=\"values\"] - if `values`, values are returned; if `indices`, indices are returned; if `*`, both indices and values are returned\n* @param {Collection} groups - collection defining which group an element in the input collection belongs to\n* @throws {TypeError} first argument must be a collection\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} last argument must be a collection\n* @throws {TypeError} must provide valid options\n* @throws {RangeError} first and last arguments must be the same length\n* @returns {Object} group results\n*\n* @example\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var out = group( arr, groups );\n* // returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }\n*\n* @example\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var opts = {\n* 'returns': 'indices'\n* };\n*\n* var out = group( arr, opts, groups );\n* // returns { 'b': [ 0, 1, 3 ], 'f': [ 2 ] }\n*\n* @example\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var opts = {\n* 'returns': '*'\n* };\n*\n* var out = group( arr, opts, groups );\n* // returns { 'b': [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], 'f': [ [ 2, 'foo' ] ] }\n*/\nfunction group( collection, options, groups ) {\n\tvar opts;\n\tvar err;\n\tvar g;\n\tif ( !isCollection( collection ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) );\n\t}\n\topts = {\n\t\t'returns': 'values'\n\t};\n\tif ( arguments.length === 2 ) {\n\t\tg = options;\n\t} else {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tg = groups;\n\t}\n\tif ( !isCollection( g ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a collection. Value: `%s`.', g ) );\n\t}\n\tif ( collection.length !== g.length ) {\n\t\tthrow new RangeError( 'invalid arguments. First and last arguments must be the same length.' );\n\t}\n\tif ( opts.returns === 'values' ) {\n\t\treturn returnValues( collection, g );\n\t}\n\tif ( opts.returns === 'indices' ) {\n\t\treturn returnIndices( collection, g );\n\t}\n\treturn returnPairs( collection, g );\n}\n\n\n// EXPORTS //\n\nmodule.exports = group;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Group values as arrays associated with distinct keys.\n*\n* @module @stdlib/utils-group\n*\n* @example\n* var group = require( '@stdlib/utils-group' );\n*\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var out = group( arr, groups );\n* // returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }\n*\n* @example\n* var group = require( '@stdlib/utils-group' );\n*\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var opts = {\n* 'returns': 'indices'\n* };\n*\n* var out = group( arr, opts, groups );\n* // returns { 'b': [ 0, 1, 3 ], 'f': [ 2 ] }\n*\n* @example\n* var group = require( '@stdlib/utils-group' );\n*\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var opts = {\n* 'returns': '*'\n* };\n*\n* var out = group( arr, opts, groups );\n* // returns { 'b': [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], 'f': [ [ 2, 'foo' ] ] }\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
- "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,I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F,EAAK,UAAY,SACdP,EAAcI,EAAYK,CAAE,EAE/BF,EAAK,UAAY,UACdN,EAAeG,EAAYK,CAAE,EAE9BP,EAAaE,EAAYK,CAAE,CACnC,CAKAb,EAAO,QAAUO,ICjDjB,IAAIO,EAAO,IAKX,OAAO,QAAUA",
6
- "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "indexOf", "format", "returns", "validate", "opts", "options", "require_return_values", "__commonJSMin", "exports", "module", "hasOwnProp", "group", "collection", "groups", "out", "len", "g", "i", "require_return_indices", "__commonJSMin", "exports", "module", "hasOwnProp", "group", "collection", "groups", "out", "len", "g", "i", "require_return_pairs", "__commonJSMin", "exports", "module", "hasOwnProp", "group", "collection", "groups", "out", "len", "g", "i", "require_main", "__commonJSMin", "exports", "module", "isCollection", "format", "validate", "returnValues", "returnIndices", "returnPairs", "group", "collection", "options", "groups", "opts", "err", "g", "main"]
3
+ "sources": ["../lib/validate.js", "../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar returns = [ 'values', 'indices', '*' ];\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {string} [options.returns] - output format\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'returns': '*'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'returns' ) ) {\n\t\topts.returns = options.returns;\n\t\tif ( indexOf( returns, opts.returns ) === -1 ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'returns', returns.join( '\", \"' ), opts.returns ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar returnValues = require( '@stdlib/array-base-group-values' );\nvar returnIndices = require( '@stdlib/array-base-group-indices' );\nvar returnPairs = require( '@stdlib/array-base-group-entries' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\n\n\n// MAIN //\n\n/**\n* Groups values as arrays associated with distinct keys.\n*\n* @param {Collection} collection - collection to group\n* @param {Options} [options] - function options\n* @param {string} [options.returns=\"values\"] - if `values`, values are returned; if `indices`, indices are returned; if `*`, both indices and values are returned\n* @param {Collection} groups - collection defining which group an element in the input collection belongs to\n* @throws {TypeError} first argument must be a collection\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} last argument must be a collection\n* @throws {TypeError} must provide valid options\n* @throws {RangeError} first and last arguments must be the same length\n* @returns {Object} group results\n*\n* @example\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var out = group( arr, groups );\n* // returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }\n*\n* @example\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var opts = {\n* 'returns': 'indices'\n* };\n*\n* var out = group( arr, opts, groups );\n* // returns { 'b': [ 0, 1, 3 ], 'f': [ 2 ] }\n*\n* @example\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var opts = {\n* 'returns': '*'\n* };\n*\n* var out = group( arr, opts, groups );\n* // returns { 'b': [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], 'f': [ [ 2, 'foo' ] ] }\n*/\nfunction group( collection, options, groups ) {\n\tvar opts;\n\tvar err;\n\tvar g;\n\tif ( !isCollection( collection ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) );\n\t}\n\topts = {\n\t\t'returns': 'values'\n\t};\n\tif ( arguments.length === 2 ) {\n\t\tg = options;\n\t} else {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tg = groups;\n\t}\n\tif ( !isCollection( g ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a collection. Value: `%s`.', g ) );\n\t}\n\tif ( collection.length !== g.length ) {\n\t\tthrow new RangeError( 'invalid arguments. First and last arguments must be the same length.' );\n\t}\n\tif ( opts.returns === 'values' ) {\n\t\treturn returnValues( collection, g );\n\t}\n\tif ( opts.returns === 'indices' ) {\n\t\treturn returnIndices( collection, g );\n\t}\n\treturn returnPairs( collection, g );\n}\n\n\n// EXPORTS //\n\nmodule.exports = group;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Group values as arrays associated with distinct keys.\n*\n* @module @stdlib/utils-group\n*\n* @example\n* var group = require( '@stdlib/utils-group' );\n*\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var out = group( arr, groups );\n* // returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }\n*\n* @example\n* var group = require( '@stdlib/utils-group' );\n*\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var opts = {\n* 'returns': 'indices'\n* };\n*\n* var out = group( arr, opts, groups );\n* // returns { 'b': [ 0, 1, 3 ], 'f': [ 2 ] }\n*\n* @example\n* var group = require( '@stdlib/utils-group' );\n*\n* var arr = [ 'beep', 'boop', 'foo', 'bar' ];\n* var groups = [ 'b', 'b', 'f', 'b' ];\n*\n* var opts = {\n* 'returns': '*'\n* };\n*\n* var out = group( arr, opts, groups );\n* // returns { 'b': [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], 'f': [ [ 2, 'foo' ] ] }\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAk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,CAKAb,EAAO,QAAUO,ICjDjB,IAAIO,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "indexOf", "format", "returns", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isCollection", "returnValues", "returnIndices", "returnPairs", "format", "validate", "group", "collection", "options", "groups", "opts", "err", "g", "main"]
7
7
  }
package/lib/main.js CHANGED
@@ -21,11 +21,11 @@
21
21
  // MODULES //
22
22
 
23
23
  var isCollection = require( '@stdlib/assert-is-collection' );
24
+ var returnValues = require( '@stdlib/array-base-group-values' );
25
+ var returnIndices = require( '@stdlib/array-base-group-indices' );
26
+ var returnPairs = require( '@stdlib/array-base-group-entries' );
24
27
  var format = require( '@stdlib/string-format' );
25
28
  var validate = require( './validate.js' );
26
- var returnValues = require( './return_values.js' );
27
- var returnIndices = require( './return_indices.js' );
28
- var returnPairs = require( './return_pairs.js' );
29
29
 
30
30
 
31
31
  // MAIN //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/utils-group",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Group values as arrays associated with distinct keys.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -15,19 +15,12 @@
15
15
  ],
16
16
  "main": "./lib",
17
17
  "directories": {
18
- "benchmark": "./benchmark",
19
18
  "doc": "./docs",
20
- "example": "./examples",
21
19
  "lib": "./lib",
22
- "test": "./test"
20
+ "dist": "./dist"
23
21
  },
24
22
  "types": "./docs/types",
25
- "scripts": {
26
- "test": "make test",
27
- "test-cov": "make test-cov",
28
- "examples": "make examples",
29
- "benchmark": "make benchmark"
30
- },
23
+ "scripts": {},
31
24
  "homepage": "https://stdlib.io",
32
25
  "repository": {
33
26
  "type": "git",
@@ -37,23 +30,17 @@
37
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
31
  },
39
32
  "dependencies": {
40
- "@stdlib/assert-has-own-property": "^0.1.0",
41
- "@stdlib/assert-is-collection": "^0.1.0",
42
- "@stdlib/assert-is-plain-object": "^0.1.0",
43
- "@stdlib/string-format": "^0.1.0",
44
- "@stdlib/types": "^0.1.0",
45
- "@stdlib/utils-index-of": "^0.1.0",
46
- "@stdlib/error-tools-fmtprodmsg": "^0.1.0"
47
- },
48
- "devDependencies": {
49
- "@stdlib/array-float64": "^0.1.0",
50
- "@stdlib/bench": "^0.1.0",
51
- "@stdlib/math-base-special-floor": "^0.1.0",
52
- "@stdlib/random-base-randu": "^0.0.8",
53
- "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
54
- "istanbul": "^0.4.1",
55
- "tap-min": "git+https://github.com/Planeshifter/tap-min.git"
33
+ "@stdlib/array-base-group-entries": "^0.2.1",
34
+ "@stdlib/array-base-group-indices": "^0.2.1",
35
+ "@stdlib/array-base-group-values": "^0.2.1",
36
+ "@stdlib/assert-has-own-property": "^0.2.1",
37
+ "@stdlib/assert-is-collection": "^0.2.1",
38
+ "@stdlib/assert-is-plain-object": "^0.2.1",
39
+ "@stdlib/string-format": "^0.2.1",
40
+ "@stdlib/utils-index-of": "^0.2.1",
41
+ "@stdlib/error-tools-fmtprodmsg": "^0.2.1"
56
42
  },
43
+ "devDependencies": {},
57
44
  "engines": {
58
45
  "node": ">=0.10.0",
59
46
  "npm": ">2.7.0"
package/CITATION.cff DELETED
@@ -1,30 +0,0 @@
1
- cff-version: 1.2.0
2
- title: stdlib
3
- message: >-
4
- If you use this software, please cite it using the
5
- metadata from this file.
6
-
7
- type: software
8
-
9
- authors:
10
- - name: The Stdlib Authors
11
- url: https://github.com/stdlib-js/stdlib/graphs/contributors
12
-
13
- repository-code: https://github.com/stdlib-js/stdlib
14
- url: https://stdlib.io
15
-
16
- abstract: |
17
- Standard library for JavaScript and Node.js.
18
-
19
- keywords:
20
- - JavaScript
21
- - Node.js
22
- - TypeScript
23
- - standard library
24
- - scientific computing
25
- - numerical computing
26
- - statistical computing
27
-
28
- license: Apache-2.0 AND BSL-1.0
29
-
30
- date-released: 2016
@@ -1,69 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2018 The Stdlib Authors.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- 'use strict';
20
-
21
- // MODULES //
22
-
23
- var hasOwnProp = require( '@stdlib/assert-has-own-property' );
24
-
25
-
26
- // MAIN //
27
-
28
- /**
29
- * Groups values as arrays associated with distinct keys and outputs element indices.
30
- *
31
- * ## Notes
32
- *
33
- * - Checking for an "own" property is necessary to guard against the edge case where a group identifier which matches a method or property on the `Object` prototype.
34
- *
35
- * @private
36
- * @param {Collection} collection - collection to group
37
- * @param {Collection} groups - collection defining which group an element in the input collection belongs to
38
- * @returns {Object} group results
39
- *
40
- * @example
41
- * var arr = [ 'beep', 'boop', 'foo', 'bar' ];
42
- * var groups = [ 'b', 'b', 'f', 'b' ];
43
- *
44
- * var out = group( arr, groups );
45
- * // returns { 'b': [ 0, 1, 3 ], 'f': [ 2 ] }
46
- */
47
- function group( collection, groups ) {
48
- var out;
49
- var len;
50
- var g;
51
- var i;
52
-
53
- len = collection.length;
54
- out = {};
55
- for ( i = 0; i < len; i++ ) {
56
- g = groups[ i ].toString();
57
- if ( hasOwnProp( out, g ) ) {
58
- out[ g ].push( i );
59
- } else {
60
- out[ g ] = [ i ];
61
- }
62
- }
63
- return out;
64
- }
65
-
66
-
67
- // EXPORTS //
68
-
69
- module.exports = group;
@@ -1,69 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2018 The Stdlib Authors.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- 'use strict';
20
-
21
- // MODULES //
22
-
23
- var hasOwnProp = require( '@stdlib/assert-has-own-property' );
24
-
25
-
26
- // MAIN //
27
-
28
- /**
29
- * Groups values as arrays associated with distinct keys and outputs index-element pairs.
30
- *
31
- * ## Notes
32
- *
33
- * - Checking for an "own" property is necessary to guard against the edge case where a group identifier which matches a method or property on the `Object` prototype.
34
- *
35
- * @private
36
- * @param {Collection} collection - collection to group
37
- * @param {Collection} groups - collection defining which group an element in the input collection belongs to
38
- * @returns {Object} group results
39
- *
40
- * @example
41
- * var arr = [ 'beep', 'boop', 'foo', 'bar' ];
42
- * var groups = [ 'b', 'b', 'f', 'b' ];
43
- *
44
- * var out = group( arr, groups );
45
- * // returns { 'b': [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], 'f': [ [ 2, 'foo' ] ] }
46
- */
47
- function group( collection, groups ) {
48
- var out;
49
- var len;
50
- var g;
51
- var i;
52
-
53
- len = collection.length;
54
- out = {};
55
- for ( i = 0; i < len; i++ ) {
56
- g = groups[ i ].toString();
57
- if ( hasOwnProp( out, g ) ) {
58
- out[ g ].push( [ i, collection[ i ] ] );
59
- } else {
60
- out[ g ] = [ [ i, collection[ i ] ] ];
61
- }
62
- }
63
- return out;
64
- }
65
-
66
-
67
- // EXPORTS //
68
-
69
- module.exports = group;
@@ -1,69 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2018 The Stdlib Authors.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- 'use strict';
20
-
21
- // MODULES //
22
-
23
- var hasOwnProp = require( '@stdlib/assert-has-own-property' );
24
-
25
-
26
- // MAIN //
27
-
28
- /**
29
- * Groups values as arrays associated with distinct keys and outputs element values.
30
- *
31
- * ## Notes
32
- *
33
- * - Checking for an "own" property is necessary to guard against the edge case where a group identifier which matches a method or property on the `Object` prototype.
34
- *
35
- * @private
36
- * @param {Collection} collection - collection to group
37
- * @param {Collection} groups - collection defining which group an element in the input collection belongs to
38
- * @returns {Object} group results
39
- *
40
- * @example
41
- * var arr = [ 'beep', 'boop', 'foo', 'bar' ];
42
- * var groups = [ 'b', 'b', 'f', 'b' ];
43
- *
44
- * var out = group( arr, groups );
45
- * // returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }
46
- */
47
- function group( collection, groups ) {
48
- var out;
49
- var len;
50
- var g;
51
- var i;
52
-
53
- len = collection.length;
54
- out = {};
55
- for ( i = 0; i < len; i++ ) {
56
- g = groups[ i ].toString();
57
- if ( hasOwnProp( out, g ) ) {
58
- out[ g ].push( collection[ i ] );
59
- } else {
60
- out[ g ] = [ collection[ i ] ];
61
- }
62
- }
63
- return out;
64
- }
65
-
66
-
67
- // EXPORTS //
68
-
69
- module.exports = group;