Skip to content

Commit

Permalink
chore: add links to intro
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Dec 29, 2024
1 parent edbe275 commit ae6a06f
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 324 deletions.
344 changes: 172 additions & 172 deletions README.md

Large diffs are not rendered by default.

Empty file added docs/api/unique.md
Empty file.
256 changes: 128 additions & 128 deletions docs/intro.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ collection
```typescript
// Export to different formats
const json = collection.toJSON({ pretty: true })
const csv = collection.toCsv()
const xml = collection.toXml()
const csv = collection.toCSV()
const xml = collection.toXML()

// SQL generation
const sql = collection.toSQL('users')
Expand Down
4 changes: 2 additions & 2 deletions src/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2920,7 +2920,7 @@ ${collection.items.map(item =>
return JSON.stringify(items, null, pretty ? 2 : undefined)
},

toCsv(options: SerializationOptions = {}): string {
toCSV(options: SerializationOptions = {}): string {
const { exclude = [], include } = options
const items = this.toArray()
if (items.length === 0)
Expand All @@ -2936,7 +2936,7 @@ ${collection.items.map(item =>
return [headers.join(','), ...rows].join('\n')
},

toXml(options: SerializationOptions = {}): string {
toXML(options: SerializationOptions = {}): string {
const { exclude = [], include } = options
const items = this.toArray()
const rootTag = 'items'
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ export interface CollectionOperations<T> extends Collection<T> {

// Serialization & Deserialization
toJSON: (options?: SerializationOptions) => string
toCsv: (options?: SerializationOptions) => string
toXml: (options?: SerializationOptions) => string
toCSV: (options?: SerializationOptions) => string
toXML: (options?: SerializationOptions) => string
parse: (data: string, format: 'json' | 'csv' | 'xml') => CollectionOperations<T>

// Caching & Performance
Expand Down
36 changes: 18 additions & 18 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3762,10 +3762,10 @@ describe('Collection Serialization', () => {
})
})

describe('toCsv()', () => {
describe('toCSV()', () => {
it('should convert simple objects to CSV format', () => {
const collection = collect(simpleData)
const csv = collection.toCsv()
const csv = collection.toCSV()
const expectedHeader = 'id,name,age'
const firstRow = '1,"John",30'

Expand All @@ -3775,41 +3775,41 @@ describe('Collection Serialization', () => {

it('should handle nested objects by stringifying them', () => {
const collection = collect(complexData)
const csv = collection.toCsv()
const csv = collection.toCSV()
expect(csv).toContain('id,name,address,hobbies')
expect(csv).toContain(`1,"John",{"street":"123 Main St","city":"Boston"},["reading","gaming"]`)
})

it('should escape special characters', () => {
const collection = collect(specialCharsData)
const csv = collection.toCsv()
const csv = collection.toCSV()
expect(csv).toContain('"John \\"Johnny\\" Doe"')
expect(csv).toContain('"Likes to use, commas"')
})

it('should handle arrays in CSV conversion', () => {
const collection = collect(complexData)
const csv = collection.toCsv()
const csv = collection.toCSV()
expect(csv).toContain('["reading","gaming"]')
})

it('should respect exclude option', () => {
const collection = collect(simpleData)
const csv = collection.toCsv({ exclude: ['age'] })
const csv = collection.toCSV({ exclude: ['age'] })
expect(csv).not.toContain('age')
expect(csv).toContain('id,name')
})

it('should respect include option', () => {
const collection = collect(simpleData)
const csv = collection.toCsv({ include: ['id', 'name'] })
const csv = collection.toCSV({ include: ['id', 'name'] })
expect(csv).not.toContain('age')
expect(csv).toContain('id,name')
})

it('should handle empty collections', () => {
const collection = collect([])
const csv = collection.toCsv()
const csv = collection.toCSV()
expect(csv).toBe('')
})

Expand All @@ -3819,7 +3819,7 @@ describe('Collection Serialization', () => {
{ id: 2, name: 'Jane', age: null },
]
const collection = collect(data)
const csv = collection.toCsv()
const csv = collection.toCSV()
// Update expectations to match actual CSV output
const lines = csv.split('\n')
expect(lines[0]).toBe('id,name,age')
Expand All @@ -3828,10 +3828,10 @@ describe('Collection Serialization', () => {
})
})

describe('toXml()', () => {
describe('toXML()', () => {
it('should convert to XML format', () => {
const collection = collect(simpleData)
const xml = collection.toXml()
const xml = collection.toXML()
expect(xml).toContain('<?xml version="1.0" encoding="UTF-8"?>')
expect(xml).toContain('<items>')
expect(xml).toContain('<item>')
Expand All @@ -3843,29 +3843,29 @@ describe('Collection Serialization', () => {
{ id: 1, name: 'John & Jane', description: '<test>' },
]
const collection = collect(specialData)
const xml = collection.toXml()
const xml = collection.toXML()
expect(xml).toContain('John &amp; Jane')
expect(xml).toContain('&lt;test&gt;')
})

it('should handle nested objects by stringifying them', () => {
const collection = collect(complexData)
const xml = collection.toXml()
const xml = collection.toXML()
// Update expectations to match actual XML output
expect(xml).toContain('<address>[object Object]</address>')
expect(xml).toContain('<hobbies>reading,gaming</hobbies>')
})

it('should respect exclude option', () => {
const collection = collect(simpleData)
const xml = collection.toXml({ exclude: ['age'] })
const xml = collection.toXML({ exclude: ['age'] })
expect(xml).not.toContain('<age>')
expect(xml).toContain('<name>')
})

it('should handle empty collections', () => {
const collection = collect([])
const xml = collection.toXml()
const xml = collection.toXML()
expect(xml).toContain('<items>')
expect(xml).toContain('</items>')
})
Expand All @@ -3881,7 +3881,7 @@ describe('Collection Serialization', () => {

it('should parse CSV string back to collection', () => {
const collection = collect(simpleData)
const csv = collection.toCsv()
const csv = collection.toCSV()
const parsed = collection.parse(csv, 'csv')
expect(parsed.count()).toBe(simpleData.length)
expect(parsed.first()).toHaveProperty('name')
Expand Down Expand Up @@ -3976,8 +3976,8 @@ describe('Collection Serialization', () => {
}))
const collection = collect(largeData)
expect(() => collection.toJSON()).not.toThrow()
expect(() => collection.toCsv()).not.toThrow()
expect(() => collection.toXml()).not.toThrow()
expect(() => collection.toCSV()).not.toThrow()
expect(() => collection.toXML()).not.toThrow()
})
})
})
Expand Down

0 comments on commit ae6a06f

Please sign in to comment.