CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-plugin-transform-es2015-literals

Babel plugin that compiles ES2015 unicode string and number literals to ES5

86

0.97x
Overview
Eval results
Files

task.mdevals/scenario-2/

File Permission Manager

A utility library for working with Unix-style file permissions that need to support legacy JavaScript environments.

Problem Statement

Build a permission manager that defines common file permission constants and provides a function to validate permission values. The library must work in older JavaScript environments (ES5) that don't support modern numeric literal syntax.

Requirements

Write your source code using modern JavaScript syntax for better readability. Your permission constants should use octal notation with the 0o prefix (e.g., 0o755, 0O644) to clearly represent Unix file permissions.

The code must be transpiled to work in ES5 environments. Configure a build system using Babel to transform your modern code into ES5-compatible output. The transpiled code should be generated in a dist/ directory.

Constants

Define the following permission constants using octal notation:

  • PERMISSION_READ_ALL: Full read permissions (0o444)
  • PERMISSION_WRITE_OWNER: Owner write permission (0o200)
  • PERMISSION_EXECUTE_ALL: Full execute permissions (0o111)
  • PERMISSION_STANDARD: Standard file permissions (0o644)
  • PERMISSION_RESTRICTED: Restricted permissions (0o600)

Validation Function

Implement a validatePermission(value) function that:

  • Returns true if the permission value is between 0 and 511 (inclusive)
  • Returns false otherwise

Build System

Set up Babel configuration to transpile your source code for ES5 compatibility. The build output should work in environments that don't support modern numeric literals.

Test Cases

  • The PERMISSION_READ_ALL constant equals 292 in the transpiled output @test
  • The PERMISSION_STANDARD constant equals 420 in the transpiled output @test
  • The validatePermission function returns true for value 493 @test
  • The validatePermission function returns false for value 512 @test

Implementation

@generates

API

/**
 * Validates whether a permission value is within the valid range.
 *
 * @param {number} value - The permission value to validate
 * @returns {boolean} True if valid (0-511), false otherwise
 */
function validatePermission(value) {
  // Implementation here
}

// Permission constants
const PERMISSION_READ_ALL = 0o444;
const PERMISSION_WRITE_OWNER = 0o200;
const PERMISSION_EXECUTE_ALL = 0o111;
const PERMISSION_STANDARD = 0o644;
const PERMISSION_RESTRICTED = 0o600;

module.exports = {
  validatePermission,
  PERMISSION_READ_ALL,
  PERMISSION_WRITE_OWNER,
  PERMISSION_EXECUTE_ALL,
  PERMISSION_STANDARD,
  PERMISSION_RESTRICTED
};

Dependencies { .dependencies }

@babel/plugin-transform-literals { .dependency }

Provides transformation support for modern numeric literal syntax to ES5-compatible code.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-babel-plugin-transform-es2015-literals

tile.json