Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elasticsearch-rolling-index-name-parser

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elasticsearch-rolling-index-name-parser - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

2

package.json
{
"name": "elasticsearch-rolling-index-name-parser",
"version": "1.1.1",
"version": "1.2.0",
"description": "Parser for Elasticsearch rolling index names.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

const moment = require( 'moment' );
const parsingLocale = 'en';
const datePatterns = [
{
period: 'hourly',
format: 'YYYY-MM-DD-HH',
regex: '^(.+)-(\\d{4}-\\d{2}-\\d{2}-\\d{2})$',
endOfCalculator: start => start.clone().endOf( 'hour' )
},
{
period: 'daily',
format: 'YYYY-MM-DD',
regex: '^(.+)-(\\d{4}-\\d{2}-\\d{2})$',
endOfCalculator: start => start.clone().endOf( 'day' )
},
{
period: 'weekly',
format: [
'GGGG-[w]WW',
'GGGG-[W]WW'
],
regex: '^(.+)-(\\d{4}-[wW]\\d{2})$',
endOfCalculator: start => start.clone().endOf( 'day' ).add( 6, 'day' )
},
{
period: 'monthly',
format: 'YYYY-MM',
regex: '^(.+)-(\\d{4}-\\d{2})$',
endOfCalculator: start => start.clone().endOf( 'month' )
}
];
module.exports = function(options) {
module.exports = function() {
const datePatterns = [
{
period: 'hourly',
format: 'YYYY-MM-DD-HH',
regex: '^(.+)-(\\d{4}-\\d{2}-\\d{2}-\\d{2})$',
endOfCalculator: start => start.clone().endOf( 'hour' )
},
{
period: 'daily',
format: 'YYYY-MM-DD',
regex: '^(.+)-(\\d{4}-\\d{2}-\\d{2})$',
endOfCalculator: start => start.clone().endOf( 'day' )
},
{
period: 'weekly',
format: options && options.usLocaleWeeks ? ['gggg-[w]ww', 'gggg-[W]ww'] : ['GGGG-[w]WW', 'GGGG-[W]WW'],
regex: '^(.+)-(\\d{4}-[wW]\\d{2})$',
endOfCalculator: start => start.clone().endOf( 'day' ).add( 6, 'day' )
},
{
period: 'monthly',
format: 'YYYY-MM',
regex: '^(.+)-(\\d{4}-\\d{2})$',
endOfCalculator: start => start.clone().endOf( 'month' )
}
];

@@ -48,3 +46,3 @@ return function( name ) {

const startMoment = moment.utc( dateString, datePattern.format, true );
const startMoment = moment.utc( dateString, datePattern.format, parsingLocale, true );
if( !startMoment.isValid() ) {

@@ -51,0 +49,0 @@ return null;

@@ -7,2 +7,3 @@ const chai = require( 'chai' );

const rollingIndexNameParser = rollingIndexNameParserFactory();
const rollingIndexNameParserLocaleWeeks = rollingIndexNameParserFactory({usLocaleWeeks: true});

@@ -56,3 +57,3 @@ describe( 'elasticsearch-rolling-index-name-parser', function() {

describe( 'when weekly pattern', function() {
describe( 'when iso weekly pattern', function() {

@@ -104,4 +105,83 @@ it( 'should parse lowercase w', function() {

it( 'should start from Jan 4', function() {
const result = rollingIndexNameParser( 'weekly_logs-2022-W01' );
assert( result, 'should parse index name' );
assert.equal( result.name, 'weekly_logs', 'name should be part before the date' );
assert.equal( result.period, 'weekly', 'period should be weekly' );
assert( moment.isMoment( result.startMoment ), 'start moment should be a moment' );
assert.equal( result.startMoment.toISOString(), '2022-01-03T00:00:00.000Z', 'should parse correct start moment' );
assert( moment.isMoment( result.endMoment ), 'end moment should be a moment' );
assert.equal( result.endMoment.toISOString(), '2022-01-09T23:59:59.999Z', 'should construct correct end moment' );
} );
} );
describe( 'when us locale weekly pattern', function() {
it( 'should parse lowercase w', function() {
const result = rollingIndexNameParserLocaleWeeks( 'super_logs-2019-w33' );
assert( result, 'should parse index name' );
assert.equal( result.name, 'super_logs', 'name should be part before the date' );
assert.equal( result.period, 'weekly', 'period should be weekly' );
assert( moment.isMoment( result.startMoment ), 'start moment should be a moment' );
assert.equal( result.startMoment.toISOString(), '2019-08-11T00:00:00.000Z', 'should parse correct start moment' );
assert( moment.isMoment( result.endMoment ), 'end moment should be a moment' );
assert.equal( result.endMoment.toISOString(), '2019-08-17T23:59:59.999Z', 'should construct correct end moment' );
} );
it( 'should parse uppercase W', function() {
const result = rollingIndexNameParserLocaleWeeks( 'super_logs-2019-W33' );
assert( result, 'should parse index name' );
assert.equal( result.name, 'super_logs', 'name should be part before the date' );
assert.equal( result.period, 'weekly', 'period should be weekly' );
assert( moment.isMoment( result.startMoment ), 'start moment should be a moment' );
assert.equal( result.startMoment.toISOString(), '2019-08-11T00:00:00.000Z', 'should parse correct start moment' );
assert( moment.isMoment( result.endMoment ), 'end moment should be a moment' );
assert.equal( result.endMoment.toISOString(), '2019-08-17T23:59:59.999Z', 'should construct correct end moment' );
} );
it( 'should parse week of year rules correctly', function() {
const result = rollingIndexNameParserLocaleWeeks( 'weekly_logs-2009-W01' );
assert( result, 'should parse index name' );
assert.equal( result.name, 'weekly_logs', 'name should be part before the date' );
assert.equal( result.period, 'weekly', 'period should be weekly' );
assert( moment.isMoment( result.startMoment ), 'start moment should be a moment' );
assert.equal( result.startMoment.toISOString(), '2008-12-28T00:00:00.000Z', 'should parse correct start moment' );
assert( moment.isMoment( result.endMoment ), 'end moment should be a moment' );
assert.equal( result.endMoment.toISOString(), '2009-01-03T23:59:59.999Z', 'should construct correct end moment' );
} );
it( 'should start from Jan 1', function() {
const result = rollingIndexNameParserLocaleWeeks( 'weekly_logs-2022-W01' );
assert( result, 'should parse index name' );
assert.equal( result.name, 'weekly_logs', 'name should be part before the date' );
assert.equal( result.period, 'weekly', 'period should be weekly' );
assert( moment.isMoment( result.startMoment ), 'start moment should be a moment' );
assert.equal( result.startMoment.toISOString(), '2021-12-26T00:00:00.000Z', 'should parse correct start moment' );
assert( moment.isMoment( result.endMoment ), 'end moment should be a moment' );
assert.equal( result.endMoment.toISOString(), '2022-01-01T23:59:59.999Z', 'should construct correct end moment' );
} );
} );
it( 'should return null for non rolling index', function() {

@@ -108,0 +188,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc