1.0.0 • Published 2 years ago

@maicol07/ts-collections v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Why?

Differences between Laravel Collections and TS Collections

There are some little differences between Laravel Collections and TS Collections due to how JS/TS works:

  • All names are camelCase (following JS coding standards)

Helpers

  • When you use a fallback value and the value you are trying to get is undefined, you will get the fallback value. Example:

    const data = {
      name: 'John Doe',
      age: undefined,
      address: {
        city: 'New York',
        country: 'USA'
      }
    }
    
    dataGet(data, 'age', 'fallback')
    // => 'fallback'

    The same applies to all the Collection methods that use this helper.

Collections

  • There are some new methods:
    • entries
    • isArray
  • Currently, lazy collections aren't implemented.
  • Due to the difference above, you can't use the following Laravel methods on your Collection:
    • chunkWhile
    • countBy
  • There are some changes inn the API of these methods:
    • contains: Instead of Laravel approach, this method will accept only one argument (item) that can be one of these values:
      • The item to test for
      • A function that will be called for each item in the collection and return true if the item matches
      • An entry (key-value pair) of the item to search in the collection
  • The following methods have not been implemented since they are already implemented in other methods or are natively supported by JS/TS:
    • containsStrict (since contains already does strict checks, following JS best practices)

WIP Status

  • all
  • average
  • avg
  • chunk
  • chunkWhile
  • collapse
  • collect
  • combine
  • concat
  • contains
  • containsOneItem
  • containsStrict
  • count
  • countBy
  • crossJoin
  • dd
  • diff
  • diffAssoc
  • diffAssocUsing
  • diffKeys
  • doesntContain
  • dot
  • dump
  • duplicates
  • duplicatesStrict
  • each
  • eachSpread
  • ensure
  • every
  • except
  • filter
  • first
  • firstOrFail
  • firstWhere
  • flatMap
  • flatten
  • flip
  • forget
  • forPage
  • get
  • groupBy
  • has
  • hasAny
  • implode
  • intersect
  • intersectAssoc
  • intersectByKeys
  • isEmpty
  • isNotEmpty
  • join
  • keyBy
  • keys
  • last
  • lazy
  • macro
  • make
  • map
  • mapInto
  • mapSpread
  • mapToGroups
  • mapWithKeys
  • max
  • median
  • merge
  • mergeRecursive
  • min
  • mode
  • nth
  • only
  • pad
  • partition
  • percentage
  • pipe
  • pipeInto
  • pipeThrough
  • pluck
  • pop
  • prepend
  • pull
  • push
  • put
  • random
  • range
  • reduce
  • reduceSpread
  • reject
  • replace
  • replaceRecursive
  • reverse
  • search
  • shift
  • shuffle
  • skip
  • skipUntil
  • skipWhile
  • slice
  • sliding
  • sole
  • some
  • sort
  • sortBy
  • sortByDesc
  • sortDesc
  • sortKeys
  • sortKeysDesc
  • sortKeysUsing
  • splice
  • split
  • splitIn
  • sum
  • take
  • takeUntil
  • takeWhile
  • tap
  • times
  • toArray
  • toJson
  • transform
  • undot
  • union
  • unique
  • uniqueStrict
  • unless
  • unlessEmpty
  • unlessNotEmpty
  • unwrap
  • value
  • values
  • when
  • whenEmpty
  • whenNotEmpty
  • where
  • whereStrict
  • whereBetween
  • whereIn
  • whereInStrict
  • whereInstanceOf
  • whereNotBetween
  • whereNotIn
  • whereNotInStrict
  • whereNotNull
  • whereNull
  • wrap
  • zip

Credits

1.0.0

2 years ago