Giter VIP home page Giter VIP logo

pure-utilities's People

Contributors

cieplus avatar dependabot[bot] avatar emilos avatar eriktrom avatar greenkeeper[bot] avatar inikonorov avatar mszmida avatar pkonieczniak avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pure-utilities's Issues

Add a new recsort method

It would be nice to add a utility to sort objects by key, something like:

const { isPlainObject } = require('pure-conditions')

const recursiveSort = (object) => {
  const newObject = {}
  Object.keys(object).sort().forEach(key => {
    const value = object[key]
    if (isPlainObject(value)) {
      newObject[key] = recursiveSort(value)
    } else {
      newObject[key] = value
    }
  })
  return newObject
}

module.exports = {
  recursiveSort
}

Acceptance criteria

  • add a recsort method to object/recsort.js
  • add specs
  • add docs
  • the method is pure (does not throw in any case)

Useful links

https://stackoverflow.com/questions/5467129/sort-javascript-object-by-key

Add hash and guid methods

e.g. something like

function hash () {
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}

function guid () {
  return hash() + hash() + '-' + hash() + '-' + hash() + '-' + hash() + '-' + hash() + hash() + hash()
}

New helpers for date objects

hours => returns the hour part from the date
minutes => returns the minutes from the date
seconds => returns the seconds from the date

New `occurences` method

Acceptance criteria

  • occurences method in collection.js
  • works for arrays (e.g. occurences(["foo", "foo", "bar"], "foo") returns 2)
  • works for strings (e.g. occurences("foo foo bar", "foo") returns 2)
  • tests
  • docs
  • examples

`unique` method should work for objects

Acceptance criteria

  • unique method should work correctly for objects within an array

here's a naive implementation, there's probably a better solution

return Array.from(new Set(array.map(item => JSON.stringify(item)))).map(JSON.parse)

Split functions into directories and separate files

Story

As a developer, I'd like to import a function per file so that the bundler I use has less work to do.

Acceptance criteria

  • create directories per type (array, string, collection etc.)
  • create a file per function (e.g. deepclone, capitalize etc. are in separate files)
  • create an index file (array/index.js) that requires all deps from given dir and exports them
  • tests should work as they do now

prettysize

Sometimes we need to define the size of file in bytes, but it is hard to read how many kilobytes or megabytes is has the the file without using calculators or comments.

 // max file size is 400 kB
 const MAX_FILE_SIZE = 409600
 const MAX_FILE_SIZE = prettysize('400KB')

So we could pass to the method string with specific unit for example '10KB' and it would be converted to bytes.

Maybe the better idea is passing to the method a configuration object.

Add a new `comma` method

It should join an array elements with comma , separator. The second parameter should be spacing (default set to 0)

Handle more edge cases in the `float` method

Acceptance criteria

  • converts more complex strings to number
"100,01" -> 100.01
"100 000,01" -> 100000.01
"100000.01" -> 100000.01
"100000.01" -> 100000.01
"100,000.01" -> 100000.01

make `deepclone` pure

Context

In the README, we're stating that the methods are side effect free. Unfortunately it's not true in all of the cases yet.

function deepclone (object) {
  return JSON.parse(JSON.stringify(object))
}

deepclone fn would throw if you'd pass undefined or when the parsed object has circular references.

Acceptance criteria

  • ensure deepclone does not throw
  • add more tests

We probably need to add a default:

function deepclone (object = {}) {}

and wrap the fn body with try catch. The simplest thing to do is probably just return an empty object if there's an exception.

Do not throw inside of the append/prepend/prettydate methods

By definition, all functions should have no side effects. It means that we should never throw.

Acceptance criteria

  • do not throw inside of the append/prepend/methods
  • append/prepend return the collection instead of throwing
  • prettydate returns an empty string instead of throwing

occurences bug

It doesn't seem to work when ! is used. Probably doesn't work for other special characters too.

occurences("!!oo", "!")
occurences("!!foo", "!")
occurences("!foo bar", "foo")

Update ava to the latest version

Issuehunt badges

Newest ava requires unique test names, so they should be adjusted as a part of this task.

Acceptance

  • update ava to the latest version
  • make names of the tests unique (based on what the test really does)
  • tests/linter is passing npm test, npm run lint
  • code coverage should still work npm run coverage

IssueHunt Summary

pro-src pro-src has been rewarded.

Backers (Total: $10.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Simplify the htmlstrip method, remove the regexp

Acceptance criteria

  • the htmlstrip method does not have a risky regexp anymore
  • the method still works for simple conditions
  • the method does not need to handle all possible edge cases
  • mention in docs that stripping html is not a secure method against xss

add a default value to all params

We're breaking the pure rule in many cases, e.g. in the simple method:

function first (array) {
  return array[0]
}

the following code would throw when there's no array, or something else was passed.

Acceptance criteria

  • add default values to functions in array.js, collection.js etc.
  • add tests against the undefined case (which is probably the most common one)

array/unique update

  • similar implementation like underscore
  • add more specs
  • bump package
  • reuse in es6-to-amd

Extend the `compact` method to accept a `strict` flag

We can add a new helper which may be helpful in some situations.
For example we sometimes do some operations on collections and later when we want to filter null values we need to use e.g. filter.Boolean()

compactmap should make transformations on elements but omits undefined and null values.
We can add also a strict flag or something similar to remove all falsy values

https://www.avanderlee.com/swift/compactmap-flatmap-differences-explained/
https://www.npmjs.com/package/compact-map

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.