```ts
export function createLruCache(capacity: number): { get: (key: string) => number | undefined; put: (key: string, value: number) => void; size: () => number } {
    if (!Number.isInteger(capacity) || capacity <= 0) {
        throw new Error('Capacity must be a positive integer');
    }

    const cache = new Map<string, number>();
    
    return {
        get(key: string): number | undefined {
            if (cache.has(key)) {
                const value = cache.get(key);
                cache.delete(key);
                if (value !== undefined) {
                    cache.set(key, value);
                }
                return value;
            }
            return undefined;
        },
        
        put(key: string, value: number): void {
            if (cache.has(key)) {
                cache.delete(key);
            } else if (cache.size >= capacity) {
                const oldestKey = cache.keys().next().value;
                if (oldestKey !== undefined) {
                    cache.delete(oldestKey);
                }
            }
            cache.set(key, value);
        },
        
        size(): number {
            return cache.size;
        }
    };
}
```