From 423ddbd6d172081964e2daf1860706925301da86 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 3 Apr 2021 02:11:02 +0300 Subject: [PATCH] docs... Signed-off-by: Alex A. Naanou --- README.md | 119 +++++++++++++++++++++++++++++++++++++++++++++++------- Set.js | 12 +++--- 2 files changed, 110 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 891a64c..77d50ab 100644 --- a/README.md +++ b/README.md @@ -404,6 +404,8 @@ Object.keys(Object.sort(o, ['x', 'a', '100'])) // -> [ '0', '100', 'x', 'a', ' 27 ', 'b' ] ``` +This is similar to [`.sort(..)`](#mapsort) and [`.sort(..)`](#setsort). + ## `Array` @@ -836,14 +838,29 @@ but before the timeout. require('ig-types/Map') ``` - - ### `.sort(..)` - +Sort `` keys in-place +```bnf +.sort() + -> +.sort() + -> +``` +In the general case this is similar to +[`.sort(..)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) +with the addition of the [`.sortAs(..)`](#arraysortas)'s ability to sort +as a list +```bnf +.sort() + -> +``` + +This is similar to [`.sort(..)`](#setsort) and [`Object.sort(..)`](#objectsort), +see the later for more info. ## `Set` @@ -852,9 +869,6 @@ require('ig-types/Map') require('ig-types/Set') ``` - - - ### `.unite(..)` @@ -873,8 +887,27 @@ require('ig-types/Set') ### `.sort(..)` - +Sort `` keys in-place +```bnf +.sort() + -> +.sort() + -> +``` + +In the general case this is similar to +[`.sort(..)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) +with the addition of the [`.sortAs(..)`](#arraysortas)'s ability to sort +as a list +```bnf +.sort() + -> +``` + + +This is similar to [`.sort(..)`](#mapsort) and [`Object.sort(..)`](#objectsort), +see the later for more info. ## `Date` @@ -883,17 +916,36 @@ require('ig-types/Set') require('ig-types/Date') ``` - - ### `Date.timeStamp(..)` - +Generate a timestamp (format: `'YYYYMMDDHHMMSS'`) +```bnf +Date.timeStamp() + -> +``` + +Generate a full timestamp, including milliseconds (format: `'YYYYMMDDHHMMSSmmm'`) +```bnf +Date.timeStamp(true) + -> +``` + +This is a shorthand to: [`(new Date()).getTimeStamp(..)`](#dategettimestamp) + +The timestamp is generated from the time of call, for generating timestamps form specific `` objects see: +[`.getTimeStamp(..)`](#dategettimestamp) ### `Date.fromTimeStamp(..)` - +Create a `` from a timestamp +```bnf +Date.fromTimeStamp() + -> +``` + +This is a shorthand to: [`(new Date()).setTimeStamp()`](#datesettimestamp) ### `Date.str2ms(..)` @@ -966,18 +1018,55 @@ Supported formats: ### `.toShortDate(..)` - +Generate a short date string from `` +(format: `'YYYY-MM-DD HH:MM:SS'`) +```bnf +.toShortDate() + -> +``` + +Generate a short date string including milliseconds from `` +(format: `'YYYY-MM-DD HH:MM:SS:mmm'`) +```bnf +.toShortDate(true) + -> +``` + +Note that `` is directly parseable by `new Date(..)` +```javascript +var a = (new Date()).toShortDate(true) + +// parse the and generate a new short date from it... +var b = (new Date(a)).toShortDate(true) + +a == b // -> true +``` ### `.getTimeStamp(..)` - +Generate a timestamp from `` +(format `'YYYYMMDDHHMMSS'`) +```bnf +.getTimeStamp() + -> +``` + +Generate a timestamp from `` including milliseconds +(format `'YYYYMMDDHHMMSSmmm'`) +```bnf +.getTimeStamp(true) + -> +``` ### `.setTimeStamp(..)` - - +Update a `` from a timestamp +```bnf +.setTimeStamp() + -> +``` ## `String` diff --git a/Set.js b/Set.js index 845c738..7b27545 100644 --- a/Set.js +++ b/Set.js @@ -32,14 +32,14 @@ object.Mixin('SetMixin', 'soft', { .filter(function(e){ return !other.has(e) })) }, - sort: function(keys=[]){ - keys = (typeof(keys) == 'function' - || keys === undefined) ? - [...this].sort(keys) - : keys + sort: function(values=[]){ + values = (typeof(values) == 'function' + || values === undefined) ? + [...this].sort(values) + : values var del = this.delete.bind(this) var add = this.add.bind(this) - new Set([...keys, ...this]) + new Set([...values, ...this]) .forEach(function(e){ if(this.has(e)){ del(e)