{"id":19098482,"url":"https://github.com/winkjs/wink-helpers","last_synced_at":"2026-03-05T00:03:09.366Z","repository":{"id":21034683,"uuid":"91557265","full_name":"winkjs/wink-helpers","owner":"winkjs","description":"Functions for cross validation, shuffle, cartesian product and more","archived":false,"fork":false,"pushed_at":"2022-12-07T17:39:14.000Z","size":212,"stargazers_count":6,"open_issues_count":9,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-31T02:20:35.462Z","etag":null,"topics":["array","cartesian-product","cartesian-products","cross-validation","frequency-table","helpers","object","pluck","random-shuffle","shuffle","sort","string","validation"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/winkjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-17T09:14:42.000Z","updated_at":"2023-09-11T19:12:10.000Z","dependencies_parsed_at":"2023-01-11T21:03:53.139Z","dependency_job_id":null,"html_url":"https://github.com/winkjs/wink-helpers","commit_stats":null,"previous_names":["decisively/wink-helpers"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/winkjs/wink-helpers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winkjs%2Fwink-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winkjs%2Fwink-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winkjs%2Fwink-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winkjs%2Fwink-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/winkjs","download_url":"https://codeload.github.com/winkjs/wink-helpers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winkjs%2Fwink-helpers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30101689,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T23:59:36.199Z","status":"ssl_error","status_checked_at":"2026-03-04T23:56:48.556Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","cartesian-product","cartesian-products","cross-validation","frequency-table","helpers","object","pluck","random-shuffle","shuffle","sort","string","validation"],"created_at":"2024-11-09T03:46:01.521Z","updated_at":"2026-03-05T00:03:09.307Z","avatar_url":"https://github.com/winkjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# wink-helpers\nFunctions for cross validation, shuffle, cartesian product and more\n\n### [![Build Status](https://travis-ci.com/winkjs/wink-helpers.svg?branch=master)](https://travis-ci.com/github/winkjs/wink-helpers) [![Coverage Status](https://coveralls.io/repos/github/winkjs/wink-helpers/badge.svg?branch=master)](https://coveralls.io/github/winkjs/wink-helpers?branch=master) [![Inline docs](http://inch-ci.org/github/winkjs/wink-helpers.svg?branch=master)](http://inch-ci.org/github/winkjs/wink-helpers) [![devDependencies Status](https://david-dm.org/winkjs/wink-helpers/dev-status.svg)](https://david-dm.org/winkjs/wink-helpers?type=dev) [![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/winkjs/Lobby)\n\n\u003cimg align=\"right\" src=\"https://decisively.github.io/wink-logos/logo-title.png\" width=\"100px\" \u003e\n\nPerform cross validation for machine learning, shuffle an array randomly, remove diacritical marks from text, find cartesian product and more using **`wink-helpers`**.\n\n\n## Installation\nUse [npm](https://www.npmjs.com/package/wink-helpers) to install:\n```\nnpm install wink-helpers --save\n```\n\n\n## Example [![Try on Runkit](https://badge.runkitcdn.com/wink-helpers.svg)](https://npm.runkit.com/wink-helpers)\n\n```javascript\n// Load wink helpers\nvar helpers = require( 'wink-helpers' );\n\n\n/* Use array helpers */\nconsole.log( helpers.array.isArray( [] ) );\n// -\u003e true\n\nvar ppl = [ { name: 'aiden', age: 42 }, { name: 'olivia', age: 37 } ];\nconsole.log( ppl.sort( helpers.array.ascendingOn( 'age' ) ) );\n// -\u003e [ { \"name\": \"olivia\", \"age\": 37 }, { \"name\": \"aiden\", \"age\": 42 } ]\n\nconsole.log( helpers.array.product( [ [ 9, 8 ], [ 1, 2 ] ] ) );\n// -\u003e [ [ 9, 1 ], [ 9, 2 ], [ 8, 1 ], [ 8, 2 ] ]\n\nconsole.log( helpers.array.shuffle( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] ) );\n// -\u003e [ 3, 7, 8, 9, 6, 4, 2, 1, 10, 5 ]\n// Note: output will change on every call!\n\n/* Use object helpers */\nconsole.log( helpers.object.isObject( {} ) );\n// -\u003e true\n\nconsole.log( helpers.object.isObject( new Set() ) );\n// -\u003e false\n\nconsole.log( helpers.object.table( { mobile: 33, chargers: 45, usb: 27 } ) );\n// -\u003e [ [ \"mobile\", 33 ], [ \"chargers\", 45 ], [ \"usb\", 27 ] ]\n\n\n/* Use string helper */\nconsole.log( helpers.string.normalize( 'Résumé' ) );\n// -\u003e 'resume'\n```\n\n## API\nThe helper functions are classified into [array](#array), [object](#object), [string](#string) and [validate](#validate).\n\n### array\n\n#### isArray( value )\nTests if argument `value` is a valid JS array; returns `true` if it is, otherwise returns `false`.\n\n#### sorting compare functions\nIt is a set of handy [compare functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) for handling a variety of array sorting needs.\n\n| compareFunction | Description |\n| --- | --- |\n| ascending | Sorts elements in ascending order. |\n| descending | Sorts elements in descending order. |\n| ascendingOnKey | It works on array of arrays, where each element is in the `[ key, value ]` format. Sorts elements in ascending order on the `key`.  |\n| descendingOnKey | Same as above, but sorts in descending order.  |\n| ascendingOnValue | It works on array of arrays, where each element is in the `[ key, value ]` format. Sorts elements in ascending order on the `value`.  |\n| descendingOnValue | Same as above, but sorts in descending order.  |\n| ascendingOn( `accessor1` [,`accessor2`] ) | A higher order function that returns a compare function for the accessors — refers to a key whose value will be used to determine the sort order.\u003cbr/\u003e\u003cbr/\u003eCan be directly used as the compare function for sort.\u003cbr/\u003e\u003cbr/\u003eIt works on array of *arrays* or *objects*. \u003cbr/\u003e\u003cbr/\u003e When both the accessors are supplied, the combination is treated as a composite key for sort. |\n| descendingOn( `accessor1` [,`accessor2`] ) | Same as above, but sorts in descending order. |\n\n\n\n#### pluck( array, key, limit )\nPlucks the values specified by the `key` from each element of the `array` of *arrays* or *objects*, and returns the resultant array. The default value of `key` is **0**. The number of elements to be plucked is defined by the `limit`, whose default value is `array.length`.\n\n#### product( array )\nReturns the *cartesian product* of the arrays present inside the `array` argument. For example, if the `array` argument is `[ [ 1, 2, 3 ], [ 4 ], [ 5, 6 ] ]`, then the return value will be:\n```javascript\n[\n  [ 1, 4, 5 ],\n  [ 1, 4, 6 ],\n  [ 2, 4, 5 ],\n  [ 2, 4, 6 ],\n  [ 3, 4, 5 ],\n  [ 3, 4, 6 ]\n]\n```\n#### shuffle( array )\nRandomly shuffles the order of the elements in the input array using algorithm described in Chapter 3 on Random Numbers of \"The Art of Computer Programming Volume II\" by Donald E Knuth.\n\n### object\n\n#### isObject( value )\nTests if argument `value` is a JS object; returns `true` if it is, otherwise returns `false`.\n\n#### keys( obj )\nReturns keys of the `obj` in an `array`.\n\n#### size( obj )\nReturns the number of *keys* in the `obj`.\n\n#### values( obj )\nReturns all the *values* from each `key: value` pair in the `obj` in form of an array.\n\n#### valueFreq( obj )\nReturns the *frequency* or *count* of every unique value from each `key: value` pair in the `obj` in form of an object.\n\n#### table( obj [, f] )\nConverts each `key: value` pair in the `obj` into an array of `[ key, value ]` pairs. Note the returned value be an array of array. Second argument - `f` is optional; it is a function, which is called with each *value*.\n\n### string\n\n#### normalize( str )\nNormalizes the `str` by converting it to lower case and stripping the diacritical marks (if any).\n\n### validate\n\n#### isArray( value )\nAlias for `array.isArray()`.\n\n#### isObject( value )\nAlias for `object.isObject()`.\n\n#### isFiniteInteger( value )\nTests if argument `value` is a finite integer; returns `true` if it is, otherwise returns `false`.\n\n#### isFiniteNumber( value )\nTests if argument `value` is a finite number; returns `true` if it is, otherwise returns `false`.\n\n#### cross( classLabels )\nPerforms cross validation and generates detailed performance metrics along with the confusion matrix. It is a higher order function that returns an object containing `evaluate()`, `metrics()`,  and `reset()` functions. The `classLabels` should be an array containing all the class labels that may be predicted.\n\nThe `evaluate()` function accepts two parameters viz. `truth` — the actual label and `guess` — the predicted label. It is typically called for every row of validation dataset. The evaluation may fail if `truth` or `guess` value is not a valid `classLabels`; or if guess is equal to `unknown`.\n\nThe `metrics()` returns an object containing macro-averaged `avgPrecision`, `avgRecall`,  `avgFMeasure` values along with other details such as label-wise recall/precision/f-measure values and the confusion matrix. A value of `null` is returned if no evaluate() has been called before.\n\nThe `reset()` re-initializes the current instance for another round of evaluation; the class labels defined at instance creation time are not touched.\n\n## Need Help?\nIf you spot a bug and the same has not yet been reported, raise a new [issue](https://github.com/winkjs/wink-helpers/issues) or consider fixing it and sending a pull request.\n\n### About wink\n\n[Wink](http://winkjs.org/) is a family of open source packages for **Statistical Analysis**, **Natural Language Processing** and **Machine Learning** in NodeJS. The code is **thoroughly documented** for easy human comprehension and has a **test coverage of ~100%** for reliability to build production grade solutions.\n\n\n## Copyright \u0026 License\n**wink-helpers** is copyright 2017-21 [GRAYPE Systems Private Limited](http://graype.in/).\n\nIt is licensed under the terms of the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinkjs%2Fwink-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinkjs%2Fwink-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinkjs%2Fwink-helpers/lists"}