1. Installation
npm install --save get-substrings-by-mask
2. Usage
2.1. Import the function
const getSubstringsByMask = ;
2.2. Description
const substings = ;
Arguments:
- mask (String): a mask;
- string (String): a string for extracting substrings;
- suppressErrors (Boolean): return null or throw error on error;
Returns
- (Object|null): an object with substrings;
3. Samples of usage
3.1. yyyy-MM-dd date
console; // { year: '2003', month: '04', day: '20' }
3.2. yyyy-MM-dd date with century
console; // { century: '20', year: '03', month: '04', day: '20' }
3.3. dd/MM/yyyy date
console; // { day: '20', month: '04', year: '2003' }
3.4. ddMMyyyy date
console; // { day: '20', month: '04', year: '2003' }
3.5. MM/dd/yyyy date
console; // { month: '04', day: '20', year: '2003' }
3.6. ISO date
console; // { year: '2019', month: '05', day: '24', hour: '09', minute: '36', second: '28', timezone: '+00:00' }
3.7. JavaScript date
console; // { weekday: 'Fri', day: '24', month: 'May', year: '2019', hour: '10', minute: '39', second: '51', timezone: 'GMT' }
3.8. dd-MMM-yyyy hh:mm date
console; // { day: '20', month: 'JUN', year: '1990', hour: '08', minute: '03' }
3.9. URL
console; // { blog: 'aboutfashion', article: '120', comment: '150', rest: 'mode=edit' }
3.10. IP address
console; // { byte1: '217', byte2: '20', byte3: '164', byte4: '1' }
3.11. latitude & longitude
console; // { deg1: '50', min1: '26', sec1: '45.8', dim1: 'N', deg2: '30', min2: '32', sec2: '44.7', dim2: 'E' }